Skip to content

Commit

Permalink
Fix comments. Make JobConfiguration an abstract class
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Jan 27, 2016
1 parent 84402ac commit d170550
Show file tree
Hide file tree
Showing 23 changed files with 806 additions and 437 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -666,9 +666,9 @@ Page<List<FieldValue>> listTableData(TableId tableId, TableDataListOption... opt

/**
* Returns a channel to write data to be inserted into a BigQuery table. Data format and other
* options can be configured using the {@link LoadConfiguration} parameter.
* options can be configured using the {@link WriteChannelConfiguration} parameter.
*
* @throws BigQueryException upon failure
*/
TableDataWriteChannel writer(LoadConfiguration loadConfiguration);
TableDataWriteChannel writer(WriteChannelConfiguration writeChannelConfiguration);
}
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,8 @@ private static QueryResult.Builder transformQueryResults(JobId jobId, List<Table
.results(transformTableData(rowsPb));
}

public TableDataWriteChannel writer(LoadConfiguration loadConfiguration) {
return new TableDataWriteChannel(options(), setProjectId(loadConfiguration));
public TableDataWriteChannel writer(WriteChannelConfiguration writeChannelConfiguration) {
return new TableDataWriteChannel(options(), setProjectId(writeChannelConfiguration));
}

private Map<BigQueryRpc.Option, ?> optionMap(Option... options) {
Expand Down Expand Up @@ -681,7 +681,7 @@ public TableId apply(TableId tableId) {
break;
case LOAD:
LoadJobConfiguration loadConfiguration = (LoadJobConfiguration) configuration;
jobBuilder.configuration((LoadJobConfiguration) setProjectId(loadConfiguration));
jobBuilder.configuration(setProjectId(loadConfiguration));
break;
default:
// never reached
Expand All @@ -698,9 +698,10 @@ private QueryRequest setProjectId(QueryRequest request) {
return builder.build();
}

private LoadConfiguration setProjectId(LoadConfiguration configuration) {
@SuppressWarnings("unchecked")
private <T extends LoadConfiguration> T setProjectId(T configuration) {
LoadConfiguration.Builder builder = configuration.toBuilder();
builder.destinationTable(setProjectId(configuration.destinationTable()));
return builder.build();
return (T) builder.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.gcloud.bigquery;

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

import com.google.api.services.bigquery.model.JobConfigurationTableCopy;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

/**
* Google BigQuery Copy Job configuration. A Copy Job copies an existing table to another new or
* existing table.
* Google BigQuery copy job configuration. A copy job copies an existing table to another new or
* existing table. Copy job configurations have {@link JobConfiguration.Type#COPY} type.
*/
public final class CopyJobConfiguration implements JobConfiguration, Serializable {
public final class CopyJobConfiguration extends JobConfiguration {

private static final long serialVersionUID = 1140509641399762967L;

Expand All @@ -24,23 +39,28 @@ public final class CopyJobConfiguration implements JobConfiguration, Serializabl
private final JobInfo.CreateDisposition createDisposition;
private final JobInfo.WriteDisposition writeDisposition;

public static final class Builder {
public static final class Builder
extends JobConfiguration.Builder<CopyJobConfiguration, Builder> {

private List<TableId> sourceTables;
private TableId destinationTable;
private JobInfo.CreateDisposition createDisposition;
private JobInfo.WriteDisposition writeDisposition;

private Builder() {}
private Builder() {
type(Type.COPY);
}

private Builder(CopyJobConfiguration jobConfiguration) {
type(Type.COPY);
this.sourceTables = jobConfiguration.sourceTables;
this.destinationTable = jobConfiguration.destinationTable;
this.createDisposition = jobConfiguration.createDisposition;
this.writeDisposition = jobConfiguration.writeDisposition;
}

private Builder(com.google.api.services.bigquery.model.JobConfiguration configurationPb) {
type(Type.COPY);
JobConfigurationTableCopy copyConfigurationPb = configurationPb.getCopy();
this.destinationTable = TableId.fromPb(copyConfigurationPb.getDestinationTable());
if (copyConfigurationPb.getSourceTables() != null) {
Expand Down Expand Up @@ -103,17 +123,13 @@ public CopyJobConfiguration build() {
}

private CopyJobConfiguration(Builder builder) {
super(builder);
this.sourceTables = checkNotNull(builder.sourceTables);
this.destinationTable = checkNotNull(builder.destinationTable);
this.createDisposition = builder.createDisposition;
this.writeDisposition = builder.writeDisposition;
}

@Override
public Type type() {
return Type.COPY;
}

/**
* Returns the source tables to copy.
*/
Expand Down Expand Up @@ -148,29 +164,29 @@ public JobInfo.WriteDisposition writeDisposition() {
return writeDisposition;
}

@Override
public Builder toBuilder() {
return new Builder(this);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
protected ToStringHelper toStringHelper() {
return super.toStringHelper()
.add("sourceTables", sourceTables)
.add("destinationTable", destinationTable)
.add("createDisposition", createDisposition)
.add("writeDisposition", writeDisposition)
.toString();
.add("writeDisposition", writeDisposition);
}

@Override
public boolean equals(Object obj) {
return obj instanceof CopyJobConfiguration
&& Objects.equals(toPb(), ((CopyJobConfiguration) obj).toPb());
return obj instanceof CopyJobConfiguration && baseEquals((CopyJobConfiguration) obj);
}

@Override
public int hashCode() {
return Objects.hash(sourceTables, destinationTable, createDisposition, writeDisposition);
return Objects.hash(baseHashCode(), sourceTables, destinationTable, createDisposition,
writeDisposition);
}

com.google.api.services.bigquery.model.JobConfiguration toPb() {
Expand Down Expand Up @@ -218,6 +234,7 @@ public static CopyJobConfiguration of(TableId destinationTable, List<TableId> so
return builder(destinationTable, sourceTables).build();
}

@SuppressWarnings("unchecked")
static CopyJobConfiguration fromPb(
com.google.api.services.bigquery.model.JobConfiguration jobPb) {
return new Builder(jobPb).build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Google Inc. All Rights Reserved.
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,19 +19,18 @@
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.api.services.bigquery.model.JobConfigurationExtract;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.collect.ImmutableList;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

/**
* Google BigQuery Extract Job configuration. An Extract Job exports a BigQuery table to Google
* Google BigQuery extract job configuration. An extract job exports a BigQuery table to Google
* Cloud Storage. The extract destination provided as URIs that point to objects in Google Cloud
* Storage.
* Storage. Extract job configurations have {@link JobConfiguration.Type#EXTRACT} type.
*/
public final class ExtractJobConfiguration implements JobConfiguration, Serializable {
public final class ExtractJobConfiguration extends JobConfiguration {

private static final long serialVersionUID = 4147749733166593761L;

Expand All @@ -42,7 +41,8 @@ public final class ExtractJobConfiguration implements JobConfiguration, Seriali
private final String format;
private final String compression;

public static final class Builder {
public static final class Builder
extends JobConfiguration.Builder<ExtractJobConfiguration, Builder> {

private TableId sourceTable;
private List<String> destinationUris;
Expand All @@ -51,9 +51,12 @@ public static final class Builder {
private String format;
private String compression;

private Builder() {}
private Builder() {
type(Type.EXTRACT);
}

private Builder(ExtractJobConfiguration jobInfo) {
type(Type.EXTRACT);
this.sourceTable = jobInfo.sourceTable;
this.destinationUris = jobInfo.destinationUris;
this.printHeader = jobInfo.printHeader;
Expand All @@ -63,6 +66,7 @@ private Builder(ExtractJobConfiguration jobInfo) {
}

private Builder(com.google.api.services.bigquery.model.JobConfiguration configurationPb) {
type(Type.EXTRACT);
JobConfigurationExtract extractConfigurationPb = configurationPb.getExtract();
this.sourceTable = TableId.fromPb(extractConfigurationPb.getSourceTable());
this.destinationUris = extractConfigurationPb.getDestinationUris();
Expand Down Expand Up @@ -134,6 +138,7 @@ public ExtractJobConfiguration build() {
}

private ExtractJobConfiguration(Builder builder) {
super(builder);
this.sourceTable = checkNotNull(builder.sourceTable);
this.destinationUris = checkNotNull(builder.destinationUris);
this.printHeader = builder.printHeader;
Expand All @@ -142,11 +147,6 @@ private ExtractJobConfiguration(Builder builder) {
this.compression = builder.compression;
}

@Override
public Type type() {
return Type.EXTRACT;
}

/**
* Returns the table to export.
*/
Expand Down Expand Up @@ -193,31 +193,30 @@ public String compression() {
return compression;
}

@Override
public Builder toBuilder() {
return new Builder(this);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
protected ToStringHelper toStringHelper() {
return super.toStringHelper()
.add("sourceTable", sourceTable)
.add("destinationUris", destinationUris)
.add("format", format)
.add("printHeader", printHeader)
.add("fieldDelimiter", fieldDelimiter)
.add("compression", compression)
.toString();
.add("compression", compression);
}

@Override
public boolean equals(Object obj) {
return obj instanceof ExtractJobConfiguration
&& Objects.equals(toPb(), ((ExtractJobConfiguration) obj).toPb());
return obj instanceof ExtractJobConfiguration && baseEquals((ExtractJobConfiguration) obj);
}

@Override
public int hashCode() {
return Objects.hash(sourceTable, destinationUris, printHeader, fieldDelimiter,
return Objects.hash(baseHashCode(), sourceTable, destinationUris, printHeader, fieldDelimiter,
format, compression);
}

Expand Down Expand Up @@ -281,6 +280,7 @@ public static ExtractJobConfiguration of(TableId sourceTable, List<String> desti
return builder(sourceTable, destinationUris).format(format).build();
}

@SuppressWarnings("unchecked")
static ExtractJobConfiguration fromPb(
com.google.api.services.bigquery.model.JobConfiguration confPb) {
return new Builder(confPb).build();
Expand Down
Loading

0 comments on commit d170550

Please sign in to comment.