@Test public void testQueryJob() throws InterruptedException { String tableName = "test_query_job_table"; String query = new StringBuilder() .append("SELECT TimestampField, StringField, BooleanField FROM ") .append(TABLE_ID.table()) .toString(); TableId destinationTable = TableId.of(DATASET, tableName); QueryJobConfiguration configuration = QueryJobConfiguration.builder(query) .defaultDataset(DatasetId.of(DATASET)) .destinationTable(destinationTable) .build(); Job remoteJob = bigquery.create(JobInfo.of(configuration)); while (!remoteJob.isDone()) { Thread.sleep(1000); } assertNull(remoteJob.status().error()); QueryResponse response = bigquery.getQueryResults(remoteJob.jobId()); while (!response.jobCompleted()) { Thread.sleep(1000); response = bigquery.getQueryResults(response.jobId()); } assertFalse(response.hasErrors()); assertEquals(QUERY_RESULT_SCHEMA, response.result().schema()); int rowCount = 0; for (List<FieldValue> row : response.result().values()) { FieldValue timestampCell = row.get(0); FieldValue stringCell = row.get(1); FieldValue booleanCell = row.get(2); assertEquals(FieldValue.Attribute.PRIMITIVE, timestampCell.attribute()); assertEquals(FieldValue.Attribute.PRIMITIVE, stringCell.attribute()); assertEquals(FieldValue.Attribute.PRIMITIVE, booleanCell.attribute()); assertEquals(1408452095220000L, timestampCell.timestampValue()); assertEquals("stringValue", stringCell.stringValue()); assertEquals(false, booleanCell.booleanValue()); rowCount++; } assertEquals(2, rowCount); assertTrue(bigquery.delete(DATASET, tableName)); Job queryJob = bigquery.getJob(remoteJob.jobId()); JobStatistics.QueryStatistics statistics = queryJob.statistics(); assertNotNull(statistics.queryPlan()); }
@Test public void testQuery() throws InterruptedException { String query = new StringBuilder() .append("SELECT TimestampField, StringField, BooleanField FROM ") .append(TABLE_ID.table()) .toString(); QueryRequest request = QueryRequest.builder(query) .defaultDataset(DatasetId.of(DATASET)) .maxWaitTime(60000L) .maxResults(1000L) .build(); QueryResponse response = bigquery.query(request); while (!response.jobCompleted()) { Thread.sleep(1000); response = bigquery.getQueryResults(response.jobId()); } assertEquals(QUERY_RESULT_SCHEMA, response.result().schema()); int rowCount = 0; for (List<FieldValue> row : response.result().values()) { FieldValue timestampCell = row.get(0); FieldValue stringCell = row.get(1); FieldValue booleanCell = row.get(2); assertEquals(FieldValue.Attribute.PRIMITIVE, timestampCell.attribute()); assertEquals(FieldValue.Attribute.PRIMITIVE, stringCell.attribute()); assertEquals(FieldValue.Attribute.PRIMITIVE, booleanCell.attribute()); assertEquals(1408452095220000L, timestampCell.timestampValue()); assertEquals("stringValue", stringCell.stringValue()); assertEquals(false, booleanCell.booleanValue()); rowCount++; } assertEquals(2, rowCount); Job queryJob = bigquery.getJob(response.jobId()); JobStatistics.QueryStatistics statistics = queryJob.statistics(); assertNotNull(statistics.queryPlan()); }