Skip to content

Commit b9d2b9a

Browse files
authored
---
yaml --- r: 13239 b: refs/heads/autosynth-texttospeech c: 174e62d h: refs/heads/master i: 13237: 48a4063 13235: a09611c 13231: 02dbb3f
1 parent 7d54a04 commit b9d2b9a

3 files changed

Lines changed: 64 additions & 15 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ refs/heads/autosynth-securitycenter: 8e95447ccb176c3648880ee0cb926cd1f4065156
143143
refs/heads/autosynth-spanner: 563dc6c78c6a2579b681f441f0a9b59005212394
144144
refs/heads/autosynth-speech: 878243784f42771467d7cf52bd59e4a6a7950ee9
145145
refs/heads/autosynth-tasks: afc9f4da54964dea5e7f3a9b164db282fc35db5c
146-
refs/heads/autosynth-texttospeech: 59bd938d9d2b158c3a7fd62c5db48f2fd7654ff4
146+
refs/heads/autosynth-texttospeech: 174e62d18380d339380e6c0aca42126c7a35eb32
147147
refs/heads/autosynth-trace: 80c58aa2fb54b0a9c6876f2c21aa8d19cf55962e
148148
refs/heads/autosynth-websecurityscanner: d4febbffb6c648b74faec62fe90e20adadc9a7d3
149149
refs/heads/bigquerystorage: 06db74d123d7f8a3ef48755c2fcabed09faf8e64

branches/autosynth-texttospeech/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
import com.google.common.base.Function;
4242
import com.google.common.base.Strings;
4343
import com.google.common.base.Supplier;
44+
import com.google.common.collect.FluentIterable;
4445
import com.google.common.collect.ImmutableList;
4546
import com.google.common.collect.Iterables;
46-
import com.google.common.collect.Lists;
4747
import com.google.common.collect.Maps;
4848
import java.util.List;
4949
import java.util.Map;
@@ -548,17 +548,18 @@ public InsertAllResponse insertAll(InsertAllRequest request) {
548548
// an anonymous inner class.
549549
final boolean[] allInsertIdsSet = {true};
550550
List<Rows> rowsPb =
551-
Lists.transform(
552-
request.getRows(),
553-
new Function<RowToInsert, Rows>() {
554-
@Override
555-
public Rows apply(RowToInsert rowToInsert) {
556-
allInsertIdsSet[0] &= rowToInsert.getId() != null;
557-
return new Rows()
558-
.setInsertId(rowToInsert.getId())
559-
.setJson(rowToInsert.getContent());
560-
}
561-
});
551+
FluentIterable.from(request.getRows())
552+
.transform(
553+
new Function<RowToInsert, Rows>() {
554+
@Override
555+
public Rows apply(RowToInsert rowToInsert) {
556+
allInsertIdsSet[0] &= rowToInsert.getId() != null;
557+
return new Rows()
558+
.setInsertId(rowToInsert.getId())
559+
.setJson(rowToInsert.getContent());
560+
}
561+
})
562+
.toList();
562563
requestPb.setRows(rowsPb);
563564

564565
TableDataInsertAllResponse responsePb;

branches/autosynth-texttospeech/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ public void testUpdateTableWithSelectedFields() {
801801
}
802802

803803
@Test
804-
public void testInsertAll() {
804+
public void testInsertAllWithRowIdShouldRetry() {
805805
Map<String, Object> row1 = ImmutableMap.<String, Object>of("field", "value1");
806806
Map<String, Object> row2 = ImmutableMap.<String, Object>of("field", "value2");
807807
List<RowToInsert> rows =
@@ -836,17 +836,65 @@ public TableDataInsertAllRequest.Rows apply(RowToInsert rowToInsert) {
836836
new TableDataInsertAllResponse.InsertErrors()
837837
.setIndex(0L)
838838
.setErrors(ImmutableList.of(new ErrorProto().setMessage("ErrorMessage")))));
839+
EasyMock.expect(bigqueryRpcMock.insertAll(PROJECT, DATASET, TABLE, requestPb))
840+
.andThrow(new BigQueryException(500, "InternalError"));
839841
EasyMock.expect(bigqueryRpcMock.insertAll(PROJECT, DATASET, TABLE, requestPb))
840842
.andReturn(responsePb);
841843
EasyMock.replay(bigqueryRpcMock);
842-
bigquery = options.getService();
844+
bigquery =
845+
options
846+
.toBuilder()
847+
.setRetrySettings(ServiceOptions.getDefaultRetrySettings())
848+
.build()
849+
.getService();
843850
InsertAllResponse response = bigquery.insertAll(request);
844851
assertNotNull(response.getErrorsFor(0L));
845852
assertNull(response.getErrorsFor(1L));
846853
assertEquals(1, response.getErrorsFor(0L).size());
847854
assertEquals("ErrorMessage", response.getErrorsFor(0L).get(0).getMessage());
848855
}
849856

857+
@Test
858+
public void testInsertAllWithoutRowIdShouldNotRetry() {
859+
Map<String, Object> row1 = ImmutableMap.<String, Object>of("field", "value1");
860+
Map<String, Object> row2 = ImmutableMap.<String, Object>of("field", "value2");
861+
List<RowToInsert> rows = ImmutableList.of(RowToInsert.of(row1), RowToInsert.of(row2));
862+
InsertAllRequest request =
863+
InsertAllRequest.newBuilder(TABLE_ID)
864+
.setRows(rows)
865+
.setSkipInvalidRows(false)
866+
.setIgnoreUnknownValues(true)
867+
.setTemplateSuffix("suffix")
868+
.build();
869+
TableDataInsertAllRequest requestPb =
870+
new TableDataInsertAllRequest()
871+
.setRows(
872+
Lists.transform(
873+
rows,
874+
new Function<RowToInsert, TableDataInsertAllRequest.Rows>() {
875+
@Override
876+
public TableDataInsertAllRequest.Rows apply(RowToInsert rowToInsert) {
877+
return new TableDataInsertAllRequest.Rows()
878+
.setInsertId(rowToInsert.getId())
879+
.setJson(rowToInsert.getContent());
880+
}
881+
}))
882+
.setSkipInvalidRows(false)
883+
.setIgnoreUnknownValues(true)
884+
.setTemplateSuffix("suffix");
885+
EasyMock.expect(bigqueryRpcMock.insertAll(PROJECT, DATASET, TABLE, requestPb))
886+
.andThrow(new BigQueryException(500, "InternalError"));
887+
EasyMock.replay(bigqueryRpcMock);
888+
bigquery =
889+
options
890+
.toBuilder()
891+
.setRetrySettings(ServiceOptions.getDefaultRetrySettings())
892+
.build()
893+
.getService();
894+
thrown.expect(BigQueryException.class);
895+
bigquery.insertAll(request);
896+
}
897+
850898
@Test
851899
public void testInsertAllWithProject() {
852900
Map<String, Object> row1 = ImmutableMap.<String, Object>of("field", "value1");

0 commit comments

Comments
 (0)