Skip to content

Commit e583840

Browse files
MMMarcyJesseLovelace
authored andcommitted
---
yaml --- r: 10235 b: refs/heads/master c: 19fe6eb h: refs/heads/master i: 10233: 135a7b9 10231: a84e688
1 parent 25ab69e commit e583840

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 5e0bca48db72eb071d1335fb23bdcd1120c351c4
2+
refs/heads/master: 19fe6eb7ff170afed47384c65ede94891821afc1
33
refs/heads/travis: 47e4fee4fd5af9b2a8ce46f23c72ec95f9b195b2
44
refs/heads/gh-pages: 9557e74bb0c6b2918b40660d6d1b35f742e5e727
55
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

trunk/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
@@ -39,6 +39,7 @@
3939
import com.google.cloud.bigquery.spi.v2.BigQueryRpc;
4040
import com.google.common.annotations.VisibleForTesting;
4141
import com.google.common.base.Function;
42+
import com.google.common.base.Strings;
4243
import com.google.common.base.Supplier;
4344
import com.google.common.collect.ImmutableList;
4445
import com.google.common.collect.Iterables;
@@ -401,7 +402,12 @@ public Table getTable(final String datasetId, final String tableId, TableOption.
401402

402403
@Override
403404
public Table getTable(TableId tableId, TableOption... options) {
404-
final TableId completeTableId = tableId.setProjectId(getOptions().getProjectId());
405+
// More context about why this: https://github.com/googleapis/google-cloud-java/issues/3808
406+
final TableId completeTableId = tableId.setProjectId(
407+
Strings.isNullOrEmpty(tableId.getProject())
408+
? getOptions().getProjectId()
409+
: tableId.getProject()
410+
);
405411
final Map<BigQueryRpc.Option, ?> optionsMap = optionMap(options);
406412
try {
407413
com.google.api.services.bigquery.model.Table answer =

trunk/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,20 @@ public void testGetTableFromTableIdWithProject() {
603603
assertEquals(new Table(bigquery, new TableInfo.BuilderImpl(tableInfo)), table);
604604
}
605605

606+
@Test
607+
public void testGetTableFromTableIdWithoutProject() {
608+
TableInfo tableInfo = TABLE_INFO.setProjectId(PROJECT);
609+
TableId tableId = TableId.of("", TABLE_ID.getDataset(), TABLE_ID.getTable());
610+
EasyMock.expect(bigqueryRpcMock.getTable(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS))
611+
.andReturn(tableInfo.toPb());
612+
EasyMock.replay(bigqueryRpcMock);
613+
BigQueryOptions bigQueryOptions =
614+
createBigQueryOptionsForProject(PROJECT, rpcFactoryMock);
615+
bigquery = bigQueryOptions.getService();
616+
Table table = bigquery.getTable(tableId);
617+
assertEquals(new Table(bigquery, new TableInfo.BuilderImpl(tableInfo)), table);
618+
}
619+
606620
@Test
607621
public void testGetTableWithSelectedFields() {
608622
Capture<Map<BigQueryRpc.Option, Object>> capturedOptions = Capture.newInstance();

0 commit comments

Comments
 (0)