Skip to content

Commit 96ae3a2

Browse files
Praful Makanichingor13
authored andcommitted
---
yaml --- r: 11551 b: refs/heads/autosynth-dataproc c: e53621b h: refs/heads/master i: 11549: b8b1b43 11547: 2a77c63 11543: 3eda5e0 11535: de393a6 11519: 01262c7
1 parent c166d15 commit 96ae3a2

3 files changed

Lines changed: 56 additions & 4 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ refs/tags/v0.66.0: ed6a3f57cbdaa20339a1995f7d7d53b172a5b8ef
114114
refs/tags/v0.67.0: 30b56f02092efc6f3c3667650ea8b8825003e0b7
115115
refs/heads/autosynth-compute: fa508ebab5b6a1db14949441c8de868cefbcf1a6
116116
refs/heads/autosynth-container: d0346e84b1f26e3dc10444450a998f357a43bcef
117-
refs/heads/autosynth-dataproc: 8da11b0dc3acf69fa8a060b0877f89efbe1f2117
117+
refs/heads/autosynth-dataproc: e53621bd2d9e1bfe1b24677c43c86f0e4cf0bce0
118118
refs/heads/autosynth-monitoring: 2cb98362409ff765ae26032b64bc84191cdc6dda
119119
refs/heads/autosynth-pubsub: 957d781d8d170777a53a948cd958e368a96eacd5
120120
refs/heads/autosynth-video-intelligence: 06fb1841ae847f4ef79a62ba995efbabc213edf8

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,12 @@ public com.google.api.services.bigquery.model.Dataset call() {
161161
@Override
162162
public Table create(TableInfo tableInfo, TableOption... options) {
163163
final com.google.api.services.bigquery.model.Table tablePb =
164-
tableInfo.setProjectId(getOptions().getProjectId()).toPb();
164+
tableInfo
165+
.setProjectId(
166+
Strings.isNullOrEmpty(tableInfo.getTableId().getProject())
167+
? getOptions().getProjectId()
168+
: tableInfo.getTableId().getProject())
169+
.toPb();
165170
final Map<BigQueryRpc.Option, ?> optionsMap = optionMap(options);
166171
try {
167172
return Table.fromPb(this,
@@ -345,7 +350,11 @@ public boolean delete(String datasetId, String tableId) {
345350

346351
@Override
347352
public boolean delete(TableId tableId) {
348-
final TableId completeTableId = tableId.setProjectId(getOptions().getProjectId());
353+
final TableId completeTableId = tableId.setProjectId(
354+
Strings.isNullOrEmpty(tableId.getProject())
355+
? getOptions().getProjectId()
356+
: tableId.getProject()
357+
);
349358
try {
350359
return runWithRetries(new Callable<Boolean>() {
351360
@Override
@@ -380,7 +389,12 @@ public com.google.api.services.bigquery.model.Dataset call() {
380389
@Override
381390
public Table update(TableInfo tableInfo, TableOption... options) {
382391
final com.google.api.services.bigquery.model.Table tablePb =
383-
tableInfo.setProjectId(getOptions().getProjectId()).toPb();
392+
tableInfo
393+
.setProjectId(
394+
Strings.isNullOrEmpty(tableInfo.getTableId().getProject())
395+
? getOptions().getProjectId()
396+
: tableInfo.getTableId().getProject())
397+
.toPb();
384398
final Map<BigQueryRpc.Option, ?> optionsMap = optionMap(options);
385399
try {
386400
return Table.fromPb(this,

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,20 @@ public void testCreateTable() {
552552
assertEquals(new Table(bigquery, new TableInfo.BuilderImpl(tableInfo)), table);
553553
}
554554

555+
@Test
556+
public void testCreateTableWithoutProject() {
557+
TableInfo tableInfo = TABLE_INFO.setProjectId(PROJECT);
558+
TableId tableId = TableId.of("", TABLE_ID.getDataset(), TABLE_ID.getTable());
559+
tableInfo.toBuilder().setTableId(tableId);
560+
EasyMock.expect(bigqueryRpcMock.create(tableInfo.toPb(), EMPTY_RPC_OPTIONS))
561+
.andReturn(tableInfo.toPb());
562+
EasyMock.replay(bigqueryRpcMock);
563+
BigQueryOptions bigQueryOptions = createBigQueryOptionsForProject(PROJECT, rpcFactoryMock);
564+
bigquery = bigQueryOptions.getService();
565+
Table table = bigquery.create(tableInfo);
566+
assertEquals(new Table(bigquery, new TableInfo.BuilderImpl(tableInfo)), table);
567+
}
568+
555569
@Test
556570
public void testCreateTableWithSelectedFields() {
557571
Capture<Map<BigQueryRpc.Option, Object>> capturedOptions = Capture.newInstance();
@@ -728,6 +742,16 @@ public void testDeleteTableFromTableIdWithProject() {
728742
assertTrue(bigquery.delete(tableId));
729743
}
730744

745+
@Test
746+
public void testDeleteTableFromTableIdWithoutProject() {
747+
TableId tableId = TableId.of("", TABLE_ID.getDataset(), TABLE_ID.getTable());
748+
EasyMock.expect(bigqueryRpcMock.deleteTable(PROJECT, DATASET, TABLE)).andReturn(true);
749+
EasyMock.replay(bigqueryRpcMock);
750+
BigQueryOptions bigQueryOptions = createBigQueryOptionsForProject(PROJECT, rpcFactoryMock);
751+
bigquery = bigQueryOptions.getService();
752+
assertTrue(bigquery.delete(tableId));
753+
}
754+
731755
@Test
732756
public void testUpdateTable() {
733757
TableInfo updatedTableInfo =
@@ -741,6 +765,20 @@ public void testUpdateTable() {
741765
assertEquals(new Table(bigquery, new TableInfo.BuilderImpl(updatedTableInfo)), table);
742766
}
743767

768+
@Test
769+
public void testUpdateTableWithoutProject() {
770+
TableInfo tableInfo = TABLE_INFO.setProjectId(PROJECT);
771+
TableId tableId = TableId.of("", TABLE_ID.getDataset(), TABLE_ID.getTable());
772+
tableInfo.toBuilder().setTableId(tableId);
773+
EasyMock.expect(bigqueryRpcMock.patch(tableInfo.toPb(), EMPTY_RPC_OPTIONS))
774+
.andReturn(tableInfo.toPb());
775+
EasyMock.replay(bigqueryRpcMock);
776+
BigQueryOptions bigQueryOptions = createBigQueryOptionsForProject(PROJECT, rpcFactoryMock);
777+
bigquery = bigQueryOptions.getService();
778+
Table table = bigquery.update(tableInfo);
779+
assertEquals(new Table(bigquery, new TableInfo.BuilderImpl(tableInfo)), table);
780+
}
781+
744782
@Test
745783
public void testUpdateTableWithSelectedFields() {
746784
Capture<Map<BigQueryRpc.Option, Object>> capturedOptions = Capture.newInstance();

0 commit comments

Comments
 (0)