Skip to content

Commit 9db5138

Browse files
committed
---
yaml --- r: 2221 b: refs/heads/pubsub-alpha c: 70ee77c h: refs/heads/master i: 2219: b6d72b4
1 parent f127a56 commit 9db5138

24 files changed

Lines changed: 180 additions & 111 deletions

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ refs/heads/master: 689bbb466df4b2d5d2483d6edb8ac5c7c7f7c6fa
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: 4e0561bb4504bf647db669a14417b2b2c87ba45d
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3
6-
refs/heads/pubsub-alpha: a2c8b39a513b90928dd6f266c6c96133d88b9de0
6+
refs/heads/pubsub-alpha: 70ee77cae5cca69c1a4c6e274d242b5c09818e7b
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
88
refs/heads/update-datastore: 482954f2c5055231e5b3122ea91d2ba00ce8187c
99
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

branches/pubsub-alpha/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BaseTableInfo.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ protected final boolean baseEquals(BaseTableInfo tableInfo) {
394394
return Objects.equals(toPb(), tableInfo.toPb());
395395
}
396396

397+
BaseTableInfo setProjectId(String projectId) {
398+
return toBuilder().tableId(tableId().setProjectId(projectId)).build();
399+
}
400+
397401
Table toPb() {
398402
Table tablePb = new Table();
399403
tablePb.setTableReference(tableId.toPb());

branches/pubsub-alpha/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BigQueryImpl.java

Lines changed: 8 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import com.google.api.services.bigquery.model.Table;
2626
import com.google.api.services.bigquery.model.TableDataInsertAllRequest;
2727
import com.google.api.services.bigquery.model.TableDataInsertAllRequest.Rows;
28-
import com.google.api.services.bigquery.model.TableReference;
2928
import com.google.api.services.bigquery.model.TableRow;
3029
import com.google.common.base.Function;
3130
import com.google.common.collect.ImmutableList;
@@ -159,7 +158,7 @@ public QueryResult nextPage() {
159158
@Override
160159
public DatasetInfo create(DatasetInfo dataset, DatasetOption... options)
161160
throws BigQueryException {
162-
final Dataset datasetPb = setProjectId(dataset).toPb();
161+
final Dataset datasetPb = dataset.setProjectId(options().projectId()).toPb();
163162
final Map<BigQueryRpc.Option, ?> optionsMap = optionMap(options);
164163
try {
165164
return DatasetInfo.fromPb(runWithRetries(new Callable<Dataset>() {
@@ -176,7 +175,7 @@ public Dataset call() {
176175
@Override
177176
public <T extends BaseTableInfo> T create(T table, TableOption... options)
178177
throws BigQueryException {
179-
final Table tablePb = setProjectId(table).toPb();
178+
final Table tablePb = table.setProjectId(options().projectId()).toPb();
180179
final Map<BigQueryRpc.Option, ?> optionsMap = optionMap(options);
181180
try {
182181
return BaseTableInfo.fromPb(runWithRetries(new Callable<Table>() {
@@ -192,7 +191,7 @@ public Table call() {
192191

193192
@Override
194193
public JobInfo create(JobInfo job, JobOption... options) throws BigQueryException {
195-
final Job jobPb = setProjectId(job).toPb();
194+
final Job jobPb = job.setProjectId(options().projectId()).toPb();
196195
final Map<BigQueryRpc.Option, ?> optionsMap = optionMap(options);
197196
try {
198197
return JobInfo.fromPb(runWithRetries(new Callable<Job>() {
@@ -295,7 +294,7 @@ public Boolean call() {
295294
@Override
296295
public DatasetInfo update(DatasetInfo dataset, DatasetOption... options)
297296
throws BigQueryException {
298-
final Dataset datasetPb = setProjectId(dataset).toPb();
297+
final Dataset datasetPb = dataset.setProjectId(options().projectId()).toPb();
299298
final Map<BigQueryRpc.Option, ?> optionsMap = optionMap(options);
300299
try {
301300
return DatasetInfo.fromPb(runWithRetries(new Callable<Dataset>() {
@@ -312,7 +311,7 @@ public Dataset call() {
312311
@Override
313312
public <T extends BaseTableInfo> T update(T table, TableOption... options)
314313
throws BigQueryException {
315-
final Table tablePb = setProjectId(table).toPb();
314+
final Table tablePb = table.setProjectId(options().projectId()).toPb();
316315
final Map<BigQueryRpc.Option, ?> optionsMap = optionMap(options);
317316
try {
318317
return BaseTableInfo.fromPb(runWithRetries(new Callable<Table>() {
@@ -508,7 +507,7 @@ public QueryResponse query(final QueryRequest request) throws BigQueryException
508507
runWithRetries(new Callable<com.google.api.services.bigquery.model.QueryResponse>() {
509508
@Override
510509
public com.google.api.services.bigquery.model.QueryResponse call() {
511-
return bigQueryRpc.query(setProjectId(request).toPb());
510+
return bigQueryRpc.query(request.setProjectId(options().projectId()).toPb());
512511
}
513512
}, options().retryParams(), EXCEPTION_HANDLER);
514513
QueryResponse.Builder builder = QueryResponse.builder();
@@ -597,7 +596,8 @@ private static QueryResult.Builder transformQueryResults(JobId jobId, List<Table
597596
}
598597

599598
public TableDataWriteChannel writer(WriteChannelConfiguration writeChannelConfiguration) {
600-
return new TableDataWriteChannel(options(), setProjectId(writeChannelConfiguration));
599+
return new TableDataWriteChannel(options(),
600+
writeChannelConfiguration.setProjectId(options().projectId()));
601601
}
602602

603603
private Map<BigQueryRpc.Option, ?> optionMap(Option... options) {
@@ -608,100 +608,4 @@ public TableDataWriteChannel writer(WriteChannelConfiguration writeChannelConfig
608608
}
609609
return optionMap;
610610
}
611-
612-
private DatasetInfo setProjectId(DatasetInfo dataset) {
613-
DatasetInfo.Builder datasetBuilder = dataset.toBuilder();
614-
datasetBuilder.datasetId(setProjectId(dataset.datasetId()));
615-
if (dataset.acl() != null) {
616-
List<Acl> acls = Lists.newArrayListWithCapacity(dataset.acl().size());
617-
for (Acl acl : dataset.acl()) {
618-
if (acl.entity().type() == Acl.Entity.Type.VIEW) {
619-
Dataset.Access accessPb = acl.toPb();
620-
TableReference viewReferencePb = accessPb.getView();
621-
if (viewReferencePb.getProjectId() == null) {
622-
viewReferencePb.setProjectId(options().projectId());
623-
}
624-
acls.add(Acl.of(new Acl.View(TableId.fromPb(viewReferencePb))));
625-
} else {
626-
acls.add(acl);
627-
}
628-
}
629-
datasetBuilder.acl(acls);
630-
}
631-
return datasetBuilder.build();
632-
}
633-
634-
private DatasetId setProjectId(DatasetId dataset) {
635-
return dataset.project() != null ? dataset
636-
: DatasetId.of(options().projectId(), dataset.dataset());
637-
}
638-
639-
private BaseTableInfo setProjectId(BaseTableInfo table) {
640-
return table.toBuilder().tableId(setProjectId(table.tableId())).build();
641-
}
642-
643-
private TableId setProjectId(TableId table) {
644-
return table.project() != null ? table
645-
: TableId.of(options().projectId(), table.dataset(), table.table());
646-
}
647-
648-
private JobInfo setProjectId(JobInfo job) {
649-
JobConfiguration configuration = job.configuration();
650-
JobInfo.Builder jobBuilder = job.toBuilder();
651-
switch (configuration.type()) {
652-
case COPY:
653-
CopyJobConfiguration copyConfiguration = (CopyJobConfiguration) configuration;
654-
CopyJobConfiguration.Builder copyBuilder = copyConfiguration.toBuilder();
655-
copyBuilder.sourceTables(
656-
Lists.transform(copyConfiguration.sourceTables(), new Function<TableId, TableId>() {
657-
@Override
658-
public TableId apply(TableId tableId) {
659-
return setProjectId(tableId);
660-
}
661-
}));
662-
copyBuilder.destinationTable(setProjectId(copyConfiguration.destinationTable()));
663-
jobBuilder.configuration(copyBuilder.build());
664-
break;
665-
case QUERY:
666-
QueryJobConfiguration queryConfiguration = (QueryJobConfiguration) configuration;
667-
QueryJobConfiguration.Builder queryBuilder = queryConfiguration.toBuilder();
668-
if (queryConfiguration.destinationTable() != null) {
669-
queryBuilder.destinationTable(setProjectId(queryConfiguration.destinationTable()));
670-
}
671-
if (queryConfiguration.defaultDataset() != null) {
672-
queryBuilder.defaultDataset(setProjectId(queryConfiguration.defaultDataset()));
673-
}
674-
jobBuilder.configuration(queryBuilder.build());
675-
break;
676-
case EXTRACT:
677-
ExtractJobConfiguration extractConfiguration = (ExtractJobConfiguration) configuration;
678-
ExtractJobConfiguration.Builder extractBuilder = extractConfiguration.toBuilder();
679-
extractBuilder.sourceTable(setProjectId(extractConfiguration.sourceTable()));
680-
jobBuilder.configuration(extractBuilder.build());
681-
break;
682-
case LOAD:
683-
LoadJobConfiguration loadConfiguration = (LoadJobConfiguration) configuration;
684-
jobBuilder.configuration(setProjectId(loadConfiguration));
685-
break;
686-
default:
687-
// never reached
688-
throw new IllegalArgumentException("Job configuration is not supported");
689-
}
690-
return jobBuilder.build();
691-
}
692-
693-
private QueryRequest setProjectId(QueryRequest request) {
694-
QueryRequest.Builder builder = request.toBuilder();
695-
if (request.defaultDataset() != null) {
696-
builder.defaultDataset(setProjectId(request.defaultDataset()));
697-
}
698-
return builder.build();
699-
}
700-
701-
@SuppressWarnings("unchecked")
702-
private <T extends LoadConfiguration> T setProjectId(T configuration) {
703-
LoadConfiguration.Builder builder = configuration.toBuilder();
704-
builder.destinationTable(setProjectId(configuration.destinationTable()));
705-
return (T) builder.build();
706-
}
707611
}

branches/pubsub-alpha/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/CopyJobConfiguration.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.google.common.base.Preconditions.checkNotNull;
2020

2121
import com.google.api.services.bigquery.model.JobConfigurationTableCopy;
22+
import com.google.common.base.Function;
2223
import com.google.common.base.MoreObjects.ToStringHelper;
2324
import com.google.common.collect.ImmutableList;
2425
import com.google.common.collect.Lists;
@@ -189,6 +190,20 @@ public int hashCode() {
189190
writeDisposition);
190191
}
191192

193+
@Override
194+
CopyJobConfiguration setProjectId(final String projectId) {
195+
Builder builder = toBuilder();
196+
builder.sourceTables(
197+
Lists.transform(sourceTables(), new Function<TableId, TableId>() {
198+
@Override
199+
public TableId apply(TableId tableId) {
200+
return tableId.setProjectId(projectId);
201+
}
202+
}));
203+
builder.destinationTable(destinationTable().setProjectId(projectId));
204+
return builder.build();
205+
}
206+
192207
com.google.api.services.bigquery.model.JobConfiguration toPb() {
193208
JobConfigurationTableCopy configurationPb = new JobConfigurationTableCopy();
194209
configurationPb.setDestinationTable(destinationTable.toPb());

branches/pubsub-alpha/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/DatasetId.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ public String toString() {
8181
return toPb().toString();
8282
}
8383

84+
DatasetId setProjectId(String projectId) {
85+
return project() != null ? this : DatasetId.of(projectId, dataset());
86+
}
87+
8488
DatasetReference toPb() {
8589
return new DatasetReference().setProjectId(project).setDatasetId(dataset);
8690
}

branches/pubsub-alpha/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/DatasetInfo.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.google.api.client.util.Data;
2323
import com.google.api.services.bigquery.model.Dataset;
24+
import com.google.api.services.bigquery.model.TableReference;
2425
import com.google.common.base.Function;
2526
import com.google.common.base.MoreObjects;
2627
import com.google.common.collect.ImmutableList;
@@ -333,6 +334,28 @@ public boolean equals(Object obj) {
333334
return obj instanceof DatasetInfo && Objects.equals(toPb(), ((DatasetInfo) obj).toPb());
334335
}
335336

337+
DatasetInfo setProjectId(String projectId) {
338+
Builder builder = toBuilder();
339+
builder.datasetId(datasetId().setProjectId(projectId));
340+
if (acl() != null) {
341+
List<Acl> acls = Lists.newArrayListWithCapacity(acl().size());
342+
for (Acl acl : acl()) {
343+
if (acl.entity().type() == Acl.Entity.Type.VIEW) {
344+
Dataset.Access accessPb = acl.toPb();
345+
TableReference viewReferencePb = accessPb.getView();
346+
if (viewReferencePb.getProjectId() == null) {
347+
viewReferencePb.setProjectId(projectId);
348+
}
349+
acls.add(Acl.of(new Acl.View(TableId.fromPb(viewReferencePb))));
350+
} else {
351+
acls.add(acl);
352+
}
353+
}
354+
builder.acl(acls);
355+
}
356+
return builder.build();
357+
}
358+
336359
Dataset toPb() {
337360
Dataset datasetPb = new Dataset();
338361
datasetPb.setDatasetReference(datasetId.toPb());

branches/pubsub-alpha/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ExtractJobConfiguration.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ public int hashCode() {
220220
format, compression);
221221
}
222222

223+
@Override
224+
ExtractJobConfiguration setProjectId(String projectId) {
225+
return toBuilder().sourceTable(sourceTable().setProjectId(projectId)).build();
226+
}
227+
223228
com.google.api.services.bigquery.model.JobConfiguration toPb() {
224229
JobConfigurationExtract extractConfigurationPb = new JobConfigurationExtract();
225230
extractConfigurationPb.setDestinationUris(destinationUris);

branches/pubsub-alpha/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/JobConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ protected final boolean baseEquals(JobConfiguration jobConfiguration) {
122122
return Objects.equals(toPb(), jobConfiguration.toPb());
123123
}
124124

125+
abstract JobConfiguration setProjectId(String projectId);
126+
125127
abstract com.google.api.services.bigquery.model.JobConfiguration toPb();
126128

127129
@SuppressWarnings("unchecked")

branches/pubsub-alpha/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/JobInfo.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ public boolean equals(Object obj) {
278278
return obj instanceof JobInfo && Objects.equals(toPb(), ((JobInfo) obj).toPb());
279279
}
280280

281+
JobInfo setProjectId(String projectId) {
282+
return toBuilder().configuration(this.configuration().setProjectId(projectId)).build();
283+
}
284+
281285
Job toPb() {
282286
Job jobPb = new Job();
283287
jobPb.setEtag(etag);

branches/pubsub-alpha/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/LoadJobConfiguration.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ public int hashCode() {
277277
return Objects.hash(baseHashCode(), sourceUris);
278278
}
279279

280+
@Override
281+
LoadJobConfiguration setProjectId(String projectId) {
282+
return toBuilder().destinationTable(destinationTable().setProjectId(projectId)).build();
283+
}
284+
280285
com.google.api.services.bigquery.model.JobConfiguration toPb() {
281286
JobConfigurationLoad loadConfigurationPb = new JobConfigurationLoad();
282287
loadConfigurationPb.setDestinationTable(destinationTable.toPb());

0 commit comments

Comments
 (0)