Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.google.cloud.bigquery.spi.v2.BigQueryRpc;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Strings;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
Expand Down Expand Up @@ -401,7 +402,12 @@ public Table getTable(final String datasetId, final String tableId, TableOption.

@Override
public Table getTable(TableId tableId, TableOption... options) {
final TableId completeTableId = tableId.setProjectId(getOptions().getProjectId());
// More context about why this: https://github.com/googleapis/google-cloud-java/issues/3808
final TableId completeTableId = tableId.setProjectId(
Strings.isNullOrEmpty(tableId.getProject())
? getOptions().getProjectId()
: tableId.getProject()
);
final Map<BigQueryRpc.Option, ?> optionsMap = optionMap(options);
try {
com.google.api.services.bigquery.model.Table answer =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,20 @@ public void testGetTableFromTableIdWithProject() {
assertEquals(new Table(bigquery, new TableInfo.BuilderImpl(tableInfo)), table);
}

@Test
public void testGetTableFromTableIdWithoutProject() {
TableInfo tableInfo = TABLE_INFO.setProjectId(PROJECT);
TableId tableId = TableId.of("", TABLE_ID.getDataset(), TABLE_ID.getTable());
EasyMock.expect(bigqueryRpcMock.getTable(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS))
.andReturn(tableInfo.toPb());
EasyMock.replay(bigqueryRpcMock);
BigQueryOptions bigQueryOptions =
createBigQueryOptionsForProject(PROJECT, rpcFactoryMock);
bigquery = bigQueryOptions.getService();
Table table = bigquery.getTable(tableId);
assertEquals(new Table(bigquery, new TableInfo.BuilderImpl(tableInfo)), table);
}

@Test
public void testGetTableWithSelectedFields() {
Capture<Map<BigQueryRpc.Option, Object>> capturedOptions = Capture.newInstance();
Expand Down