Skip to content
This repository was archived by the owner on Nov 11, 2022. It is now read-only.

Commit fe13fb7

Browse files
authored
Merge pull request #458 from peihe/fixup-bq-diff
Forward port fixups in Beam PR-1032
2 parents ac1d97b + 1303cb7 commit fe13fb7

2 files changed

Lines changed: 23 additions & 15 deletions

File tree

sdk/src/main/java/com/google/cloud/dataflow/sdk/util/BigQueryTableRowIterator.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,11 @@ public boolean advance() throws IOException, InterruptedException {
177177
list.setPageToken(pageToken);
178178
}
179179

180-
TableDataList result =
181-
executeWithBackOff(
182-
list,
183-
String.format(
184-
"Error reading from BigQuery table %s of dataset %s.",
185-
ref.getTableId(),
186-
ref.getDatasetId()));
180+
TableDataList result = executeWithBackOff(
181+
list,
182+
String.format(
183+
"Error reading from BigQuery table %s of dataset %s.",
184+
ref.getTableId(), ref.getDatasetId()));
187185

188186
pageToken = result.getPageToken();
189187
iteratorOverCurrentBatch =
@@ -370,7 +368,7 @@ private void createDataset(String datasetId, @Nullable String location)
370368
executeWithBackOff(
371369
client.datasets().insert(projectId, dataset),
372370
String.format(
373-
"Error when trying to create the temporary dataset %s in project %s",
371+
"Error when trying to create the temporary dataset %s in project %s.",
374372
datasetId, projectId));
375373
}
376374

@@ -407,7 +405,7 @@ private TableReference executeQueryAndWaitForCompletion()
407405
Job dryRunJob = new Job()
408406
.setConfiguration(new JobConfiguration()
409407
.setQuery(new JobConfigurationQuery()
410-
.setQuery(query))
408+
.setQuery(query))
411409
.setDryRun(true));
412410
JobStatistics jobStats = executeWithBackOff(
413411
client.jobs().insert(projectId, dryRunJob),
@@ -508,7 +506,6 @@ public static <T> T executeWithBackOff(AbstractGoogleClientRequest<T> client, St
508506
}
509507
}
510508
}
511-
512509
return result;
513510
}
514511

sdk/src/test/java/com/google/cloud/dataflow/sdk/util/BigQueryTableRowIteratorTest.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,17 @@ private static Table tableWithBasicSchema() {
133133
new TableFieldSchema().setName("anniversary_time").setType("TIME"))));
134134
}
135135

136+
private static Table noTableQuerySchema() {
137+
return new Table()
138+
.setSchema(
139+
new TableSchema()
140+
.setFields(
141+
Arrays.asList(
142+
new TableFieldSchema().setName("name").setType("STRING"),
143+
new TableFieldSchema().setName("count").setType("INTEGER"),
144+
new TableFieldSchema().setName("photo").setType("BYTES"))));
145+
}
146+
136147
private static Table tableWithLocation() {
137148
return new Table()
138149
.setLocation("EU");
@@ -206,6 +217,7 @@ public void testReadFromQuery() throws IOException, InterruptedException {
206217
assertEquals("2000-01-01", row.get("anniversary_date"));
207218
assertEquals("2000-01-01 00:00:00.000005", row.get("anniversary_datetime"));
208219
assertEquals("00:00:00.000005", row.get("anniversary_time"));
220+
209221
assertFalse(iterator.advance());
210222
}
211223

@@ -257,14 +269,13 @@ public void testReadFromQueryNoTables() throws IOException, InterruptedException
257269
when(mockJobsGet.execute()).thenReturn(getJob);
258270

259271
// Mock table schema fetch.
260-
when(mockTablesGet.execute()).thenReturn(tableWithBasicSchema());
272+
when(mockTablesGet.execute()).thenReturn(noTableQuerySchema());
261273

262274
byte[] photoBytes = "photograph".getBytes();
263275
String photoBytesEncoded = BaseEncoding.base64().encode(photoBytes);
264276
// Mock table data fetch.
265277
when(mockTabledataList.execute()).thenReturn(
266-
rawDataList(rawRow("Arthur", 42, photoBytesEncoded,
267-
"2000-01-01", "2000-01-01 00:00:00.000005", "00:00:00.000005")));
278+
rawDataList(rawRow("Arthur", 42, photoBytesEncoded)));
268279

269280
// Run query and verify
270281
String query = String.format(
@@ -277,10 +288,10 @@ public void testReadFromQueryNoTables() throws IOException, InterruptedException
277288
TableRow row = iterator.getCurrent();
278289

279290
assertTrue(row.containsKey("name"));
280-
assertTrue(row.containsKey("answer"));
291+
assertTrue(row.containsKey("count"));
281292
assertTrue(row.containsKey("photo"));
282293
assertEquals("Arthur", row.get("name"));
283-
assertEquals(42, row.get("answer"));
294+
assertEquals(42, row.get("count"));
284295
assertEquals(photoBytesEncoded, row.get("photo"));
285296

286297
assertFalse(iterator.advance());

0 commit comments

Comments
 (0)