Search in sources :

Example 16 with QueryResponse

use of com.google.cloud.bigquery.QueryResponse in project google-cloud-java by GoogleCloudPlatform.

the class ITBigQueryTest method testQuery.

@Test
public void testQuery() throws InterruptedException {
    String query = new StringBuilder().append("SELECT TimestampField, StringField, BooleanField FROM ").append(TABLE_ID.getTable()).toString();
    QueryRequest request = QueryRequest.newBuilder(query).setDefaultDataset(DatasetId.of(DATASET)).setMaxWaitTime(60000L).setPageSize(1000L).build();
    QueryResponse response = queryAndWaitForResponse(request);
    assertEquals(QUERY_RESULT_SCHEMA, response.getResult().getSchema());
    int rowCount = 0;
    for (List<FieldValue> row : response.getResult().getValues()) {
        FieldValue timestampCell = row.get(0);
        FieldValue stringCell = row.get(1);
        FieldValue booleanCell = row.get(2);
        assertEquals(FieldValue.Attribute.PRIMITIVE, timestampCell.getAttribute());
        assertEquals(FieldValue.Attribute.PRIMITIVE, stringCell.getAttribute());
        assertEquals(FieldValue.Attribute.PRIMITIVE, booleanCell.getAttribute());
        assertEquals(1408452095220000L, timestampCell.getTimestampValue());
        assertEquals("stringValue", stringCell.getStringValue());
        assertEquals(false, booleanCell.getBooleanValue());
        rowCount++;
    }
    assertEquals(2, rowCount);
    Job queryJob = bigquery.getJob(response.getJobId());
    JobStatistics.QueryStatistics statistics = queryJob.getStatistics();
    assertNotNull(statistics.getQueryPlan());
}
Also used : JobStatistics(com.google.cloud.bigquery.JobStatistics) QueryRequest(com.google.cloud.bigquery.QueryRequest) QueryResponse(com.google.cloud.bigquery.QueryResponse) FieldValue(com.google.cloud.bigquery.FieldValue) Job(com.google.cloud.bigquery.Job) Test(org.junit.Test)

Aggregations

QueryResponse (com.google.cloud.bigquery.QueryResponse)16 QueryRequest (com.google.cloud.bigquery.QueryRequest)11 FieldValue (com.google.cloud.bigquery.FieldValue)9 Test (org.junit.Test)9 QueryResult (com.google.cloud.bigquery.QueryResult)5 TableId (com.google.cloud.bigquery.TableId)5 BigQuery (com.google.cloud.bigquery.BigQuery)3 Job (com.google.cloud.bigquery.Job)3 QueryParameterValue (com.google.cloud.bigquery.QueryParameterValue)3 Table (com.google.cloud.bigquery.Table)3 JobStatistics (com.google.cloud.bigquery.JobStatistics)2 QueryJobConfiguration (com.google.cloud.bigquery.QueryJobConfiguration)2 Schema (com.google.cloud.bigquery.Schema)2 TableInfo (com.google.cloud.bigquery.TableInfo)2 ExternalTableDefinition (com.google.cloud.bigquery.ExternalTableDefinition)1 Field (com.google.cloud.bigquery.Field)1 FieldValueList (com.google.cloud.bigquery.FieldValueList)1 InsertAllRequest (com.google.cloud.bigquery.InsertAllRequest)1 InsertAllResponse (com.google.cloud.bigquery.InsertAllResponse)1 JobId (com.google.cloud.bigquery.JobId)1