Search in sources :

Example 1 with SessionInfo

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);
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) ArrowSchema(com.google.cloud.bigquery.storage.v1.ArrowSchema) SessionInfo(com.google.cloud.bigquery.JobStatistics.SessionInfo) QueryStatistics(com.google.cloud.bigquery.JobStatistics.QueryStatistics) Tuple(com.google.cloud.Tuple) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with SessionInfo

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());
}
Also used : QueryStatistics(com.google.cloud.bigquery.JobStatistics.QueryStatistics) Connection(com.google.cloud.bigquery.Connection) BigQueryDryRunResult(com.google.cloud.bigquery.BigQueryDryRunResult) Parameter(com.google.cloud.bigquery.Parameter) SessionInfo(com.google.cloud.bigquery.JobStatistics.SessionInfo) ConnectionSettings(com.google.cloud.bigquery.ConnectionSettings) Test(org.junit.Test)

Example 3 with SessionInfo

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);
}
Also used : QueryParameter(com.google.api.services.bigquery.model.QueryParameter) ArrowSchema(com.google.cloud.bigquery.storage.v1.ArrowSchema) SessionInfo(com.google.cloud.bigquery.JobStatistics.SessionInfo) QueryStatistics(com.google.cloud.bigquery.JobStatistics.QueryStatistics) QueryParameter(com.google.api.services.bigquery.model.QueryParameter) BetaApi(com.google.api.core.BetaApi)

Example 4 with SessionInfo

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);
}
Also used : QueryStatistics(com.google.cloud.bigquery.JobStatistics.QueryStatistics) SessionInfo(com.google.cloud.bigquery.JobStatistics.SessionInfo) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

QueryStatistics (com.google.cloud.bigquery.JobStatistics.QueryStatistics)4 SessionInfo (com.google.cloud.bigquery.JobStatistics.SessionInfo)4 ArrowSchema (com.google.cloud.bigquery.storage.v1.ArrowSchema)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 BetaApi (com.google.api.core.BetaApi)1 QueryParameter (com.google.api.services.bigquery.model.QueryParameter)1 Tuple (com.google.cloud.Tuple)1 BigQueryDryRunResult (com.google.cloud.bigquery.BigQueryDryRunResult)1 Connection (com.google.cloud.bigquery.Connection)1 ConnectionSettings (com.google.cloud.bigquery.ConnectionSettings)1 Parameter (com.google.cloud.bigquery.Parameter)1 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)1 Test (org.junit.Test)1