Skip to content

Commit 7620e6f

Browse files
Praful MakaniJesseLovelace
authored andcommitted
---
yaml --- r: 13179 b: refs/heads/autosynth-speech c: 74a4517 h: refs/heads/master i: 13177: 2b78994 13175: 976121a
1 parent c6affef commit 7620e6f

3 files changed

Lines changed: 59 additions & 2 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ refs/heads/autosynth-redis: 4c68cb0fbc599124e717ab3f24bd8a8a5d085ca9
141141
refs/heads/autosynth-scheduler: 2f0fe714a8541dc72f88b45bddd8748e5f21cf29
142142
refs/heads/autosynth-securitycenter: 8e95447ccb176c3648880ee0cb926cd1f4065156
143143
refs/heads/autosynth-spanner: 563dc6c78c6a2579b681f441f0a9b59005212394
144-
refs/heads/autosynth-speech: bb3cfb437f216ca08f869f051a6cefd20a010e17
144+
refs/heads/autosynth-speech: 74a4517cc99b2a3d5c3505baeb607e249f7aab82
145145
refs/heads/autosynth-tasks: afc9f4da54964dea5e7f3a9b164db282fc35db5c
146146
refs/heads/autosynth-texttospeech: a447278ab2ec3975aab3b641549c6780eac0a07a
147147
refs/heads/autosynth-trace: 80c58aa2fb54b0a9c6876f2c21aa8d19cf55962e

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,13 @@ public Table apply(com.google.api.services.bigquery.model.Table table) {
539539

540540
@Override
541541
public InsertAllResponse insertAll(InsertAllRequest request) {
542-
final TableId tableId = request.getTable().setProjectId(getOptions().getProjectId());
542+
final TableId tableId =
543+
request
544+
.getTable()
545+
.setProjectId(
546+
Strings.isNullOrEmpty(request.getTable().getProject())
547+
? getOptions().getProjectId()
548+
: request.getTable().getProject());
543549
final TableDataInsertAllRequest requestPb = new TableDataInsertAllRequest();
544550
requestPb.setIgnoreUnknownValues(request.ignoreUnknownValues());
545551
requestPb.setSkipInvalidRows(request.skipInvalidRows());

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,57 @@ public TableDataInsertAllRequest.Rows apply(RowToInsert rowToInsert) {
945945
assertEquals("ErrorMessage", response.getErrorsFor(0L).get(0).getMessage());
946946
}
947947

948+
@Test
949+
public void testInsertAllWithProjectInTable() {
950+
Map<String, Object> row1 = ImmutableMap.<String, Object>of("field", "value1");
951+
Map<String, Object> row2 = ImmutableMap.<String, Object>of("field", "value2");
952+
List<RowToInsert> rows =
953+
ImmutableList.of(new RowToInsert("row1", row1), new RowToInsert("row2", row2));
954+
TableId tableId = TableId.of("project-different-from-option", DATASET, TABLE);
955+
InsertAllRequest request =
956+
InsertAllRequest.newBuilder(tableId)
957+
.setRows(rows)
958+
.setSkipInvalidRows(false)
959+
.setIgnoreUnknownValues(true)
960+
.setTemplateSuffix("suffix")
961+
.build();
962+
TableDataInsertAllRequest requestPb =
963+
new TableDataInsertAllRequest()
964+
.setRows(
965+
Lists.transform(
966+
rows,
967+
new Function<RowToInsert, TableDataInsertAllRequest.Rows>() {
968+
@Override
969+
public TableDataInsertAllRequest.Rows apply(RowToInsert rowToInsert) {
970+
return new TableDataInsertAllRequest.Rows()
971+
.setInsertId(rowToInsert.getId())
972+
.setJson(rowToInsert.getContent());
973+
}
974+
}))
975+
.setSkipInvalidRows(false)
976+
.setIgnoreUnknownValues(true)
977+
.setTemplateSuffix("suffix");
978+
TableDataInsertAllResponse responsePb =
979+
new TableDataInsertAllResponse()
980+
.setInsertErrors(
981+
ImmutableList.of(
982+
new TableDataInsertAllResponse.InsertErrors()
983+
.setIndex(0L)
984+
.setErrors(ImmutableList.of(new ErrorProto().setMessage("ErrorMessage")))));
985+
EasyMock.expect(
986+
bigqueryRpcMock.insertAll("project-different-from-option", DATASET, TABLE, requestPb))
987+
.andReturn(responsePb);
988+
EasyMock.replay(bigqueryRpcMock);
989+
BigQueryOptions bigQueryOptions =
990+
createBigQueryOptionsForProject(OTHER_PROJECT, rpcFactoryMock);
991+
bigquery = bigQueryOptions.getService();
992+
InsertAllResponse response = bigquery.insertAll(request);
993+
assertNotNull(response.getErrorsFor(0L));
994+
assertNull(response.getErrorsFor(1L));
995+
assertEquals(1, response.getErrorsFor(0L).size());
996+
assertEquals("ErrorMessage", response.getErrorsFor(0L).get(0).getMessage());
997+
}
998+
948999
@Test
9491000
public void testListTableData() {
9501001
EasyMock.expect(bigqueryRpcMock.listTableData(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS))

0 commit comments

Comments
 (0)