Skip to content

Commit aa38428

Browse files
feat: return JobID with TableResult (#2689)
* chore: improve job create retry * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore: remove option 2 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore: pass jobid from job.getQUeryResults() * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * choreL set jobID as null when empty * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore: add IT tests * chore: complete tests * chore: make setJobId package private * chore: remove redundant job ID setting * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent e371e65 commit aa38428

File tree

5 files changed

+78
-11
lines changed

5 files changed

+78
-11
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,20 @@ If you are using Maven without the BOM, add this to your dependencies:
5353
If you are using Gradle 5.x or later, add this to your dependencies:
5454

5555
```Groovy
56-
implementation platform('com.google.cloud:libraries-bom:26.16.0')
56+
implementation platform('com.google.cloud:libraries-bom:26.17.0')
5757
5858
implementation 'com.google.cloud:google-cloud-bigquery'
5959
```
6060
If you are using Gradle without BOM, add this to your dependencies:
6161

6262
```Groovy
63-
implementation 'com.google.cloud:google-cloud-bigquery:2.27.0'
63+
implementation 'com.google.cloud:google-cloud-bigquery:2.27.1'
6464
```
6565

6666
If you are using SBT, add this to your dependencies:
6767

6868
```Scala
69-
libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.27.0"
69+
libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.27.1"
7070
```
7171
<!-- {x-version-update-end} -->
7272

@@ -350,7 +350,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
350350
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-bigquery/java11.html
351351
[stability-image]: https://img.shields.io/badge/stability-stable-green
352352
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-bigquery.svg
353-
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-bigquery/2.27.0
353+
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-bigquery/2.27.1
354354
[authentication]: https://github.com/googleapis/google-cloud-java#authentication
355355
[auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes
356356
[predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ public com.google.api.services.bigquery.model.Job call() {
411411
}
412412
},
413413
getOptions().getRetrySettings(),
414-
EXCEPTION_HANDLER,
414+
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
415415
getOptions().getClock(),
416416
DEFAULT_RETRY_CONFIG));
417417
} catch (BigQueryRetryHelper.BigQueryRetryHelperException e) {
@@ -1334,7 +1334,7 @@ public com.google.api.services.bigquery.model.QueryResponse call() {
13341334
List<BigQueryError> bigQueryErrors =
13351335
Lists.transform(results.getErrors(), BigQueryError.FROM_PB_FUNCTION);
13361336
// Throwing BigQueryException since there may be no JobId and we want to stay consistent
1337-
// with the case where there there is a HTTP error
1337+
// with the case where there is an HTTP error
13381338
throw new BigQueryException(bigQueryErrors);
13391339
}
13401340

@@ -1369,7 +1369,9 @@ public com.google.api.services.bigquery.model.QueryResponse call() {
13691369
new QueryPageFetcher(jobId, schema, getOptions(), cursor, optionMap(options)),
13701370
cursor,
13711371
// cache first page of result
1372-
transformTableData(results.getRows(), schema)));
1372+
transformTableData(results.getRows(), schema)),
1373+
// Return the JobID of the successful job
1374+
jobId);
13731375
}
13741376
// only 1 page of result
13751377
return new TableResult(
@@ -1378,7 +1380,9 @@ public com.google.api.services.bigquery.model.QueryResponse call() {
13781380
new PageImpl<>(
13791381
new TableDataPageFetcher(null, schema, getOptions(), null, optionMap(options)),
13801382
null,
1381-
transformTableData(results.getRows(), schema)));
1383+
transformTableData(results.getRows(), schema)),
1384+
// Return the JobID of the successful job
1385+
results.getJobReference() != null ? JobId.fromPb(results.getJobReference()) : null);
13821386
}
13831387

13841388
@Override

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -311,15 +311,20 @@ public TableResult getQueryResults(QueryResultsOption... options)
311311
// Listing table data might fail, such as with CREATE VIEW queries.
312312
// Avoid a tabledata.list API request by returning an empty TableResult.
313313
if (response.getTotalRows() == 0) {
314-
return new EmptyTableResult(response.getSchema());
314+
TableResult emptyTableResult = new EmptyTableResult(response.getSchema());
315+
emptyTableResult.setJobId(job.getJobId());
316+
return emptyTableResult;
315317
}
316318

317319
TableId table =
318320
((QueryJobConfiguration) getConfiguration()).getDestinationTable() == null
319321
? ((QueryJobConfiguration) job.getConfiguration()).getDestinationTable()
320322
: ((QueryJobConfiguration) getConfiguration()).getDestinationTable();
321-
return bigquery.listTableData(
322-
table, response.getSchema(), listOptions.toArray(new TableDataListOption[0]));
323+
TableResult tableResult =
324+
bigquery.listTableData(
325+
table, response.getSchema(), listOptions.toArray(new TableDataListOption[0]));
326+
tableResult.setJobId(job.getJobId());
327+
return tableResult;
323328
}
324329

325330
private QueryResponse waitForQueryResults(

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

+19
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ public class TableResult implements Page<FieldValueList>, Serializable {
3535
@Nullable private final Schema schema;
3636
private final long totalRows;
3737
private final Page<FieldValueList> pageNoSchema;
38+
@Nullable private JobId jobId = null;
39+
40+
// package-private so job id is not set outside the package.
41+
void setJobId(@Nullable JobId jobId) {
42+
this.jobId = jobId;
43+
}
44+
45+
public JobId getJobId() {
46+
return jobId;
47+
}
3848

3949
/**
4050
* If {@code schema} is non-null, {@code TableResult} adds the schema to {@code FieldValueList}s
@@ -47,6 +57,15 @@ public TableResult(Schema schema, long totalRows, Page<FieldValueList> pageNoSch
4757
this.pageNoSchema = checkNotNull(pageNoSchema);
4858
}
4959

60+
@InternalApi("Exposed for testing")
61+
public TableResult(
62+
Schema schema, long totalRows, Page<FieldValueList> pageNoSchema, JobId jobId) {
63+
this.schema = schema;
64+
this.totalRows = totalRows;
65+
this.pageNoSchema = checkNotNull(pageNoSchema);
66+
this.jobId = jobId;
67+
}
68+
5069
/** Returns the schema of the results. Null if the schema is not supplied. */
5170
public Schema getSchema() {
5271
return schema;

0 commit comments

Comments
 (0)