@Test public void testAlterOption() throws Exception { SqlQuery ctas = getQueryFromSQL("alter session set \"planner.enable_multiphase_agg\"=true"); Job ctasJob = jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(ctas) .build(), NoOpJobStatusListener.INSTANCE); ctasJob.getData().loadIfNecessary(); }
@Test public void testAliasedQuery() throws Exception { SqlQuery ctas = getQueryFromSQL("SHOW SCHEMAS"); Job ctasJob = jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(ctas) .build(), NoOpJobStatusListener.INSTANCE); ctasJob.getData().loadIfNecessary(); }
@Test public void testExplain() throws Exception { SqlQuery ctas = getQueryFromSQL("EXPLAIN PLAN FOR SELECT * FROM sys.version"); Job ctasJob = jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(ctas) .build(), NoOpJobStatusListener.INSTANCE); ctasJob.getData().loadIfNecessary(); }
@Test public void testCTASAndDropTable() throws Exception { // Create a table SqlQuery ctas = getQueryFromSQL("CREATE TABLE \"$scratch\".\"ctas\" AS select * from cp.\"json/users.json\" LIMIT 1"); Job ctasJob = jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(ctas) .setQueryType(QueryType.UI_RUN) .build(), NoOpJobStatusListener.INSTANCE); ctasJob.getData().loadIfNecessary(); FileSystemPlugin plugin = (FileSystemPlugin) getCurrentDremioDaemon().getBindingProvider().lookup(CatalogService.class).getSource("$scratch"); // Make sure the table data files exist File ctasTableDir = new File(plugin.getConfig().getPath().toString(), "ctas"); assertTrue(ctasTableDir.exists()); assertTrue(ctasTableDir.list().length >= 1); // Now drop the table SqlQuery dropTable = getQueryFromSQL("DROP TABLE \"$scratch\".\"ctas\""); Job dropTableJob = jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(dropTable) .setQueryType(QueryType.ACCELERATOR_DROP) .build(), NoOpJobStatusListener.INSTANCE); dropTableJob.getData().loadIfNecessary(); // Make sure the table data directory is deleted assertFalse(ctasTableDir.exists()); }
@Test public void testCTASReplace() throws Exception { NamespaceKey namespaceKey = new NamespaceKey("ctasSpace"); SpaceConfig spaceConfig = new SpaceConfig(); spaceConfig.setName("ctasSpace"); newNamespaceService().addOrUpdateSpace(namespaceKey, spaceConfig); SqlQuery ctas = getQueryFromSQL("CREATE OR REPLACE VIEW ctasSpace.ctastest AS select * from (VALUES (1))"); Job ctasJob = jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(ctas) .setQueryType(QueryType.UI_RUN) .build(), NoOpJobStatusListener.INSTANCE); waitForCompletion(ctasJob); ctas = getQueryFromSQL("CREATE OR REPLACE VIEW ctasSpace.ctastest AS select * from (VALUES (2))"); ctasJob = jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(ctas) .setQueryType(QueryType.UI_RUN) .build(), NoOpJobStatusListener.INSTANCE); waitForCompletion(ctasJob); newNamespaceService().deleteSpace(namespaceKey, newNamespaceService().getSpace(namespaceKey).getTag()); }
.setSqlQuery(getQueryFromSQL("select * from LocalFS1.\"dac-sample1.json\" limit 1")) .setDatasetPath(ds1.toNamespaceKey()) .setDatasetVersion(new DatasetVersion("v1")).build(), NoOpJobStatusListener.INSTANCE); Job job2_0 = jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(getQueryFromSQL("select * from LocalFS1.\"dac-sample1.json\" limit 1")) .setDatasetPath(ds2.toNamespaceKey()) .setDatasetVersion(new DatasetVersion("v1")).build(), NoOpJobStatusListener.INSTANCE); Job job3_0 = jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(getQueryFromSQL("select * from LocalFS1.\"dac-sample1.json\" limit 1")) .setDatasetPath(ds3.toNamespaceKey()) .setDatasetVersion(new DatasetVersion("v1")).build(), NoOpJobStatusListener.INSTANCE); .setSqlQuery(getQueryFromSQL("select * from LocalFS1.\"dac-sample1.json\" limit 1")) .setDatasetPath(ds1.toNamespaceKey()) .setDatasetVersion(new DatasetVersion("v1")).build(), NoOpJobStatusListener.INSTANCE); Job job1_3 = jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(getQueryFromSQL("select * from LocalFS1.\"dac-sample1.json\" limit 1")) .setDatasetPath(ds1.toNamespaceKey()) .setDatasetVersion(new DatasetVersion("v2")).build(), NoOpJobStatusListener.INSTANCE); Job job2_2 = jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(getQueryFromSQL("select * from LocalFS1.\"dac-sample1.json\" limit 1")) .setDatasetPath(ds2.toNamespaceKey()) .setDatasetVersion(new DatasetVersion("v2")).build(), NoOpJobStatusListener.INSTANCE); .setSqlQuery(getQueryFromSQL("select * from LocalFS1.\"dac-sample1.json\" limit 1")) .setDatasetPath(ds1.toNamespaceKey()) .setDatasetVersion(new DatasetVersion("v1")).build(), NoOpJobStatusListener.INSTANCE);
@Test public void testJobCleanup() throws Exception { jobsService = (LocalJobsService) l(JobsService.class); SqlQuery ctas = getQueryFromSQL("SHOW SCHEMAS"); Job job = jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(ctas) .build(), NoOpJobStatusListener.INSTANCE); job.getData().loadIfNecessary(); SabotContext context = l(SabotContext.class); OptionValue days = OptionValue.createLong(OptionType.SYSTEM, ExecConstants.RESULTS_MAX_AGE_IN_DAYS.getOptionName(), 0); context.getOptionManager().setOption(days); OptionValue millis = OptionValue.createLong(OptionType.SYSTEM, ExecConstants.DEBUG_RESULTS_MAX_AGE_IN_MILLISECONDS.getOptionName(), 10); context.getOptionManager().setOption(millis); Thread.sleep(20); LocalJobsService.CleanupTask cleanupTask = jobsService.new CleanupTask(); cleanupTask.cleanup(); //make sure that the job output directory is gone assertFalse(jobsService.getJobResultsStore().jobOutputDirectoryExists(job.getJobId())); job = jobsService.getJob(job.getJobId()); assertFalse(JobDetailsUI.of(job).getResultsAvailable()); context.getOptionManager().setOption(OptionValue.createLong(OptionType.SYSTEM, ExecConstants.RESULTS_MAX_AGE_IN_DAYS.getOptionName(), 30)); context.getOptionManager().setOption(OptionValue.createLong(OptionType.SYSTEM, ExecConstants.DEBUG_RESULTS_MAX_AGE_IN_MILLISECONDS.getOptionName(), 0)); }