@Override public void loadIfNecessary() { delegate.loadIfNecessary(); } }
@Override public void loadIfNecessary() { delegate.loadIfNecessary(); }
@Test public void testDownloadJsonRest() throws Exception { final String downloadPath = new DatasetVersionResourcePath(new DatasetPath("DG.dsg1"), dsg1.getVersion()).toString(); InitialDownloadResponse initialDownloadResponse = expectSuccess( getBuilder(getAPIv2().path(downloadPath).path("download").queryParam("downloadFormat", DownloadFormat.JSON)).buildGet(), InitialDownloadResponse.class); // wait for job final Job job = l(JobsService.class).getJob(initialDownloadResponse.getJobId()); job.getData().loadIfNecessary(); // get job data Response response = getBuilder(getAPIv2().path(initialDownloadResponse.getDownloadUrl())).buildGet().invoke(); validateAllRows(readDataJson((InputStream)response.getEntity())); }
@Test public void testDownloadCsvRest() throws Exception { final String downloadPath = new DatasetVersionResourcePath(new DatasetPath("DG.dsg1"), dsg1.getVersion()).toString(); InitialDownloadResponse initialDownloadResponse = expectSuccess( getBuilder(getAPIv2().path(downloadPath).path("download").queryParam("downloadFormat", DownloadFormat.CSV)).buildGet(), InitialDownloadResponse.class); // wait for job final Job job = l(JobsService.class).getJob(initialDownloadResponse.getJobId()); job.getData().loadIfNecessary(); // get job data Response response = getBuilder(getAPIv2().path(initialDownloadResponse.getDownloadUrl())).buildGet().invoke(); validateAllRows(readDataCsv((InputStream)response.getEntity())); }
@Test // DX-6142 & DX-9432 public void testDownloadWithLimitInDatasetSql() throws Exception { final DatasetPath dsPath = new DatasetPath("DG.testDS"); DatasetUI ds = createDatasetFromSQLAndSave(dsPath,"select * from DG.dsg1 LIMIT 10 --- comment", asList("cp")); Job job = datasetService.prepareDownload(dsPath, ds.getDatasetVersion(), DownloadFormat.CSV, 50, SampleDataPopulator.DEFAULT_USER_NAME); job.getData().loadIfNecessary(); DownloadDataResponse downloadDataResponse = datasetService.downloadData(job.getJobAttempt().getInfo().getDownloadInfo(), SampleDataPopulator.DEFAULT_USER_NAME); final List<TestData> downloadedData = readDataCsv(downloadDataResponse.getInput()); assertEquals(10, downloadedData.size()); for (int i = 0; i < 10; ++i) { assertEquals("user" + i, downloadedData.get(i).getUser()); assertEquals(i%25, downloadedData.get(i).getAge()); assertEquals("address" + i, downloadedData.get(i).getAddress()); } }
protected void setSystemOption(String optionName, String optionValue) { final String query = String.format("ALTER SYSTEM SET \"%s\"=%s", optionName, optionValue); final Job job = getJobsService().submitJob(JobRequest.newBuilder() .setSqlQuery(new SqlQuery(query, DEFAULT_USERNAME)) .setQueryType(QueryType.UI_INTERNAL_RUN) .setDatasetPath(DatasetPath.NONE.toNamespaceKey()) .build(), NoOpJobStatusListener.INSTANCE); job.getData().loadIfNecessary(); }
@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 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 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 testDsg1Unknown() { Job job = jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(new SqlQuery("select * from DG.dsg1", SampleDataPopulator.DEFAULT_USER_NAME)) .setQueryType(QueryType.UNKNOWN) .build(), NoOpJobStatusListener.INSTANCE); job.getData().loadIfNecessary(); // unkown jobs are not counted assertEquals((int)jobsCount.get(dsg1), jobsService.getJobsCount(dsg1.toNamespaceKey())); assertEquals((int) jobsCount.get(sample1), jobsService.getJobsCount(sample1.toNamespaceKey())); }
@Test public void testVirtualDatasetWithNotNullFields() throws Exception { final LocalJobsService jobsService = (LocalJobsService) l(JobsService.class); expectSuccess(getBuilder(getAPIv2().path("space/space1")).buildPut(Entity.json(new Space(null, "space1", null, null, null, 0, null))), Space.class); final String pathName = "space1.v1"; final DatasetPath numbersJsonPath = new DatasetPath(pathName); DatasetUI numbersJsonVD = createDatasetFromSQLAndSave(numbersJsonPath, "select row_number() over (order by a) as rnk, a from cp.\"json/numbers.json\"", asList("cp")); final SqlQuery query = getQueryFromSQL(String.format("select t1.rnk, t1.a from %s t1 join %s t2 on t1.rnk = t2.rnk+1", pathName, pathName)); final Job ctasJob = jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(query) .build(), NoOpJobStatusListener.INSTANCE); ctasJob.getData().loadIfNecessary(); }
@Test public void testDsg2Internal() { Job job = jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(new SqlQuery("select * from DG.dsg2", SampleDataPopulator.DEFAULT_USER_NAME)) .setQueryType(QueryType.UI_INTERNAL_PREVIEW) .build(), NoOpJobStatusListener.INSTANCE); job.getData().loadIfNecessary(); // internal jobs don't get counted assertEquals((int) jobsCount.get(dsg2), jobsService.getJobsCount(dsg2.toNamespaceKey())); assertEquals((int) jobsCount.get(sample2), jobsService.getJobsCount(sample2.toNamespaceKey())); }
@Test public void testVirtualDatasetWithTimestampDiff() throws Exception { final LocalJobsService jobsService = (LocalJobsService) l(JobsService.class); expectSuccess(getBuilder(getAPIv2().path("space/space1")).buildPut(Entity.json(new Space(null, "space1", null, null, null, 0, null))), Space.class); final String pathName = "space1.v1"; final DatasetPath datetimePath = new DatasetPath(pathName); DatasetUI dateTimeVD = createDatasetFromSQLAndSave(datetimePath, "select timestampdiff(SECOND, datetime1, datetime2) as tsdiff from cp.\"json/datetime.json\"", asList("cp")); final SqlQuery query = getQueryFromSQL(String.format("select * from %s", pathName, pathName)); final Job ctasJob = jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(query) .build(), NoOpJobStatusListener.INSTANCE); ctasJob.getData().loadIfNecessary(); }
@Test public void testReflectionsTable() { jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(getQueryFromSQL("SELECT * FROM sys.reflections")) .setDatasetPath(NONE_PATH) .build(), NoOpJobStatusListener.INSTANCE).getData().loadIfNecessary(); }
@Test public void testMaterializationsTable() { jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(getQueryFromSQL("SELECT * FROM sys.materializations")) .setDatasetPath(NONE_PATH) .build(), NoOpJobStatusListener.INSTANCE).getData().loadIfNecessary(); } }
@Test public void testDownloadCsv() throws Exception { Job job = datasetService.prepareDownload(dsg1DatasetPath, dsg1.getVersion(), DownloadFormat.CSV, -1, SampleDataPopulator.DEFAULT_USER_NAME); job.getData().loadIfNecessary(); DownloadDataResponse downloadDataResponse = datasetService.downloadData(job.getJobAttempt().getInfo().getDownloadInfo(), SampleDataPopulator.DEFAULT_USER_NAME); validateAllRows(readDataCsv(downloadDataResponse.getInput())); }
@Test public void testDownloadJson() throws Exception { Job job = datasetService.prepareDownload(dsg1DatasetPath, dsg1.getVersion(), DownloadFormat.JSON, -1, SampleDataPopulator.DEFAULT_USER_NAME); job.getData().loadIfNecessary(); DownloadDataResponse downloadDataResponse = datasetService.downloadData(job.getJobAttempt().getInfo().getDownloadInfo(), SampleDataPopulator.DEFAULT_USER_NAME); validateAllRows(readDataJson(downloadDataResponse.getInput())); }
private static QueryProfile getQueryProfile(final String query) throws JobNotFoundException { final Job job = getJobsService().submitJob(JobRequest.newBuilder() .setSqlQuery(new SqlQuery(query, DEFAULT_USERNAME)) .setQueryType(QueryType.UI_INTERNAL_RUN) .setDatasetPath(DatasetPath.NONE.toNamespaceKey()) .setDatasetVersion(DatasetVersion.NONE) .build(), new NoOpJobStatusListener()); job.getData().loadIfNecessary(); return getJobsService().getProfile(job.getJobId(), 0); }
@Test public void testDsg2UI() { Job job = jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(new SqlQuery("select * from DG.dsg2", SampleDataPopulator.DEFAULT_USER_NAME)) .setQueryType(QueryType.UI_RUN) .build(), NoOpJobStatusListener.INSTANCE); job.getData().loadIfNecessary(); assertEquals(inc(dsg2), jobsService.getJobsCount(dsg2.toNamespaceKey())); assertEquals(inc(sample2), jobsService.getJobsCount(sample2.toNamespaceKey())); }
@Test public void testDsg1External() { Job job = jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(new SqlQuery("select * from DG.dsg1", SampleDataPopulator.DEFAULT_USER_NAME)) .setQueryType(QueryType.UI_RUN) .build(), NoOpJobStatusListener.INSTANCE); job.getData().loadIfNecessary(); assertEquals(inc(dsg1), jobsService.getJobsCount(dsg1.toNamespaceKey())); assertEquals(inc(sample1), jobsService.getJobsCount(sample1.toNamespaceKey())); }