Skip to content

Commit

Permalink
Fix googleapis#3924 ExtractJobConfiguration's setProjectId makes cros…
Browse files Browse the repository at this point in the history
…s-project BQ extracts impossible
  • Loading branch information
ajaaym committed Dec 5, 2018
1 parent 90f8c98 commit 2dbf234
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.api.services.bigquery.model.JobConfigurationTableCopy;
import com.google.common.base.Function;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import java.util.List;
Expand Down Expand Up @@ -216,10 +217,15 @@ CopyJobConfiguration setProjectId(final String projectId) {
new Function<TableId, TableId>() {
@Override
public TableId apply(TableId tableId) {
return tableId.setProjectId(projectId);
if (Strings.isNullOrEmpty(tableId.getProject())) {
return tableId.setProjectId(projectId);
}
return tableId;
}
}));
builder.setDestinationTable(getDestinationTable().setProjectId(projectId));
if (Strings.isNullOrEmpty(getDestinationTable().getProject())) {
builder.setDestinationTable(getDestinationTable().setProjectId(projectId));
}
return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.google.api.services.bigquery.model.JobConfigurationExtract;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -215,7 +216,10 @@ public int hashCode() {

@Override
ExtractJobConfiguration setProjectId(String projectId) {
return toBuilder().setSourceTable(getSourceTable().setProjectId(projectId)).build();
if (Strings.isNullOrEmpty(getSourceTable().getProject())) {
return toBuilder().setSourceTable(getSourceTable().setProjectId(projectId)).build();
}
return this;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.google.api.services.bigquery.model.JobConfigurationLoad;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.primitives.Ints;
import java.util.List;
Expand Down Expand Up @@ -398,7 +399,10 @@ public int hashCode() {

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.cloud.bigquery.JobInfo.WriteDisposition;
import com.google.common.base.Function;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
Expand Down Expand Up @@ -769,7 +770,8 @@ public int hashCode() {
@Override
QueryJobConfiguration setProjectId(String projectId) {
Builder builder = toBuilder();
if (getDestinationTable() != null) {
if (getDestinationTable() != null
&& Strings.isNullOrEmpty(getDestinationTable().getProject())) {
builder.setDestinationTable(getDestinationTable().setProjectId(projectId));
}
if (getDefaultDataset() != null) {
Expand Down

0 comments on commit 2dbf234

Please sign in to comment.