use of com.google.cloud.bigquery.JobStatistics.SessionInfo in project java-bigquery by googleapis.
the class ConnectionImpl method processQueryResponseResults.
@VisibleForTesting
BigQueryResult processQueryResponseResults(com.google.api.services.bigquery.model.QueryResponse results) {
Schema schema;
long numRows;
schema = Schema.fromPb(results.getSchema());
numRows = results.getTotalRows() == null ? 0 : // in case of DML or DDL
results.getTotalRows().longValue();
// QueryResponse only provides cache hits, dmlStats, and sessionInfo as query processing
// statistics
DmlStats dmlStats = results.getDmlStats() == null ? null : DmlStats.fromPb(results.getDmlStats());
Boolean cacheHit = results.getCacheHit();
QueryStatistics queryStatistics = QueryStatistics.newBuilder().setDmlStats(dmlStats).setCacheHit(cacheHit).build();
// We cannot directly set sessionInfo in QueryStatistics
SessionInfo sessionInfo = results.getSessionInfo() == null ? null : JobStatistics.SessionInfo.fromPb(results.getSessionInfo());
BigQueryResultStats bigQueryResultStats = new BigQueryResultStatsImpl(queryStatistics, sessionInfo);
bufferFvl = new LinkedBlockingDeque<>(getBufferSize());
BlockingQueue<Tuple<Iterable<FieldValueList>, Boolean>> pageCache = new LinkedBlockingDeque<>(getPageCacheSize(connectionSettings.getNumBufferedRows(), schema));
BlockingQueue<Tuple<TableDataList, Boolean>> rpcResponseQueue = new LinkedBlockingDeque<>(getPageCacheSize(connectionSettings.getNumBufferedRows(), schema));
JobId jobId = JobId.fromPb(results.getJobReference());
// Thread to make rpc calls to fetch data from the server
runNextPageTaskAsync(results.getPageToken(), getDestinationTable(jobId), rpcResponseQueue);
// Thread to parse data received from the server to client library objects
parseRpcDataAsync(results.getRows(), schema, pageCache, rpcResponseQueue);
// Thread to populate the buffer (a blocking queue) shared with the consumer
populateBufferAsync(rpcResponseQueue, pageCache, bufferFvl);
return new BigQueryResultImpl<AbstractList<FieldValue>>(schema, numRows, bufferFvl, bigQueryResultStats);
}
use of com.google.cloud.bigquery.JobStatistics.SessionInfo in project java-bigquery by googleapis.
the class ITBigQueryTest method testConnectionImplDryRun.
@Test
public void testConnectionImplDryRun() throws SQLException {
String query = String.format("select StringField, BigNumericField, BooleanField, BytesField, IntegerField, TimestampField, FloatField, NumericField, TimeField, DateField, DateTimeField , GeographyField, RecordField.BytesField, RecordField.BooleanField, IntegerArrayField from %s where StringField = ? order by TimestampField", TABLE_ID_FASTQUERY_BQ_RESULTSET.getTable());
ConnectionSettings connectionSettings = ConnectionSettings.newBuilder().setDefaultDataset(DatasetId.of(DATASET)).setCreateSession(true).build();
Connection connection = bigquery.createConnection(connectionSettings);
BigQueryDryRunResult bigQueryDryRunResultSet = connection.dryRun(query);
assertNotNull(bigQueryDryRunResultSet.getSchema());
assertEquals(BQ_RESULTSET_EXPECTED_SCHEMA, // match the schema
bigQueryDryRunResultSet.getSchema());
List<Parameter> queryParameters = bigQueryDryRunResultSet.getQueryParameters();
assertEquals(StandardSQLTypeName.STRING, queryParameters.get(0).getValue().getType());
QueryStatistics queryStatistics = bigQueryDryRunResultSet.getStatistics().getQueryStatistics();
assertNotNull(queryStatistics);
SessionInfo sessionInfo = bigQueryDryRunResultSet.getStatistics().getSessionInfo();
assertNotNull(sessionInfo.getSessionId());
assertEquals(StatementType.SELECT, queryStatistics.getStatementType());
}
use of com.google.cloud.bigquery.JobStatistics.SessionInfo 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.SessionInfo 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