@Override public TableId apply(TableId tableId) { return tableId.setProjectId(TEST_PROJECT_ID); } }))
@Override public TableId apply(TableId tableId) { if (Strings.isNullOrEmpty(tableId.getProject())) { return tableId.setProjectId(projectId); } return tableId; } }));
@Override LoadJobConfiguration setProjectId(String projectId) { if (Strings.isNullOrEmpty(getDestinationTable().getProject())) { return toBuilder().setDestinationTable(getDestinationTable().setProjectId(projectId)).build(); } return this; }
@Override ExtractJobConfiguration setProjectId(String projectId) { if (Strings.isNullOrEmpty(getSourceTable().getProject())) { return toBuilder().setSourceTable(getSourceTable().setProjectId(projectId)).build(); } return this; }
@Override CopyJobConfiguration setProjectId(final String projectId) { Builder builder = toBuilder(); builder.setSourceTables( Lists.transform( getSourceTables(), new Function<TableId, TableId>() { @Override public TableId apply(TableId tableId) { if (Strings.isNullOrEmpty(tableId.getProject())) { return tableId.setProjectId(projectId); } return tableId; } })); if (Strings.isNullOrEmpty(getDestinationTable().getProject())) { builder.setDestinationTable(getDestinationTable().setProjectId(projectId)); } return builder.build(); }
TableInfo setProjectId(String projectId) { if (Strings.isNullOrEmpty(getTableId().getProject())) { return toBuilder().setTableId(getTableId().setProjectId(projectId)).build(); } return this; }
@Test public void testDeleteTableFromTableIdWithProject() { TableId tableId = TABLE_ID.setProjectId(OTHER_PROJECT); EasyMock.expect(bigqueryRpcMock.deleteTable(OTHER_PROJECT, DATASET, TABLE)).andReturn(true); EasyMock.replay(bigqueryRpcMock); BigQueryOptions bigQueryOptions = createBigQueryOptionsForProject(OTHER_PROJECT, rpcFactoryMock); bigquery = bigQueryOptions.getService(); assertTrue(bigquery.delete(tableId)); }
@Test public void testSetProjectId() { TableId differentProjectTable = TableId.of("differentProject", "dataset", "table"); assertEquals(differentProjectTable, TABLE.setProjectId("differentProject")); }
WriteChannelConfiguration setProjectId(String projectId) { if (Strings.isNullOrEmpty(getDestinationTable().getProject())) { return toBuilder().setDestinationTable(getDestinationTable().setProjectId(projectId)).build(); } return this; }
@Override QueryJobConfiguration setProjectId(String projectId) { Builder builder = toBuilder(); if (getDestinationTable() != null && Strings.isNullOrEmpty(getDestinationTable().getProject())) { builder.setDestinationTable(getDestinationTable().setProjectId(projectId)); } if (getDefaultDataset() != null) { builder.setDefaultDataset(getDefaultDataset().setProjectId(projectId)); } return builder.build(); }
@Test public void testListTableDataFromTableIdWithProject() { TableId tableId = TABLE_ID.setProjectId(OTHER_PROJECT); EasyMock.expect(bigqueryRpcMock.listTableData(OTHER_PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS)) .andReturn(TABLE_DATA_PB); EasyMock.replay(bigqueryRpcMock); BigQueryOptions bigQueryOptions = createBigQueryOptionsForProject(OTHER_PROJECT, rpcFactoryMock); bigquery = bigQueryOptions.getService(); Page<FieldValueList> page = bigquery.listTableData(tableId); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals(TABLE_DATA.toArray(), Iterables.toArray(page.getValues(), List.class)); }
@Override public boolean delete(TableId tableId) { final TableId completeTableId = tableId.setProjectId( Strings.isNullOrEmpty(tableId.getProject()) ? getOptions().getProjectId() : tableId.getProject()); try { return runWithRetries( new Callable<Boolean>() { @Override public Boolean call() { return bigQueryRpc.deleteTable( completeTableId.getProject(), completeTableId.getDataset(), completeTableId.getTable()); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); } catch (RetryHelper.RetryHelperException e) { throw BigQueryException.translateAndThrow(e); } }
@Test public void testGetTableFromTableIdWithProject() { TableInfo tableInfo = TABLE_INFO.setProjectId(OTHER_PROJECT); TableId tableId = TABLE_ID.setProjectId(OTHER_PROJECT); EasyMock.expect(bigqueryRpcMock.getTable(OTHER_PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS)) .andReturn(tableInfo.toPb()); EasyMock.replay(bigqueryRpcMock); BigQueryOptions bigQueryOptions = createBigQueryOptionsForProject(OTHER_PROJECT, rpcFactoryMock); bigquery = bigQueryOptions.getService(); Table table = bigquery.getTable(tableId); assertEquals(new Table(bigquery, new TableInfo.BuilderImpl(tableInfo)), table); }
@Override public Table getTable(TableId tableId, TableOption... options) { // 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 = runWithRetries( new Callable<com.google.api.services.bigquery.model.Table>() { @Override public com.google.api.services.bigquery.model.Table call() { return bigQueryRpc.getTable( completeTableId.getProject(), completeTableId.getDataset(), completeTableId.getTable(), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Table.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw BigQueryException.translateAndThrow(e); } }
@Test public void testSetProjectIdDoNotOverride() { LoadConfiguration configuration = LOAD_CONFIGURATION_CSV .toBuilder() .setDestinationTable(TABLE_ID.setProjectId(TEST_PROJECT_ID)) .build() .setProjectId("do-not-update"); assertEquals(TEST_PROJECT_ID, configuration.getDestinationTable().getProject()); }
try { final TableId completeTableId = tableId.setProjectId( Strings.isNullOrEmpty(serviceOptions.getProjectId()) ? tableId.getProject()
request .getTable() .setProjectId( Strings.isNullOrEmpty(request.getTable().getProject()) ? getOptions().getProjectId()
@Test public void testSetProjectIdDoNotOverride() { ExtractJobConfiguration configuration = EXTRACT_CONFIGURATION .toBuilder() .setSourceTable(TABLE_ID.setProjectId(TEST_PROJECT_ID)) .build() .setProjectId("do-not-update"); assertEquals(TEST_PROJECT_ID, configuration.getSourceTable().getProject()); }
@Test public void testSetProjectIdDoNotOverride() { CopyJobConfiguration configuration = COPY_JOB_CONFIGURATION_MULTIPLE_TABLES .toBuilder() .setSourceTables( Lists.transform( SOURCE_TABLES, new Function<TableId, TableId>() { @Override public TableId apply(TableId tableId) { return tableId.setProjectId(TEST_PROJECT_ID); } })) .setDestinationTable(DESTINATION_TABLE.setProjectId(TEST_PROJECT_ID)) .build() .setProjectId("do-not-update"); assertEquals(TEST_PROJECT_ID, configuration.getDestinationTable().getProject()); for (TableId sourceTable : configuration.getSourceTables()) { assertEquals(TEST_PROJECT_ID, sourceTable.getProject()); } }
@Test public void testSetProjectIdDoNotOverride() { QueryJobConfiguration configuration = QUERY_JOB_CONFIGURATION .toBuilder() .setDestinationTable(TABLE_ID.setProjectId(TEST_PROJECT_ID)) .build() .setProjectId("update-only-on-dataset"); assertEquals("update-only-on-dataset", configuration.getDefaultDataset().getProject()); assertEquals(TEST_PROJECT_ID, configuration.getDestinationTable().getProject()); }