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

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 @@ -23,6 +23,7 @@
import com.google.cloud.bigquery.BigQuery.DatasetOption;
import com.google.cloud.bigquery.BigQuery.TableListOption;
import com.google.cloud.bigquery.BigQuery.TableOption;
import com.google.common.base.Strings;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.List;
Expand Down Expand Up @@ -275,7 +276,13 @@ public Page<Table> list(TableListOption... options) {
* @throws BigQueryException upon failure
*/
public Table get(String tableId, TableOption... options) {
return bigquery.getTable(TableId.of(getDatasetId().getDataset(), tableId), options);
// Adding the projectId used of getting the DataSet as a parameter for the issue:
// https://github.com/googleapis/java-bigquery/issues/1369
TableId tabId =
Strings.isNullOrEmpty(getDatasetId().getProject())
? TableId.of(getDatasetId().getDataset(), tableId)
: TableId.of(getDatasetId().getProject(), getDatasetId().getDataset(), tableId);
return bigquery.getTable(tabId, options);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ public class DatasetTest {
TableInfo.newBuilder(TableId.of("dataset", "table2"), VIEW_DEFINITION).build();
private static final TableInfo TABLE_INFO3 =
TableInfo.newBuilder(TableId.of("dataset", "table3"), EXTERNAL_TABLE_DEFINITION).build();
private static final String NEW_PROJECT_ID = "projectId2";
private static final TableId TABLE_ID1 = TableId.of(NEW_PROJECT_ID, "dataset", "table3");
private static final TableInfo TABLE_INFO4 =
TableInfo.newBuilder(
TableId.of(NEW_PROJECT_ID, "dataset", "table3"), EXTERNAL_TABLE_DEFINITION)
.build();

@Rule public MockitoRule rule;

Expand Down Expand Up @@ -255,6 +261,16 @@ public void testGet() {
verify(bigquery).getTable(TABLE_INFO1.getTableId());
}

@Test
public void testGetTableWithNewProjectId() {
Table expectedTable = new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO4));
when(bigquery.getTable(TABLE_ID1, null)).thenReturn(expectedTable);
Table table = bigquery.getTable(TABLE_ID1, null);
assertNotNull(table);
assertEquals(table.getTableId().getProject(), NEW_PROJECT_ID);
verify(bigquery).getTable(TABLE_ID1, null);
}

@Test
public void testGetNull() {
when(bigquery.getTable(TABLE_INFO1.getTableId())).thenReturn(null);
Expand Down