Search in sources :

Example 11 with QueryRequest

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

QueryRequest (com.google.cloud.bigquery.QueryRequest)11 QueryResponse (com.google.cloud.bigquery.QueryResponse)11 FieldValue (com.google.cloud.bigquery.FieldValue)8 Test (org.junit.Test)6 TableId (com.google.cloud.bigquery.TableId)4 QueryParameterValue (com.google.cloud.bigquery.QueryParameterValue)3 QueryResult (com.google.cloud.bigquery.QueryResult)3 Table (com.google.cloud.bigquery.Table)3 BigQuery (com.google.cloud.bigquery.BigQuery)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 InsertAllRequest (com.google.cloud.bigquery.InsertAllRequest)1 InsertAllResponse (com.google.cloud.bigquery.InsertAllResponse)1 Job (com.google.cloud.bigquery.Job)1 JobStatistics (com.google.cloud.bigquery.JobStatistics)1 StandardTableDefinition (com.google.cloud.bigquery.StandardTableDefinition)1 ViewDefinition (com.google.cloud.bigquery.ViewDefinition)1 HashMap (java.util.HashMap)1