Search in sources :

Example 1 with BigQueryDryRunResult

use of com.google.cloud.bigquery.BigQueryDryRunResult 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)

Aggregations

BigQueryDryRunResult (com.google.cloud.bigquery.BigQueryDryRunResult)1 Connection (com.google.cloud.bigquery.Connection)1 ConnectionSettings (com.google.cloud.bigquery.ConnectionSettings)1 QueryStatistics (com.google.cloud.bigquery.JobStatistics.QueryStatistics)1 SessionInfo (com.google.cloud.bigquery.JobStatistics.SessionInfo)1 Parameter (com.google.cloud.bigquery.Parameter)1 Test (org.junit.Test)1