Skip to content

Commit 47a55dc

Browse files
committed
pr comment
1 parent f370cbe commit 47a55dc

File tree

13 files changed

+33
-35
lines changed

13 files changed

+33
-35
lines changed

CHANGES.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
- You no longer have to call `Job.waitFor`.
66
- `BigQuery.getQueryResults(JobId)` is replaced.
77
- Instead of `bigquery.getQueryResults(id)`, use `bigquery.getJob(id).getQueryResults()`.
8-
- `Job.getQueryResults` returns `TableResult`, not `QueryResponse`.
8+
- `BigQuery.query` and `Job.getQueryResults` returns `TableResult`, not `QueryResponse`.
99
- Instead of `queryResponse.getResult().iterateAll()`, use `tableResult.iterateAll()`.
1010
- This change should make iterating large result sets significantly faster.
11+
- `BigQuery.listTableData` and `Table.list` returns `TableResult` instead of `Page<FieldValueList>`.
12+
- This remains source-compatible, since `TableResult` implements `Page<FieldValueList>`.
13+
- `TableResult` allows inserting `Shema` into each iterated row.
14+
- `TableResult.getTotalRows()` can be called to obtain the total number of rows across pages.
1115
- Various `Job` statistics are no longer available at `QueryResponse`.
1216
- Use `BigQuery.getJob` then `Job.getStatistics` instead.

google-cloud-bigquery/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ Then add the following code to run the query and wait for the result:
179179
```java
180180
// Create a query request
181181
QueryJobConfiguration queryConfig =
182-
QueryJobConfiguration.newBuilder("SELECT * FROM my_dataset_id.my_table_id").build();
182+
QueryJobConfiguration.newBuilder("SELECT my_column FROM my_dataset_id.my_table_id").build();
183183
// Read rows
184184
System.out.println("Table rows:");
185185
for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) {

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ public int hashCode() {
911911
* String tableName = "my_table_name";
912912
* Schema schema = ...;
913913
* String field = "my_field";
914-
* Page<FieldValueList> tableData =
914+
* TableResult tableData =
915915
* bigquery.listTableData(datasetName, tableName, schema);
916916
* for (FieldValueList row : tableData.iterateAll()) {
917917
* row.get(field)
@@ -936,10 +936,10 @@ TableResult listTableData(
936936
* Field.of("word_count", LegacySQLTypeName.STRING),
937937
* Field.of("corpus", LegacySQLTypeName.STRING),
938938
* Field.of("corpus_date", LegacySQLTypeName.STRING));
939-
* Page<FieldValueList> page =
939+
* TableResult tableData =
940940
* bigquery.listTableData(
941941
* TableId.of("bigquery-public-data", "samples", "shakespeare"), schema);
942-
* FieldValueList row = page.getValues().iterator().next();
942+
* FieldValueList row = tableData.getValues().iterator().next();
943943
* System.out.println(row.get("word").getStringValue());
944944
* }</pre>
945945
*

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Job.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,6 @@ public TableResult getQueryResults(QueryResultsOption... options)
273273
"Getting query results is supported only for " + Type.QUERY + " jobs");
274274
}
275275

276-
TableId table = ((QueryJobConfiguration) getConfiguration()).getDestinationTable();
277-
278276
List<QueryResultsOption> waitOptions =
279277
new ArrayList<>(Arrays.asList(DEFAULT_QUERY_WAIT_OPTIONS));
280278
List<TableDataListOption> listOptions = new ArrayList<>();
@@ -301,6 +299,8 @@ public TableResult getQueryResults(QueryResultsOption... options)
301299
if (response.getSchema() == null) {
302300
throw new JobException(getJobId(), response.getErrors());
303301
}
302+
303+
TableId table = ((QueryJobConfiguration) getConfiguration()).getDestinationTable();
304304
return bigquery.listTableData(
305305
table, response.getSchema(), listOptions.toArray(new TableDataListOption[0]));
306306
}

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/JobException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017, Google LLC All rights reserved.
2+
* Copyright 2018 Google LLC All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryResponse.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
@InternalApi
2525
@AutoValue
2626
public abstract class QueryResponse {
27-
QueryResponse() {}
27+
QueryResponse() {
28+
// Package private so users can't subclass it but AutoValue can.
29+
}
2830

2931
// Only null if the job fails.
3032
@Nullable

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Table.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public InsertAllResponse insert(Iterable<InsertAllRequest.RowToInsert> rows,
292292
* <pre>{@code
293293
* // This example reads the result 100 rows per RPC call. If there's no need to limit the number,
294294
* // simply omit the option.
295-
* Page<FieldValueList> page = table.list(TableDataListOption.pageSize(100));
295+
* TableResult page = table.list(TableDataListOption.pageSize(100));
296296
* for (FieldValueList row : page.iterateAll()) {
297297
* // do something with the row
298298
* }
@@ -301,7 +301,7 @@ public InsertAllResponse insert(Iterable<InsertAllRequest.RowToInsert> rows,
301301
* @param options table data list options
302302
* @throws BigQueryException upon failure
303303
*/
304-
public Page<FieldValueList> list(TableDataListOption... options) throws BigQueryException {
304+
public TableResult list(TableDataListOption... options) throws BigQueryException {
305305
return bigquery.listTableData(getTableId(), options);
306306
}
307307

@@ -313,7 +313,7 @@ public Page<FieldValueList> list(TableDataListOption... options) throws BigQuery
313313
* <pre>{@code
314314
* Schema schema = ...;
315315
* String field = "my_field";
316-
* Page<FieldValueList> page = table.list(schema);
316+
* TableResult page = table.list(schema);
317317
* for (FieldValueList row : page.iterateAll()) {
318318
* row.get(field);
319319
* }
@@ -322,7 +322,7 @@ public Page<FieldValueList> list(TableDataListOption... options) throws BigQuery
322322
* @param options table data list options
323323
* @throws BigQueryException upon failure
324324
*/
325-
public Page<FieldValueList> list(Schema schema, TableDataListOption... options)
325+
public TableResult list(Schema schema, TableDataListOption... options)
326326
throws BigQueryException {
327327
return bigquery.listTableData(getTableId(), schema, options);
328328
}

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableResult.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 Google Inc. All Rights Reserved.
2+
* Copyright 2018 Google LLC All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,8 +49,6 @@ public Schema getSchema() {
4949
/**
5050
* Returns the total number of rows in the complete result set, which can be more than the number
5151
* of rows in the first page of results returned by {@link #getValues()}.
52-
*
53-
* <p>If this instance is a result of a dry-run query, returns {@code 0}.
5452
*/
5553
public long getTotalRows() {
5654
return totalRows;

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,6 @@ public void testQueryRequestCompletedOptions() throws InterruptedException {
11971197

11981198
EasyMock.replay(bigqueryRpcMock);
11991199
bigquery = options.getService();
1200-
// TODO(pongad): pagesize = 42
12011200
Job job = bigquery.create(JobInfo.of(queryJob, QUERY_JOB_CONFIGURATION_FOR_QUERY));
12021201
TableResult result = job.getQueryResults(pageSizeOption);
12031202
assertThat(result.getSchema()).isEqualTo(TABLE_SCHEMA);
@@ -1218,11 +1217,6 @@ public void testQueryRequestCompletedOnSecondAttempt() throws InterruptedExcepti
12181217
.setId(JOB);
12191218
jobResponsePb1.getConfiguration().getQuery().setDestinationTable(TABLE_ID.toPb());
12201219

1221-
com.google.api.services.bigquery.model.Job jobResponsePb2 =
1222-
jobResponsePb1
1223-
.clone()
1224-
.setStatus(new com.google.api.services.bigquery.model.JobStatus().setState("DONE"));
1225-
12261220
GetQueryResultsResponse responsePb1 =
12271221
new GetQueryResultsResponse()
12281222
.setJobReference(queryJob.toPb())
@@ -1263,7 +1257,6 @@ public void testQueryRequestCompletedOnSecondAttempt() throws InterruptedExcepti
12631257

12641258
EasyMock.replay(bigqueryRpcMock);
12651259
bigquery = options.getService();
1266-
// TODO(pongad): pagesize = 42
12671260
TableResult result = bigquery.query(QUERY_JOB_CONFIGURATION_FOR_QUERY, queryJob);
12681261
assertThat(result.getSchema()).isEqualTo(TABLE_SCHEMA);
12691262
assertThat(result.getTotalRows()).isEqualTo(1);
@@ -1313,7 +1306,7 @@ public void testGetQueryResultsWithProject() {
13131306
EasyMock.replay(bigqueryRpcMock);
13141307
bigquery = options.getService();
13151308
QueryResponse response = bigquery.getQueryResults(queryJob);
1316-
assertEquals(true, response.getCompleted());
1309+
assertTrue(response.getCompleted());
13171310
assertEquals(null, response.getSchema());
13181311
}
13191312

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/JobTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public void testWaitForAndGetQueryResults() throws InterruptedException {
251251
expect(bigquery.getOptions()).andReturn(mockOptions);
252252
expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()).times(2);
253253
Job completedJob = expectedJob.toBuilder().setStatus(status).build();
254-
// TODO(pongad): remove when https://github.com/googleapis/gax-java/pull/431/ lands.
254+
// TODO(pongad): remove when we bump gax to 1.15.
255255
Page<FieldValueList> emptyPage =
256256
new Page<FieldValueList>() {
257257
@Override

0 commit comments

Comments
 (0)