Skip to content

Commit 0f5693a

Browse files
mikekapsduskis
authored andcommitted
---
yaml --- r: 13911 b: refs/heads/autosynth-compute c: 2e239f7 h: refs/heads/master i: 13909: a024163 13907: 4fff1d7 13903: 5564a5c
1 parent 00bbbf8 commit 0f5693a

4 files changed

Lines changed: 54 additions & 4 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ refs/tags/v0.64.0: 456e8fbd129deced3ca025f239a2d8a82bde1d0a
112112
refs/tags/v0.65.0: 10939381ffe0b8da32db4fe3087c86e3aa7f3e55
113113
refs/tags/v0.66.0: ed6a3f57cbdaa20339a1995f7d7d53b172a5b8ef
114114
refs/tags/v0.67.0: 30b56f02092efc6f3c3667650ea8b8825003e0b7
115-
refs/heads/autosynth-compute: 68963f79cc77a873914cd60f28715a806cf5a230
115+
refs/heads/autosynth-compute: 2e239f7148c852b7b7e2de4af66e8e5707d9d049
116116
refs/heads/autosynth-container: d0346e84b1f26e3dc10444450a998f357a43bcef
117117
refs/heads/autosynth-dataproc: bc74a8841bc1693d7945d991d15979df550b1fd1
118118
refs/heads/autosynth-monitoring: 120f508e0065f4ce39cf0e6a69a08138773f2cfb

branches/autosynth-compute/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/EmptyTableResult.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818

1919
import com.google.api.core.InternalApi;
2020
import com.google.cloud.PageImpl;
21+
import javax.annotation.Nullable;
2122

2223
public class EmptyTableResult extends TableResult {
2324

2425
private static final long serialVersionUID = -4831062717210349819L;
2526

2627
/** An empty {@code TableResult} to avoid making API requests to unlistable tables. */
2728
@InternalApi("Exposed for testing")
28-
public EmptyTableResult() {
29-
super(null, 0, new PageImpl<FieldValueList>(null, "", null));
29+
public EmptyTableResult(@Nullable Schema schema) {
30+
super(schema, 0, new PageImpl<FieldValueList>(null, "", null));
3031
}
3132
}

branches/autosynth-compute/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Job.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public TableResult getQueryResults(QueryResultsOption... options)
305305
// Listing table data might fail, such as with CREATE VIEW queries.
306306
// Avoid a tabledata.list API request by returning an empty TableResult.
307307
if (response.getTotalRows() == 0) {
308-
return new EmptyTableResult();
308+
return new EmptyTableResult(response.getSchema());
309309
}
310310

311311
TableId table = ((QueryJobConfiguration) getConfiguration()).getDestinationTable();

branches/autosynth-compute/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/JobTest.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,55 @@ public Iterable<FieldValueList> getValues() {
302302
verify(status, mockOptions);
303303
}
304304

305+
@Test
306+
public void testWaitForAndGetQueryResultsEmptyWithSchema() throws InterruptedException {
307+
QueryJobConfiguration jobConfig =
308+
QueryJobConfiguration.newBuilder("CREATE VIEW").setDestinationTable(TABLE_ID1).build();
309+
QueryStatistics jobStatistics =
310+
QueryStatistics.newBuilder()
311+
.setCreationTimestamp(1L)
312+
.setEndTime(3L)
313+
.setStartTime(2L)
314+
.build();
315+
JobInfo jobInfo =
316+
JobInfo.newBuilder(jobConfig)
317+
.setJobId(JOB_ID)
318+
.setStatistics(jobStatistics)
319+
.setJobId(JOB_ID)
320+
.setEtag(ETAG)
321+
.setGeneratedId(GENERATED_ID)
322+
.setSelfLink(SELF_LINK)
323+
.setUserEmail(EMAIL)
324+
.setStatus(JOB_STATUS)
325+
.build();
326+
327+
initializeExpectedJob(2, jobInfo);
328+
JobStatus status = createStrictMock(JobStatus.class);
329+
expect(bigquery.getOptions()).andReturn(mockOptions);
330+
expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()).times(2);
331+
Job completedJob = expectedJob.toBuilder().setStatus(status).build();
332+
QueryResponse completedQuery =
333+
QueryResponse.newBuilder()
334+
.setCompleted(true)
335+
.setTotalRows(0)
336+
.setSchema(Schema.of(Field.of("field1", LegacySQLTypeName.BOOLEAN)))
337+
.setErrors(ImmutableList.<BigQueryError>of())
338+
.build();
339+
340+
expect(bigquery.getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS))
341+
.andReturn(completedQuery);
342+
expect(bigquery.getJob(JOB_INFO.getJobId())).andReturn(completedJob);
343+
expect(bigquery.getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS))
344+
.andReturn(completedQuery);
345+
346+
replay(status, bigquery, mockOptions);
347+
initializeJob(jobInfo);
348+
assertThat(job.waitFor(TEST_RETRY_OPTIONS)).isSameAs(completedJob);
349+
assertThat(job.getQueryResults().getSchema())
350+
.isEqualTo(Schema.of(Field.of("field1", LegacySQLTypeName.BOOLEAN)));
351+
verify(status, mockOptions);
352+
}
353+
305354
@Test
306355
public void testWaitForAndGetQueryResults() throws InterruptedException {
307356
QueryJobConfiguration jobConfig =

0 commit comments

Comments
 (0)