8000 BigQuery : Fix setProjectId by pmakani · Pull Request #4227 · googleapis/google-cloud-java · GitHub
[go: up one dir, main page]

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

Filter by extension

Filter by extension

8000
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 @@ -625,7 +625,11 @@ private static Tuple<? extends Page<FieldValueList>, Long> listTableData(
final BigQueryOptions serviceOptions,
final Map<BigQueryRpc.Option, ?> optionsMap) {
try {
final TableId completeTableId = tableId.setProjectId(serviceOptions.getProjectId());
final TableId completeTableId =
tableId.setProjectId(
Strings.isNullOrEmpty(serviceOptions.getProjectId())
? tableId.getProject()
: serviceOptions.getProjectId());
TableDataList result =
runWithRetries(
new Callable<TableDataList>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.api.client.util.Data;
import com.google.api.client.util.Strings;
import com.google.api.core.BetaApi;
import com.google.api.services.bigquery.model.Table;
import com.google.common.base.Function;
Expand Down Expand Up @@ -396,7 +397,10 @@ public static TableInfo of(TableId tableId, TableDefinition definition) {
}

TableInfo setProjectId(String projectId) {
return toBuilder().setTableId(getTableId().setProjectId(projectId)).build();
if (Strings.isNullOrEmpty(getTableId().getProject())) {
return toBuilder().setTableId(getTableId().setProjectId(projectId)).build();
}
return this;
}

Table toPb() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.api.client.util.Strings;
import com.google.api.services.bigquery.model.JobConfigurationLoad;
import com.google.cloud.bigquery.JobInfo.CreateDisposition;
import com.google.cloud.bigquery.JobInfo.SchemaUpdateOption;
Expand Down Expand Up @@ -390,7 +391,10 @@ public int hashCode() {
}

WriteChannelConfiguration setProjectId(String projectId) {
return toBuilder().setDestinationTable(getDestinationTable().setProjectId(projectId)).build();
if (Strings.isNullOrEmpty(getDestinationTable().getProject())) {
return toBuilder().setDestinationTable(getDestinationTable().setProjectId(projectId)).build();
}
return this;
}

com.google.api.services.bigquery.model.JobConfiguration toPb() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ public void testSetProjectId() {
assertEquals("project", VIEW_INFO.setProjectId("project").getTableId().getProject());
}

@Test
public void testSetProjectIdDoNotOverride() {
TableInfo tableInfo = TableInfo.of(TABLE_ID, TABLE_DEFINITION).setProjectId("project");
tableInfo.setProjectId("not-override-project").toBuilder();
assertEquals("project", tableInfo.getTableId().getProject());
}

private void compareTableInfo(TableInfo expected, TableInfo value) {
assertEquals(expected, value);
assertEquals(expected.getTableId(), value.getTableId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ public void testToPbAndFromPb() {
compareLoadConfiguration(configuration, WriteChannelConfiguration.fromPb(configuration.toPb()));
}

@Test
public void testSetProjectIdDoNotOverride() {
WriteChannelConfiguration configuration =
WriteChannelConfiguration.of(TABLE_ID).setProjectId("project");
configuration.setProjectId("different-project").toBuilder();
assertEquals("project", configuration.getDestinationTable().getProject());
}

private void compareLoadConfiguration(
WriteChannelConfiguration expected, WriteChannelConfiguration value) {
assertEquals(expected, value);
Expand Down
0