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 @@ -161,7 +161,12 @@ public com.google.api.services.bigquery.model.Dataset call() {
@Override
public Table create(TableInfo tableInfo, TableOption... options) {
final com.google.api.services.bigquery.model.Table tablePb =
tableInfo.setProjectId(getOptions().getProjectId()).toPb();
tableInfo
.setProjectId(
Strings.isNullOrEmpty(tableInfo.getTableId().getProject())
? getOptions().getProjectId()
: tableInfo.getTableId().getProject())
.toPb();
final Map<BigQueryRpc.Option, ?> optionsMap = optionMap(options);
try {
return Table.fromPb(this,
Expand Down Expand Up @@ -345,7 +350,11 @@ public boolean delete(String datasetId, String tableId) {

@Override
public boolean delete(TableId tableId) {
final TableId completeTableId = tableId.setProjectId(getOptions().getProjectId());
final TableId completeTableId = tableId.setProjectId(
Strings.isNullOrEmpty(tableId.getProject())
? getOptions().getProjectId()
: tableId.getProject()
);
try {
return runWithRetries(new Callable<Boolean>() {
@Override
Expand Down Expand Up @@ -380,7 +389,12 @@ public com.google.api.services.bigquery.model.Dataset call() {
@Override
public Table update(TableInfo tableInfo, TableOption... options) {
final com.google.api.services.bigquery.model.Table tablePb =
tableInfo.setProjectId(getOptions().getProjectId()).toPb();
tableInfo
.setProjectId(
Strings.isNullOrEmpty(tableInfo.getTableId().getProject())
? getOptions().getProjectId()
: tableInfo.getTableId().getProject())
.toPb();
final Map<BigQueryRpc.Option, ?> optionsMap = optionMap(options);
try {
return Table.fromPb(this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,20 @@ public void testCreateTable() {
assertEquals(new Table(bigquery, new TableInfo.BuilderImpl(tableInfo)), table);
}

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

@Test
public void testCreateTableWithSelectedFields() {
Capture<Map<BigQueryRpc.Option, Object>> capturedOptions = Capture.newInstance();
Expand Down Expand Up @@ -728,6 +742,16 @@ public void testDeleteTableFromTableIdWithProject() {
assertTrue(bigquery.delete(tableId));
}

@Test
public void testDeleteTableFromTableIdWithoutProject() {
TableId tableId = TableId.of("", TABLE_ID.getDataset(), TABLE_ID.getTable());
EasyMock.expect(bigqueryRpcMock.deleteTable(PROJECT, DATASET, TABLE)).andReturn(true);
EasyMock.replay(bigqueryRpcMock);
BigQueryOptions bigQueryOptions = createBigQueryOptionsForProject(PROJECT, rpcFactoryMock);
bigquery = bigQueryOptions.getService();
assertTrue(bigquery.delete(tableId));
}

@Test
public void testUpdateTable() {
TableInfo updatedTableInfo =
Expand All @@ -741,6 +765,20 @@ public void testUpdateTable() {
assertEquals(new Table(bigquery, new TableInfo.BuilderImpl(updatedTableInfo)), table);
}

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

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