Skip to content

Commit 2120c6d

Browse files
Praful Makanichingor13
authored andcommitted
---
yaml --- r: 11417 b: refs/heads/autosynth-logging c: e53621b h: refs/heads/master i: 11415: 139be4f
1 parent 6b58c7f commit 2120c6d

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
@@ -105,7 +105,7 @@ refs/tags/v0.61.0: e4b526656bb1bf5eefd0ee578b7405147821225e
105105
refs/tags/v0.62.0: bbede7385d48ba08f487bdd29ec10668ace96396
106106
refs/heads/0.60.0-alpha: 10939381ffe0b8da32db4fe3087c86e3aa7f3e55
107107
refs/heads/autosynth-dlp: b09fbe4790ce98bd3c91d8061e488276836ad60b
108-
refs/heads/autosynth-logging: 8da11b0dc3acf69fa8a060b0877f89efbe1f2117
108+
refs/heads/autosynth-logging: e53621bd2d9e1bfe1b24677c43c86f0e4cf0bce0
109109
refs/heads/dupes: 3478c5d81fd242d0e985656645a679420a2060c2
110110
refs/tags/v0.63.0: 94f19b71d40f46b36120e7b9d78a1a3d41bfcbd6
111111
refs/tags/v0.64.0: 456e8fbd129deced3ca025f239a2d8a82bde1d0a

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