use of com.google.cloud.bigquery.JobStatistics.QueryStatistics in project java-bigquery by googleapis.
the class JobTest method testWaitForAndGetQueryResults.
@Test
public void testWaitForAndGetQueryResults() throws InterruptedException {
QueryJobConfiguration jobConfig = QueryJobConfiguration.newBuilder("SELECT 1").setDestinationTable(TABLE_ID1).build();
QueryStatistics jobStatistics = QueryStatistics.newBuilder().setCreationTimestamp(1L).setEndTime(3L).setStartTime(2L).build();
JobInfo jobInfo = JobInfo.newBuilder(jobConfig).setJobId(JOB_ID).setStatistics(jobStatistics).setJobId(JOB_ID).setEtag(ETAG).setGeneratedId(GENERATED_ID).setSelfLink(SELF_LINK).setUserEmail(EMAIL).setStatus(JOB_STATUS).build();
when(bigquery.getOptions()).thenReturn(mockOptions);
when(mockOptions.getClock()).thenReturn(CurrentMillisClock.getDefaultClock());
Job completedJob = expectedJob.toBuilder().setStatus(new JobStatus(JobStatus.State.RUNNING)).build();
Page<FieldValueList> singlePage = Pages.empty();
TableResult result = new TableResult(Schema.of(), 1, singlePage);
QueryResponse completedQuery = QueryResponse.newBuilder().setCompleted(true).setTotalRows(// Lies to force call of listTableData().
1).setSchema(Schema.of(Field.of("_f0", LegacySQLTypeName.INTEGER))).setErrors(ImmutableList.<BigQueryError>of()).build();
when(bigquery.getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS)).thenReturn(completedQuery);
when(bigquery.getJob(JOB_INFO.getJobId())).thenReturn(completedJob);
when(bigquery.getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS)).thenReturn(completedQuery);
when(bigquery.listTableData(eq(TABLE_ID1), any(Schema.class))).thenReturn(result);
job = this.job.toBuilder().setConfiguration(jobConfig).build();
assertThat(job.waitFor(TEST_RETRY_OPTIONS)).isSameInstanceAs(completedJob);
assertThat(job.getQueryResults().iterateAll()).hasSize(0);
verify(bigquery, times(2)).getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS);
verify(bigquery).getJob(JOB_INFO.getJobId());
}
use of com.google.cloud.bigquery.JobStatistics.QueryStatistics in project java-bigquery by googleapis.
the class ConnectionImpl method dryRun.
/**
* This method runs a dry run query
*
* @param sql SQL SELECT statement
* @return BigQueryDryRunResult containing List<Parameter> and Schema
* @throws BigQuerySQLException
*/
@BetaApi
@Override
public BigQueryDryRunResult dryRun(String sql) throws BigQuerySQLException {
com.google.api.services.bigquery.model.Job dryRunJob = createDryRunJob(sql);
Schema schema = Schema.fromPb(dryRunJob.getStatistics().getQuery().getSchema());
List<QueryParameter> queryParametersPb = dryRunJob.getStatistics().getQuery().getUndeclaredQueryParameters();
List<Parameter> queryParameters = Lists.transform(queryParametersPb, QUERY_PARAMETER_FROM_PB_FUNCTION);
QueryStatistics queryStatistics = JobStatistics.fromPb(dryRunJob);
SessionInfo sessionInfo = queryStatistics.getSessionInfo() == null ? null : queryStatistics.getSessionInfo();
BigQueryResultStats bigQueryResultStats = new BigQueryResultStatsImpl(queryStatistics, sessionInfo);
return new BigQueryDryRunResultImpl(schema, queryParameters, bigQueryResultStats);
}
use of com.google.cloud.bigquery.JobStatistics.QueryStatistics in project java-bigquery by googleapis.
the class ConnectionImpl method getBigQueryResultSetStats.
@VisibleForTesting
BigQueryResultStats getBigQueryResultSetStats(JobId jobId) {
// Create GetQueryResultsResponse query statistics
Job queryJob = getQueryJobRpc(jobId);
QueryStatistics queryStatistics = queryJob.getStatistics();
SessionInfo sessionInfo = queryStatistics.getSessionInfo() == null ? null : queryStatistics.getSessionInfo();
return new BigQueryResultStatsImpl(queryStatistics, sessionInfo);
}
Aggregations