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

Filter by extension

Filter by extension

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
@@ -0,0 +1,105 @@
/*
* Copyright 2017 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.cloud.bigquery;

import com.google.common.base.MoreObjects;
import java.util.List;
import java.util.Objects;

/**
* Google BigQuery options for Cloud Datastore backup.
*/
public final class DatastoreBackupOptions extends FormatOptions {

This comment was marked as spam.

This comment was marked as spam.


private final List<String> projectionFields;

private static final long serialVersionUID = -5302774763661451947L;

public static final class Builder {
private List<String> projectionFields;

private Builder() {}

private Builder(DatastoreBackupOptions options) {
projectionFields = options.projectionFields;
}

/**
* Sets which entity properties to load into BigQuery from a Cloud Datastore backup. Property
* names are case sensitive and must be top-level properties.
* If no properties are specified, BigQuery loads all properties. If any named property isn't
* found in the Cloud Datastore backup, an invalid error is returned in the job result.
*/
public Builder setProjectionFields(List<String> projectionFields) {
this.projectionFields = projectionFields;
return this;
}

/**
* Creates a {@code DatastoreBackupOptions} object.
*/
public DatastoreBackupOptions build() {
return new DatastoreBackupOptions(this);
}
}

private DatastoreBackupOptions(Builder builder) {
super(FormatOptions.DATASTORE_BACKUP);
this.projectionFields = builder.projectionFields;
}

/**
* Returns the value of which entity properties to load into BigQuery from a Cloud Datastore
* backup.
*/
public List<String> getProjectionFields() {
return projectionFields;
}

/**
* Returns a builder for the {@code DatastoreBackupOptions} object.
*/
public Builder toBuilder() {
return new Builder(this);
}

/**
* Returns a builder for a {@code DatastoreBackupOptions} object.
*/
public static Builder newBuilder() {
return new Builder();
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("projectionFields", projectionFields)
.toString();
}

@Override
public int hashCode() {
return Objects.hash(getType(), projectionFields);
}

@Override
public boolean equals(Object obj) {
return obj == this
|| obj instanceof DatastoreBackupOptions
&& Objects.equals(projectionFields, ((DatastoreBackupOptions) obj).getProjectionFields());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static FormatOptions json() {
* Default options for DATASTORE_BACKUP format.
*/
public static FormatOptions datastoreBackup() {
return new FormatOptions(DATASTORE_BACKUP);
return DatastoreBackupOptions.newBuilder().build();
}

/**
Expand All @@ -101,6 +101,8 @@ public static FormatOptions avro() {
public static FormatOptions of(String format) {
if (checkNotNull(format).equals(CSV)) {
return csv();
} else if (format.equals(DATASTORE_BACKUP)) {
return datastoreBackup();
}
return new FormatOptions(format);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,6 @@ interface Builder {
*/
Builder setIgnoreUnknownValues(Boolean ignoreUnknownValues);


/**
* Sets which entity properties to load into BigQuery from a Cloud Datastore backup. This field
* is only used if the source format is set to {@code DATASTORE_BACKUP}. Property names are case
* sensitive and must be top-level properties. If no properties are specified, BigQuery loads
* all properties. If any named property isn't found in the Cloud Datastore backup, an invalid
* error is returned in the job result.
*/
Builder setProjectionFields(List<String> projectionFields);

LoadConfiguration build();
}

Expand Down Expand Up @@ -166,13 +156,9 @@ interface Builder {


/**
* Returns which entity properties to load into BigQuery from a Cloud Datastore backup. This field
* is only used if the source format is set to {@code DATASTORE_BACKUP}. Property names are case
* sensitive and must be top-level properties. If no properties are specified, BigQuery loads
* all properties. If any named property isn't found in the Cloud Datastore backup, an invalid
* error is returned in the job result.
* Returns additional options used to load from a Cloud datastore backup.
*/
List<String> getProjectionFields();
DatastoreBackupOptions getDatastoreBackupOptions();

/**
* Returns a builder for the load configuration object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public final class LoadJobConfiguration extends JobConfiguration implements Load
private final Integer maxBadRecords;
private final Schema schema;
private final Boolean ignoreUnknownValues;
private final List<String> projectionFields;

public static final class Builder
extends JobConfiguration.Builder<LoadJobConfiguration, Builder>
Expand Down Expand Up @@ -72,7 +71,6 @@ private Builder(LoadJobConfiguration loadConfiguration) {
this.maxBadRecords = loadConfiguration.maxBadRecords;
this.schema = loadConfiguration.schema;
this.ignoreUnknownValues = loadConfiguration.ignoreUnknownValues;
this.projectionFields = loadConfiguration.projectionFields;
this.sourceUris = loadConfiguration.sourceUris;
}

Expand Down Expand Up @@ -172,15 +170,6 @@ public Builder setIgnoreUnknownValues(Boolean ignoreUnknownValues) {
return this;
}


@Override
public Builder setProjectionFields(List<String> projectionFields) {
this.projectionFields =
projectionFields != null ? ImmutableList.copyOf(projectionFields) : null;
return this;
}


/**
* Sets the fully-qualified URIs that point to source data in Google Cloud Storage (e.g.
* gs://bucket/path). Each URI can contain one '*' wildcard character and it must come after the
Expand All @@ -207,7 +196,6 @@ private LoadJobConfiguration(Builder builder) {
this.maxBadRecords = builder.maxBadRecords;
this.schema = builder.schema;
this.ignoreUnknownValues = builder.ignoreUnknownValues;
this.projectionFields = builder.projectionFields;
}


Expand All @@ -234,6 +222,12 @@ public CsvOptions getCsvOptions() {
return formatOptions instanceof CsvOptions ? (CsvOptions) formatOptions : null;
}

@Override
public DatastoreBackupOptions getDatastoreBackupOptions() {
return formatOptions instanceof DatastoreBackupOptions ?
(DatastoreBackupOptions) formatOptions : null;
}


@Override
public String getFormat() {
Expand All @@ -257,13 +251,6 @@ public Boolean ignoreUnknownValues() {
return ignoreUnknownValues;
}


@Override
public List<String> getProjectionFields() {
return projectionFields;
}


/**
* Returns the fully-qualified URIs that point to source data in Google Cloud Storage (e.g.
* gs://bucket/path). Each URI can contain one '*' wildcard character and it must come after the
Expand All @@ -288,7 +275,6 @@ ToStringHelper toStringHelper() {
.add("maxBadRecords", maxBadRecords)
.add("schema", schema)
.add("ignoreUnknownValue", ignoreUnknownValues)
.add("projectionFields", projectionFields)
.add("sourceUris", sourceUris);
}

Expand Down Expand Up @@ -339,7 +325,10 @@ com.google.api.services.bigquery.model.JobConfiguration toPb() {
}
loadConfigurationPb.setMaxBadRecords(maxBadRecords);
loadConfigurationPb.setIgnoreUnknownValues(ignoreUnknownValues);
loadConfigurationPb.setProjectionFields(projectionFields);
if (getDatastoreBackupOptions() != null) {
DatastoreBackupOptions backOptions = getDatastoreBackupOptions();
loadConfigurationPb.setProjectionFields(backOptions.getProjectionFields());
}
if (sourceUris != null) {
loadConfigurationPb.setSourceUris(ImmutableList.copyOf(sourceUris));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public final class WriteChannelConfiguration implements LoadConfiguration, Seria
private final Integer maxBadRecords;
private final Schema schema;
private final Boolean ignoreUnknownValues;
private final List<String> projectionFields;

public static final class Builder implements LoadConfiguration.Builder {

Expand All @@ -56,7 +55,6 @@ public static final class Builder implements LoadConfiguration.Builder {
private Integer maxBadRecords;
private Schema schema;
private Boolean ignoreUnknownValues;
private List<String> projectionFields;

private Builder() {}

Expand All @@ -68,7 +66,6 @@ private Builder(WriteChannelConfiguration writeChannelConfiguration) {
this.maxBadRecords = writeChannelConfiguration.maxBadRecords;
this.schema = writeChannelConfiguration.schema;
this.ignoreUnknownValues = writeChannelConfiguration.ignoreUnknownValues;
this.projectionFields = writeChannelConfiguration.projectionFields;
}

private Builder(com.google.api.services.bigquery.model.JobConfiguration configurationPb) {
Expand Down Expand Up @@ -110,7 +107,11 @@ private Builder(com.google.api.services.bigquery.model.JobConfiguration configur
this.schema = Schema.fromPb(loadConfigurationPb.getSchema());
}
this.ignoreUnknownValues = loadConfigurationPb.getIgnoreUnknownValues();
this.projectionFields = loadConfigurationPb.getProjectionFields();
if (loadConfigurationPb.getProjectionFields() != null) {
this.formatOptions = DatastoreBackupOptions.newBuilder()

This comment was marked as spam.

This comment was marked as spam.

.setProjectionFields(loadConfigurationPb.getProjectionFields())
.build();
}
}


Expand Down Expand Up @@ -162,14 +163,6 @@ public Builder setIgnoreUnknownValues(Boolean ignoreUnknownValues) {
return this;
}


@Override
public Builder setProjectionFields(List<String> projectionFields) {
this.projectionFields =
projectionFields != null ? ImmutableList.copyOf(projectionFields) : null;
return this;
}

@Override
public WriteChannelConfiguration build() {
return new WriteChannelConfiguration(this);
Expand All @@ -184,7 +177,6 @@ protected WriteChannelConfiguration(Builder builder) {
this.maxBadRecords = builder.maxBadRecords;
this.schema = builder.schema;
this.ignoreUnknownValues = builder.ignoreUnknownValues;
this.projectionFields = builder.projectionFields;
}


Expand Down Expand Up @@ -236,8 +228,9 @@ public Boolean ignoreUnknownValues() {


@Override
public List<String> getProjectionFields() {
return projectionFields;
public DatastoreBackupOptions getDatastoreBackupOptions() {
return formatOptions instanceof DatastoreBackupOptions ?
(DatastoreBackupOptions) formatOptions : null;
}

@Override
Expand All @@ -253,8 +246,7 @@ MoreObjects.ToStringHelper toStringHelper() {
.add("formatOptions", formatOptions)
.add("maxBadRecords", maxBadRecords)
.add("schema", schema)
.add("ignoreUnknownValue", ignoreUnknownValues)
.add("projectionFields", projectionFields);
.add("ignoreUnknownValue", ignoreUnknownValues);
}

@Override
Expand All @@ -272,7 +264,7 @@ public boolean equals(Object obj) {
@Override
public int hashCode() {
return Objects.hash(destinationTable, createDisposition, writeDisposition, formatOptions,
maxBadRecords, schema, ignoreUnknownValues, projectionFields);
maxBadRecords, schema, ignoreUnknownValues);
}

WriteChannelConfiguration setProjectId(String projectId) {
Expand Down Expand Up @@ -308,7 +300,10 @@ com.google.api.services.bigquery.model.JobConfiguration toPb() {
}
loadConfigurationPb.setMaxBadRecords(maxBadRecords);
loadConfigurationPb.setIgnoreUnknownValues(ignoreUnknownValues);
loadConfigurationPb.setProjectionFields(projectionFields);
if (getDatastoreBackupOptions() != null) {
DatastoreBackupOptions backupOptions = getDatastoreBackupOptions();
loadConfigurationPb.setProjectionFields(backupOptions.getProjectionFields());
}
return new com.google.api.services.bigquery.model.JobConfiguration()
.setLoad(loadConfigurationPb);
}
Expand Down
Loading