Skip to content

Commit 0c4fd23

Browse files
mikekapsduskis
authored andcommitted
---
yaml --- r: 15679 b: refs/heads/autosynth-datastore c: 2e239f7 h: refs/heads/master i: 15677: 356136a 15675: 4968d6a 15671: f354347 15663: 41f06e1 15647: 9c3c5b8 15615: 20d461f
1 parent 2ded07f commit 0c4fd23

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
@@ -129,7 +129,7 @@ refs/heads/autosynth-bigquerystorage: 14ab055598b943ae3f33f484e9fb1653355d08e7
129129
refs/heads/autosynth-bigtable: 2fbcb15847e0e89e79d6dc07420e28d7dfcea894
130130
refs/heads/autosynth-bigtable-admin: 6379a2bc712f2736c83de0e009b4d26da4fa82ca
131131
refs/heads/autosynth-containeranalysis: 039ca5b8db725c76c16a965ff26b2774322b8ef8
132-
refs/heads/autosynth-datastore: 68963f79cc77a873914cd60f28715a806cf5a230
132+
refs/heads/autosynth-datastore: 2e239f7148c852b7b7e2de4af66e8e5707d9d049
133133
refs/heads/autosynth-dialogflow: ebdd13c445b9674ff9ad4601f78d7ecd6f9c3660
134134
refs/heads/autosynth-errorreporting: 3d0566d6bebcc187f148bbed463b5a8e75b1edf6
135135
refs/heads/autosynth-firestore: 92b27fbc8855c9902168695abb0a8f1f433b750b

branches/autosynth-datastore/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-datastore/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-datastore/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)