public SqlQuery cloneWithNewSql(String sql) { return new SqlQuery(sql, context, username); }
protected SqlQuery getQueryFromSQL(String sql) { return new SqlQuery(sql, DEFAULT_USERNAME); }
SqlQuery getDatasetSql() throws DatasetVersionNotFoundException { final VirtualDatasetUI datasetConfig = getDatasetConfig(); return new SqlQuery(datasetConfig.getSql(), datasetConfig.getState().getContextList(), securityContext.getUserPrincipal().getName()); } }
@POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public JobDataFragment query(CreateFromSQL sql) { SqlQuery query = new SqlQuery(sql.getSql(), sql.getContext(), securityContext); // Pagination is not supported in this API, so we need to truncate the results to 500 records return new JobUI(jobs.submitJob(JobRequest.newBuilder() .setSqlQuery(query) .setQueryType(QueryType.REST) .build(), NoOpJobStatusListener.INSTANCE)).getData().truncate(500); }
@Deprecated public JobDataFragment previewPhysicalDataset(String table, FileFormat formatOptions) { SqlQuery query = new SqlQuery(format("select * from table(%s (%s))", table, formatOptions.toTableOptions()), null, context.getUserPrincipal().getName()); // We still need to truncate the results to 500 as the preview physical datasets doesn't support pagination yet return new JobUI(jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(query) .setQueryType(QueryType.UI_INITIAL_PREVIEW) .build(), NoOpJobStatusListener.INSTANCE)).getData().truncate(500); } }
@Override public TransformResult visit(TransformUpdateSQL updateSQL) throws Exception { final SqlQuery query = new SqlQuery(updateSQL.getSql(), updateSQL.getSqlContextList(), username); m.setSql(query, getMetadata(query)); return m.result(); }
protected SqlQuery getQueryFromConfig(DatasetUI config) { return new SqlQuery(config.getSql(), config.getContext(), DEFAULT_USERNAME); }
private JobData runExternalQuery(String sql) { return new JobUI(jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(new SqlQuery(sql, Arrays.asList("@" + DEFAULT_USER_NAME), DEFAULT_USER_NAME)) .build(), NoOpJobStatusListener.INSTANCE)).getData(); }
public void validateAncestors(String sql, String... ancestors) { QueryMetadata metadata = QueryParser.extract(new SqlQuery(sql, null, DEFAULT_USERNAME), l(SabotContext.class)); List<SqlIdentifier> actualAncestors = metadata.getAncestors().get(); String message = "expected: " + Arrays.toString(ancestors) + " actual: " + actualAncestors; Assert.assertEquals(message, ancestors.length, actualAncestors.size()); for (int i = 0; i < ancestors.length; i++) { String expectedAncestor = ancestors[i]; String actualAncestor = actualAncestors.get(i).toString(); Assert.assertEquals(message, expectedAncestor, actualAncestor); } }
@POST public QueryDetails runQuery(CreateFromSQL sql) { SqlQuery query = new SqlQuery(sql.getSql(), sql.getContext(), securityContext); Job job = jobs.submitJob(JobRequest.newBuilder() .setSqlQuery(query) .setQueryType(QueryType.REST) .build(), NoOpJobStatusListener.INSTANCE); return new QueryDetails(job.getJobId().getId()); } }
private JobDataFragment runQuery(String sql) { JobData completeJobData = new JobUI(jobs.submitJob(JobRequest.newBuilder() .setSqlQuery(new SqlQuery(sql, Collections.singletonList("cp"), DEFAULT_USERNAME)) .build(), NoOpJobStatusListener.INSTANCE)).getData(); return completeJobData.truncate(500); }
protected SqlQuery getQueryFromConfig(VirtualDatasetUI config) { return new SqlQuery(config.getSql(), config.getState().getContextList(), DEFAULT_USERNAME); }
private ReplaceValuesCard genReplaceValuesCard(List<String> selected, Selection selection) throws DatasetVersionNotFoundException { VirtualDatasetUI virtualDatasetUI = getDatasetConfig(); Set<String> selectedSet = new HashSet<>(selected); SqlQuery query = new SqlQuery(virtualDatasetUI.getSql(), virtualDatasetUI.getState().getContextList(), securityContext); DataType colType = getColType(selection.getColName()); Histogram<HistogramValue> histo = histograms.getHistogram(datasetPath, version, selection, colType, query); long selectedCount = histograms.getSelectionCount(datasetPath, version, query, colType, selection.getColName(), selectedSet); return new ReplaceValuesCard(histo.getValues(), selectedCount, histo.getAvailableValues() - selectedCount, histo.getAvailableValues()); }
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 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 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 testQueryOnFile() throws Exception { final JobsService jobService = l(JobsService.class); Job job = jobService.submitJob(JobRequest.newBuilder() .setSqlQuery(new SqlQuery("SELECT * FROM dachdfs_test.dir1.json.\"users.json\"", SampleDataPopulator.DEFAULT_USER_NAME)) .build(), NoOpJobStatusListener.INSTANCE); JobDataFragment jobData = job.getData().truncate(500); assertEquals(3, jobData.getReturnedRowCount()); assertEquals(2, jobData.getSchema().getFieldCount()); } }
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())); }