From 85e54d448b6e864284706b94da84ccdd6e5538e2 Mon Sep 17 00:00:00 2001 From: Seth Hollyman Date: Mon, 18 Jun 2018 10:44:31 -0700 Subject: [PATCH 1/8] BigQuery: Add ORC format support for load jobs. Additionally, plumb in the (missing) Bigtable format support for federated tables. --- .../google/cloud/bigquery/BigtableColumn.java | 157 +++++++++++++++ .../cloud/bigquery/BigtableColumnFamily.java | 187 ++++++++++++++++++ .../cloud/bigquery/BigtableOptions.java | 111 +++++++++++ .../bigquery/ExternalTableDefinition.java | 8 + .../google/cloud/bigquery/FormatOptions.java | 22 ++- 5 files changed, 484 insertions(+), 1 deletion(-) create mode 100644 google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java create mode 100644 google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java create mode 100644 google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java new file mode 100644 index 000000000000..49078af31576 --- /dev/null +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java @@ -0,0 +1,157 @@ +package com.google.cloud.bigquery; + + +import com.google.common.base.Function; +import com.google.common.base.MoreObjects; +import java.io.Serializable; + +public class BigtableColumn implements Serializable { + + + static final Function FROM_PB_FUNCTION = + new Function() { + @Override + public BigtableColumn apply( + com.google.api.services.bigquery.model.BigtableColumn pb) { + return BigtableColumn.fromPb(pb); + } + }; + + static final Function TO_PB_FUNCTION = + new Function() { + @Override + public com.google.api.services.bigquery.model.BigtableColumn apply( + BigtableColumn column) { + return column.toPb(); + } + }; + + private static final long serialVersionUID = 1L; + + public String getQualifierEncoded() { return qualifierEncoded; } + public String getFieldName() { return fieldName; } + public Boolean getOnlyReadLatest() { return onlyReadLatest; } + public String getEncoding() { return encoding; } + public String getType() { return type; } + + private final String qualifierEncoded; + private final String fieldName; + private final Boolean onlyReadLatest; + private final String encoding; + private final String type; + + static final class Builder { + private String qualifierEncoded; + private String fieldName; + private Boolean onlyReadLatest; + private String encoding; + private String type; + + private Builder() {} + + /** + * Qualifier of the column. + * + * Columns in the parent column family that has this exact qualifier are exposed + * as . field. If the qualifier is valid UTF-8 string, it can be specified in the + * qualifier_string field. Otherwise, a base-64 encoded value must be set to qualifier_encoded. The column field name is the same as the + * column qualifier. However, if the qualifier is not a valid BigQuery field + * identifier, a valid identifier must be provided as field_name. + */ + Builder setQualifierEncoded(String qualifierEncoded) { + this.qualifierEncoded = qualifierEncoded; + return this; + } + + /** + * If the qualifier is not a valid BigQuery field identifier, a valid identifier must + * be provided as the column field name and is used as field name in queries. + */ + Builder setFieldName(String fieldName) { + this.fieldName = fieldName; + return this; + } + + /** + * If this is set, only the latest version of value in this column are exposed. + * + * 'onlyReadLatest' can also be set at the column family level. However, the setting + * at the column level takes precedence if 'onlyReadLatest' is set at both levels. + */ + Builder setOnlyReadLatest(Boolean onlyReadLatest) { + this.onlyReadLatest = onlyReadLatest; + return this; + } + + /** + * The encoding of the values when the type is not STRING. + * Acceptable encoding values are: + * TEXT - indicates values are alphanumeric text strings. + * BINARY - indicates values are encoded using HBase Bytes.toBytes family of functions. + * + * Encoding can also be set at the column family level. However, the setting at the + * column level takes precedence if 'encoding' is set at both levels. + */ + Builder setEncoding(String encoding) { + this.encoding = encoding; + return this; + } + + /** + * The type to convert the value in cells of this column. + * + * The values are expected to be encoded using HBase Bytes.toBytes function when using + * the BINARY encoding value. Following BigQuery types are allowed (case-sensitive): + * BYTES STRING INTEGER FLOAT BOOLEAN Default type is BYTES. + * + * 'type' can also be set at the column family level. However, the setting at the column + * level takes precedence if 'type' is set at both levels. + * + */ + Builder setType(String type) { + this.type = type; + return this; + } + + BigtableColumn build() {return new BigtableColumn(this);} + } + + BigtableColumn(Builder builder) { + qualifierEncoded = builder.qualifierEncoded; + fieldName = builder.fieldName; + onlyReadLatest = builder.onlyReadLatest; + encoding = builder.encoding; + type = builder.type; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("qualifierEncoded", qualifierEncoded) + .add("fieldName", fieldName) + .add("onlyReadLatest", onlyReadLatest) + .add("encoding", encoding) + .add("type", type) + .toString(); + } + + static BigtableColumn fromPb(com.google.api.services.bigquery.model.BigtableColumn column) { + Builder builder = new BigtableColumn.Builder(); + builder.setQualifierEncoded(column.getQualifierEncoded()); + builder.setFieldName(column.getFieldName()); + builder.setOnlyReadLatest(column.getOnlyReadLatest()); + builder.setEncoding(column.getEncoding()); + builder.setType(column.getType()); + return builder.build(); + } + + com.google.api.services.bigquery.model.BigtableColumn toPb() { + com.google.api.services.bigquery.model.BigtableColumn column = new com.google.api.services.bigquery.model.BigtableColumn() + .setQualifierEncoded(qualifierEncoded) + .setFieldName(fieldName) + .setOnlyReadLatest(onlyReadLatest) + .setEncoding(encoding) + .setType(type); + return column; + } +} diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java new file mode 100644 index 000000000000..7b0cb1c76fa1 --- /dev/null +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java @@ -0,0 +1,187 @@ +package com.google.cloud.bigquery; + + +import com.google.common.base.Function; +import com.google.common.base.MoreObjects; +import com.google.common.collect.Lists; +import java.io.Serializable; +import java.util.List; + +/** + * List of column families to expose in the table schema along with their types. This list restricts + * the column families that can be referenced in queries and specifies their value types. + * + * You can use this list to do type conversions - see the 'type' field for more details. If you + * leave this list empty, all column families are present in the table schema and their values are + * read as BYTES. During a query only the column families referenced in that query are read from + * Bigtable. + */ + + +public class BigtableColumnFamily implements Serializable { + + static final Function FROM_PB_FUNCTION = + new Function() { + @Override + public BigtableColumnFamily apply( + com.google.api.services.bigquery.model.BigtableColumnFamily pb) { + return BigtableColumnFamily.fromPb(pb); + } + }; + + static final Function TO_PB_FUNCTION = + new Function() { + @Override + public com.google.api.services.bigquery.model.BigtableColumnFamily apply( + BigtableColumnFamily columnFamily) { + return columnFamily.toPb(); + } + }; + + private static final long serialVersionUID = 1L; + + public String getFamilyID() { + return familyID; + } + + public List getColumns() { + return columns; + } + + public String getEncoding() { + return encoding; + } + + public Boolean getOnlyReadLatest() { + return onlyReadLatest; + } + + public String getType() { + return type; + } + + private final String familyID; + private final List columns; + private final String encoding; + private final Boolean onlyReadLatest; + private final String type; + + static final class Builder { + + private String familyID; + private List columns; + private String encoding; + private Boolean onlyReadLatest; + private String type; + + private Builder() { + } + + /** + * Identifier of the column family. + */ + Builder setFamilyID(String familyID) { + this.familyID = familyID; + return this; + } + + /** + * Lists of columns that should be exposed as individual fields as opposed to a list of (column + * name, value) pairs. All columns whose qualifier matches a qualifier in this list can be + * accessed as .. Other columns can be accessed as a list through .Column field. + */ + Builder setColumns(List columns) { + this.columns = columns; + return this; + } + + /** + * The encoding of the values when the type is not STRING. + * + * Acceptable encoding values are: TEXT - indicates values are alphanumeric text strings. BINARY + * - indicates values are encoded using HBase Bytes.toBytes family of functions. + * + * This can be overridden for a specific column by listing that column in 'columns' and + * specifying an encoding for it. + */ + Builder setEncoding(String encoding) { + this.encoding = encoding; + return this; + } + + /** + * If true, only the latest version of values are exposed for all columns in this column family. + * This can be overridden for a specific column by listing that column in 'columns' and + * specifying a different setting for that column. + */ + Builder setOnlyReadLatest(Boolean onlyReadLatest) { + this.onlyReadLatest = onlyReadLatest; + return this; + } + + /** + * The type to convert the value in cells of this column family. The values are expected to be + * encoded using HBase Bytes.toBytes function when using the BINARY encoding value. + * + * Following BigQuery types are allowed (case-sensitive): BYTES STRING INTEGER FLOAT BOOLEAN. + * + * The default type is BYTES. This can be overridden for a specific column by listing that + * column in 'columns' and specifying a type for it. + */ + Builder setType(String type) { + this.type = type; + return this; + } + + BigtableColumnFamily build() { + return new BigtableColumnFamily(this); + } + } + + BigtableColumnFamily(Builder builder) { + familyID = builder.familyID; + columns = builder.columns; + encoding = builder.encoding; + onlyReadLatest = builder.onlyReadLatest; + type = builder.type; + + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("familyID", familyID) + .add("columns", columns) + .add("encoding", encoding) + .add("onlyReadLatest", onlyReadLatest) + .add("type", type) + .toString(); + } + + static BigtableColumnFamily fromPb( + com.google.api.services.bigquery.model.BigtableColumnFamily columnFamily) { + Builder builder = new BigtableColumnFamily.Builder(); + builder.setFamilyID(columnFamily.getFamilyId()); + builder.setColumns(Lists.transform(columnFamily.getColumns(), BigtableColumn.FROM_PB_FUNCTION)); + builder.setEncoding(columnFamily.getEncoding()); + builder.setOnlyReadLatest(columnFamily.getOnlyReadLatest()); + builder.setType(columnFamily.getType()); + return builder.build(); + + } + + com.google.api.services.bigquery.model.BigtableColumnFamily toPb() { + com.google.api.services.bigquery.model.BigtableColumnFamily colFamilyPb = new com.google.api.services.bigquery.model.BigtableColumnFamily() + .setFamilyId(familyID) + .setEncoding(encoding) + .setOnlyReadLatest(onlyReadLatest) + .setType(type); + if (columns != null) { + colFamilyPb.setColumns(Lists.transform(columns, BigtableColumn.TO_PB_FUNCTION)); + } + return colFamilyPb; + } +} + + + diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java new file mode 100644 index 000000000000..dd3466736897 --- /dev/null +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java @@ -0,0 +1,111 @@ +package com.google.cloud.bigquery; + +import com.google.common.base.MoreObjects; +import com.google.common.collect.Lists; +import java.io.Serializable; +import java.util.List; + + +public class BigtableOptions implements Serializable { + + + private static final long serialVersionUID = 1L; + + public Boolean getIgnoreUnspecifiedColumnFamilies() { + return ignoreUnspecifiedColumnFamilies; + } + + public Boolean getReadRowkeyAsString() { + return readRowkeyAsString; + } + + public List getColumnFamilies() { + return columnFamilies; + } + + private final Boolean ignoreUnspecifiedColumnFamilies; + private final Boolean readRowkeyAsString; + private final List columnFamilies; + + static final class Builder { + + private Boolean ignoreUnspecifiedColumnFamilies; + private Boolean readRowkeyAsString; + private List columnFamilies; + + private Builder() { + } + + /** + * If field is true, then the column families that are not specified in columnFamilies list are + * not exposed in the table schema. Otherwise, they are read with BYTES type values. The default + * value is false. + */ + Builder setIgnoreUnspecifiedColumnFamilies(Boolean ignoreUnspecifiedColumnFamilies) { + this.ignoreUnspecifiedColumnFamilies = ignoreUnspecifiedColumnFamilies; + return this; + } + + /** + * If readRowkeyAsString is true, then the rowkey column families will be read and converted to + * string. Otherwise they are read with BYTES type values and users need to manually cast them + * with CAST if necessary. The default value is false. + */ + Builder setReadRowkeyAsString(Boolean readRowkeyAsString) { + this.readRowkeyAsString = readRowkeyAsString; + return this; + } + + /** + * List of column families to expose in the table schema along with their types. + * + * This list restricts the column families that can be referenced in queries and specifies their + * value types. You can use this list to do type conversions - see the 'type' field for more + * details. If you leave this list empty, all column families are present in the table schema + * and their values are read as BYTES. During a query only the column families referenced in + * that query are read from Bigtable. + */ + Builder setColumnFamilies(List columnFamilies) { + this.columnFamilies = columnFamilies; + return this; + } + + BigtableOptions build() { + return new BigtableOptions(this); + } + + } + + BigtableOptions(Builder builder) { + ignoreUnspecifiedColumnFamilies = builder.ignoreUnspecifiedColumnFamilies; + readRowkeyAsString = builder.readRowkeyAsString; + columnFamilies = builder.columnFamilies; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("ignoreUnspecifiedColumnFamilies", ignoreUnspecifiedColumnFamilies) + .add("readRowkeyAsString", readRowkeyAsString) + .add("columnFamilies", columnFamilies) + .toString(); + } + + static BigtableOptions fromPb(com.google.api.services.bigquery.model.BigtableOptions options) { + Builder builder = new BigtableOptions.Builder(); + builder.setIgnoreUnspecifiedColumnFamilies(options.getIgnoreUnspecifiedColumnFamilies()); + builder.setReadRowkeyAsString(options.getReadRowkeyAsString()); + builder.setColumnFamilies(Lists.transform(options.getColumnFamilies(), BigtableColumnFamily.FROM_PB_FUNCTION)); + return builder.build(); + } + + com.google.api.services.bigquery.model.BigtableOptions toPb() { + com.google.api.services.bigquery.model.BigtableOptions options = new com.google.api.services.bigquery.model.BigtableOptions() + .setIgnoreUnspecifiedColumnFamilies(ignoreUnspecifiedColumnFamilies) + .setReadRowkeyAsString(readRowkeyAsString); + if (columnFamilies != null) { + options.setColumnFamilies(Lists.transform(columnFamilies, BigtableColumnFamily.TO_PB_FUNCTION)); + } + return options; + } +} diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ExternalTableDefinition.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ExternalTableDefinition.java index d63918b9bb45..30b7c5697c2a 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ExternalTableDefinition.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ExternalTableDefinition.java @@ -64,7 +64,15 @@ public abstract static class Builder * bucket's name. Size limits related to load jobs apply to external data sources, plus an * additional limit of 10 GB maximum size across all URIs. * + * For Google Cloud Bigtable URIs: + * Exactly one URI can be specified and it has be a fully specified and valid + * HTTPS URL for a Google Cloud Bigtable table. + * + * For Google Cloud Datastore backup URIs: + * Exactly one URI can be specified. Also, the '*' wildcard character is not allowed. + * * @see Quota + * */ public Builder setSourceUris(List sourceUris) { return setSourceUrisImmut(ImmutableList.copyOf(sourceUris)); diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FormatOptions.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FormatOptions.java index 2b64f446add8..476ac6fdfedd 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FormatOptions.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FormatOptions.java @@ -26,15 +26,25 @@ /** * Base class for Google BigQuery format options. These class define the format of external data * used by BigQuery, for either federated tables or load jobs. + * + * Load jobs support the following formats: + * AVRO, CSV, DATASTORE_BACKUP, GOOGLE_SHEETS, JSON, ORC, PARQUET + * + * Federated tables can be defined against following formats: + * AVRO, BIGTABLE, CSV, DATASTORE_BACKUP, GOOGLE_SHEETS, JSON + * */ public class FormatOptions implements Serializable { static final String CSV = "CSV"; static final String JSON = "NEWLINE_DELIMITED_JSON"; + static final String BIGTABLE = "BIGTABLE"; static final String DATASTORE_BACKUP = "DATASTORE_BACKUP"; static final String AVRO = "AVRO"; static final String GOOGLE_SHEETS = "GOOGLE_SHEETS"; static final String PARQUET = "PARQUET"; + static final String ORC = "ORC"; + private static final long serialVersionUID = -443376052020423691L; private final String type; @@ -97,6 +107,11 @@ public static FormatOptions avro() { return new FormatOptions(AVRO); } + /** + * Default options for BIGTABLE format. + */ + public static FormatOptions bigtable() { return new FormatOptions(BIGTABLE); } + /** * Default options for GOOGLE_SHEETS format. */ @@ -111,7 +126,12 @@ public static FormatOptions parquet() { return new FormatOptions(PARQUET); } - /** + /** + * Default options for the ORC format. + */ + public static FormatOptions orc() { return new FormatOptions(ORC); } + + /** * Default options for the provided format. */ public static FormatOptions of(String format) { From 64fd87f5190b5769243f296e744ab5fde7d9c503 Mon Sep 17 00:00:00 2001 From: Seth Hollyman Date: Mon, 18 Jun 2018 11:34:46 -0700 Subject: [PATCH 2/8] add overrides, unit testing --- .../google/cloud/bigquery/BigtableColumn.java | 31 ++++++ .../cloud/bigquery/BigtableColumnFamily.java | 33 +++++++ .../cloud/bigquery/BigtableOptions.java | 24 +++++ .../cloud/bigquery/BigtableOptionsTest.java | 99 +++++++++++++++++++ 4 files changed, 187 insertions(+) create mode 100644 google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigtableOptionsTest.java diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java index 49078af31576..72506d6a04d0 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java @@ -4,6 +4,7 @@ import com.google.common.base.Function; import com.google.common.base.MoreObjects; import java.io.Serializable; +import java.util.Objects; public class BigtableColumn implements Serializable { @@ -135,6 +136,36 @@ public String toString() { .toString(); } + @Override + public final int hashCode() { + return Objects.hash( + qualifierEncoded, + fieldName, + onlyReadLatest, + encoding, + type); + } + + @Override + public final boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (obj == null || !obj.getClass().equals(BigtableColumn.class)) { + return false; + } + BigtableColumn other = (BigtableColumn) obj; + return qualifierEncoded == other.qualifierEncoded + && fieldName == other.fieldName + && onlyReadLatest == other.onlyReadLatest + && encoding == other.encoding + && type == other.type; + } + + static Builder newBuilder() { + return new Builder(); + } + static BigtableColumn fromPb(com.google.api.services.bigquery.model.BigtableColumn column) { Builder builder = new BigtableColumn.Builder(); builder.setQualifierEncoded(column.getQualifierEncoded()); diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java index 7b0cb1c76fa1..a3efc9349b2d 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java @@ -6,6 +6,7 @@ import com.google.common.collect.Lists; import java.io.Serializable; import java.util.List; +import java.util.Objects; /** * List of column families to expose in the table schema along with their types. This list restricts @@ -138,6 +139,7 @@ BigtableColumnFamily build() { } } + BigtableColumnFamily(Builder builder) { familyID = builder.familyID; columns = builder.columns; @@ -158,6 +160,37 @@ public String toString() { .toString(); } + @Override + public final int hashCode() { + return Objects.hash( + familyID, + columns, + encoding, + onlyReadLatest, + type); + } + + @Override + public final boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (obj == null || !obj.getClass().equals(BigtableColumnFamily.class)) { + return false; + } + BigtableColumnFamily other = (BigtableColumnFamily) obj; + return familyID == other.familyID + && encoding == other.encoding + && onlyReadLatest == other.onlyReadLatest + && type == other.type + && Objects.equals(columns, other.columns); + } + + static Builder newBuilder() { + return new Builder(); + } + + static BigtableColumnFamily fromPb( com.google.api.services.bigquery.model.BigtableColumnFamily columnFamily) { Builder builder = new BigtableColumnFamily.Builder(); diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java index dd3466736897..a748854559e8 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java @@ -4,6 +4,7 @@ import com.google.common.collect.Lists; import java.io.Serializable; import java.util.List; +import java.util.Objects; public class BigtableOptions implements Serializable { @@ -91,6 +92,29 @@ public String toString() { .toString(); } + @Override + public final int hashCode() { + return Objects.hash(ignoreUnspecifiedColumnFamilies, readRowkeyAsString, columnFamilies); + } + + @Override + public final boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (obj == null || !obj.getClass().equals(BigtableOptions.class)) { + return false; + } + BigtableOptions other = (BigtableOptions) obj; + return ignoreUnspecifiedColumnFamilies == other.ignoreUnspecifiedColumnFamilies + && readRowkeyAsString == other.readRowkeyAsString + && Objects.equals(columnFamilies, other.columnFamilies); + } + + static Builder newBuilder() { + return new Builder(); + } + static BigtableOptions fromPb(com.google.api.services.bigquery.model.BigtableOptions options) { Builder builder = new BigtableOptions.Builder(); builder.setIgnoreUnspecifiedColumnFamilies(options.getIgnoreUnspecifiedColumnFamilies()); diff --git a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigtableOptionsTest.java b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigtableOptionsTest.java new file mode 100644 index 000000000000..b54dcc59615a --- /dev/null +++ b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigtableOptionsTest.java @@ -0,0 +1,99 @@ +package com.google.cloud.bigquery; + +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertTrue; + +import com.google.common.collect.ImmutableList; +import org.junit.Test; + +public class BigtableOptionsTest { + + + private static final BigtableColumn COL1 = BigtableColumn.newBuilder() + .setQualifierEncoded("aaa") + .setFieldName("field1") + .setOnlyReadLatest(true) + .setEncoding("BINARY") + .setType("BYTES") + .build(); + private static final BigtableColumn COL2 = BigtableColumn.newBuilder() + .setQualifierEncoded("bbb") + .setFieldName("field2") + .setOnlyReadLatest(true) + .setEncoding("TEXT") + .setType("STRING") + .build(); + private static final BigtableColumnFamily TESTFAMILY = BigtableColumnFamily.newBuilder() + .setFamilyID("fooFamily") + .setEncoding("TEXT") + .setOnlyReadLatest(true) + .setType("INTEGER") + .setColumns(ImmutableList.of(COL1, COL2)) + .build(); + private static final BigtableOptions OPTIONS = BigtableOptions.newBuilder() + .setIgnoreUnspecifiedColumnFamilies(true) + .setReadRowkeyAsString(true) + .setColumnFamilies(ImmutableList.of(TESTFAMILY)) + .build(); + + + @Test + public void testConstructors() { + + // column + assertEquals(COL1.getQualifierEncoded(), "aaa"); + assertEquals(COL1.getFieldName(), "field1"); + assertTrue(COL1.getOnlyReadLatest()); + assertEquals(COL1.getEncoding(), "BINARY"); + assertEquals(COL1.getType(), "BYTES"); + + // family + assertEquals(TESTFAMILY.getFamilyID(), "fooFamily"); + assertEquals(TESTFAMILY.getEncoding(), "TEXT"); + assertTrue(TESTFAMILY.getOnlyReadLatest()); + assertEquals(TESTFAMILY.getType(), "INTEGER"); + assertEquals(TESTFAMILY.getColumns(), ImmutableList.of(COL1, COL2)); + + // options + assertTrue(OPTIONS.getIgnoreUnspecifiedColumnFamilies()); + assertTrue(OPTIONS.getReadRowkeyAsString()); + assertEquals(OPTIONS.getColumnFamilies(), ImmutableList.of(TESTFAMILY)); + } + + @Test + public void testToAndFromPb() { + compareBigtableColumn(COL1, BigtableColumn.fromPb(COL1.toPb())); + compareBigtableColumnFamily(TESTFAMILY, BigtableColumnFamily.fromPb(TESTFAMILY.toPb())); + compareBigtableOptions(OPTIONS, BigtableOptions.fromPb(OPTIONS.toPb())); + } + + @Test + public void testEquals() { + compareBigtableColumn(COL1, COL1); + compareBigtableColumnFamily(TESTFAMILY, TESTFAMILY); + compareBigtableOptions(OPTIONS, OPTIONS); + } + + private void compareBigtableColumn(BigtableColumn expected, BigtableColumn value) { + assertEquals(expected.getEncoding(), value.getEncoding()); + assertEquals(expected.getFieldName(), value.getFieldName()); + assertEquals(expected.getQualifierEncoded(), value.getQualifierEncoded()); + assertEquals(expected.getOnlyReadLatest(), value.getOnlyReadLatest()); + assertEquals(expected.getType(), value.getType()); + } + + private void compareBigtableColumnFamily(BigtableColumnFamily expected, BigtableColumnFamily value) { + assertEquals(expected, value); + assertEquals(expected.getFamilyID(), value.getFamilyID()); + assertEquals(expected.getOnlyReadLatest(), value.getOnlyReadLatest()); + assertEquals(expected.getColumns(), value.getColumns()); + assertEquals(expected.getEncoding(), value.getEncoding()); + assertEquals(expected.getType(), value.getType()); + } + + private void compareBigtableOptions(BigtableOptions expected, BigtableOptions value) { + assertEquals(expected.getIgnoreUnspecifiedColumnFamilies(), value.getIgnoreUnspecifiedColumnFamilies()); + assertEquals(expected.getReadRowkeyAsString(), value.getReadRowkeyAsString()); + assertEquals(expected.getColumnFamilies(), value.getColumnFamilies()); + } +} \ No newline at end of file From 25b4ca6eba10d89399100d488b40f25e385984c4 Mon Sep 17 00:00:00 2001 From: Seth Hollyman Date: Mon, 18 Jun 2018 12:36:17 -0700 Subject: [PATCH 3/8] Wire bigtable up into formatoptions --- .../com/google/cloud/bigquery/BigtableOptions.java | 14 ++++++++++---- .../cloud/bigquery/ExternalTableDefinition.java | 9 +++++++++ .../com/google/cloud/bigquery/FormatOptions.java | 6 +++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java index a748854559e8..a833b27d5ef5 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java @@ -7,7 +7,7 @@ import java.util.Objects; -public class BigtableOptions implements Serializable { +public class BigtableOptions extends FormatOptions { private static final long serialVersionUID = 1L; @@ -34,7 +34,12 @@ static final class Builder { private Boolean readRowkeyAsString; private List columnFamilies; - private Builder() { + private Builder() {} + + private Builder(BigtableOptions bigtableOptions) { + this.ignoreUnspecifiedColumnFamilies = bigtableOptions.ignoreUnspecifiedColumnFamilies; + this.readRowkeyAsString = bigtableOptions.readRowkeyAsString; + this.columnFamilies = bigtableOptions.columnFamilies; } /** @@ -78,6 +83,7 @@ BigtableOptions build() { } BigtableOptions(Builder builder) { + super(FormatOptions.BIGTABLE); ignoreUnspecifiedColumnFamilies = builder.ignoreUnspecifiedColumnFamilies; readRowkeyAsString = builder.readRowkeyAsString; columnFamilies = builder.columnFamilies; @@ -111,12 +117,12 @@ public final boolean equals(Object obj) { && Objects.equals(columnFamilies, other.columnFamilies); } - static Builder newBuilder() { + public static Builder newBuilder() { return new Builder(); } static BigtableOptions fromPb(com.google.api.services.bigquery.model.BigtableOptions options) { - Builder builder = new BigtableOptions.Builder(); + Builder builder = newBuilder(); builder.setIgnoreUnspecifiedColumnFamilies(options.getIgnoreUnspecifiedColumnFamilies()); builder.setReadRowkeyAsString(options.getReadRowkeyAsString()); builder.setColumnFamilies(Lists.transform(options.getColumnFamilies(), BigtableColumnFamily.FROM_PB_FUNCTION)); diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ExternalTableDefinition.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ExternalTableDefinition.java index 30b7c5697c2a..626e7ec41503 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ExternalTableDefinition.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ExternalTableDefinition.java @@ -247,6 +247,9 @@ com.google.api.services.bigquery.model.ExternalDataConfiguration toExternalDataC if (getFormatOptions() != null && FormatOptions.GOOGLE_SHEETS.equals(getFormatOptions().getType())) { externalConfigurationPb.setGoogleSheetsOptions(((GoogleSheetsOptions) getFormatOptions()).toPb()); } + if (getFormatOptions() != null && FormatOptions.BIGTABLE.equals(getFormatOptions().getType())) { + externalConfigurationPb.setBigtableOptions(((BigtableOptions) getFormatOptions()).toPb()); + } if (getAutodetect() != null) { externalConfigurationPb.setAutodetect(getAutodetect()); } @@ -354,6 +357,9 @@ static ExternalTableDefinition fromPb(Table tablePb) { if (externalDataConfiguration.getGoogleSheetsOptions() != null) { builder.setFormatOptions(GoogleSheetsOptions.fromPb(externalDataConfiguration.getGoogleSheetsOptions())); } + if (externalDataConfiguration.getBigtableOptions() != null) { + builder.setFormatOptions(BigtableOptions.fromPb(externalDataConfiguration.getBigtableOptions())); + } builder.setMaxBadRecords(externalDataConfiguration.getMaxBadRecords()); builder.setAutodetect(externalDataConfiguration.getAutodetect()); } @@ -384,6 +390,9 @@ static ExternalTableDefinition fromExternalDataConfiguration( if (externalDataConfiguration.getGoogleSheetsOptions() != null) { builder.setFormatOptions(GoogleSheetsOptions.fromPb(externalDataConfiguration.getGoogleSheetsOptions())); } + if (externalDataConfiguration.getBigtableOptions() != null) { + builder.setFormatOptions(BigtableOptions.fromPb(externalDataConfiguration.getBigtableOptions())); + } if (externalDataConfiguration.getMaxBadRecords() != null) { builder.setMaxBadRecords(externalDataConfiguration.getMaxBadRecords()); } diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FormatOptions.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FormatOptions.java index 476ac6fdfedd..3e2e6c4f31c7 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FormatOptions.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FormatOptions.java @@ -110,7 +110,9 @@ public static FormatOptions avro() { /** * Default options for BIGTABLE format. */ - public static FormatOptions bigtable() { return new FormatOptions(BIGTABLE); } + public static FormatOptions bigtable() { + return BigtableOptions.newBuilder().build(); + } /** * Default options for GOOGLE_SHEETS format. @@ -141,6 +143,8 @@ public static FormatOptions of(String format) { return datastoreBackup(); } else if (format.equals(GOOGLE_SHEETS)) { return googleSheets(); + } else if (format.equals(BIGTABLE)) { + return bigtable(); } return new FormatOptions(format); } From 337d3964778fef2d6aa104d57588c21fa6dda9c2 Mon Sep 17 00:00:00 2001 From: Seth Hollyman Date: Mon, 18 Jun 2018 12:42:30 -0700 Subject: [PATCH 4/8] add copyright headers. --- .../com/google/cloud/bigquery/BigtableColumn.java | 15 +++++++++++++++ .../cloud/bigquery/BigtableColumnFamily.java | 15 +++++++++++++++ .../google/cloud/bigquery/BigtableOptions.java | 15 +++++++++++++++ .../cloud/bigquery/BigtableOptionsTest.java | 15 +++++++++++++++ 4 files changed, 60 insertions(+) diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java index 72506d6a04d0..95f570dd48c4 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java @@ -1,3 +1,18 @@ +/* + * Copyright 2018 Google LLC + * + * 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; diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java index a3efc9349b2d..acc8d061a162 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java @@ -1,3 +1,18 @@ +/* + * Copyright 2018 Google LLC + * + * 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; diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java index a833b27d5ef5..adeaa6e3cbc3 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java @@ -1,3 +1,18 @@ +/* + * Copyright 2018 Google LLC + * + * 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; diff --git a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigtableOptionsTest.java b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigtableOptionsTest.java index b54dcc59615a..33e7c2bd223f 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigtableOptionsTest.java +++ b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigtableOptionsTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2018 Google LLC + * + * 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 static junit.framework.TestCase.assertEquals; From 3fe97ecce85e5fae6cc3781491d4e49c2fe3d064 Mon Sep 17 00:00:00 2001 From: Seth Hollyman Date: Tue, 19 Jun 2018 09:51:32 -0700 Subject: [PATCH 5/8] Convert BigtableColumn and BigtableColumnFamily to autovalue generation. --- .../google/cloud/bigquery/BigtableColumn.java | 157 +++++----------- .../cloud/bigquery/BigtableColumnFamily.java | 170 +++++------------- 2 files changed, 91 insertions(+), 236 deletions(-) diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java index 95f570dd48c4..aa14b19bd4d1 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java @@ -18,52 +18,34 @@ import com.google.common.base.Function; import com.google.common.base.MoreObjects; +import com.google.auto.value.AutoValue; import java.io.Serializable; import java.util.Objects; +import javax.annotation.Nullable; -public class BigtableColumn implements Serializable { +@AutoValue +public abstract class BigtableColumn { + private static final long serialVersionUID = 1L; - static final Function FROM_PB_FUNCTION = - new Function() { - @Override - public BigtableColumn apply( - com.google.api.services.bigquery.model.BigtableColumn pb) { - return BigtableColumn.fromPb(pb); - } - }; + @Nullable + public abstract String getQualifierEncoded(); - static final Function TO_PB_FUNCTION = - new Function() { - @Override - public com.google.api.services.bigquery.model.BigtableColumn apply( - BigtableColumn column) { - return column.toPb(); - } - }; + @Nullable + public abstract String getFieldName(); - private static final long serialVersionUID = 1L; + @Nullable + public abstract Boolean getOnlyReadLatest(); - public String getQualifierEncoded() { return qualifierEncoded; } - public String getFieldName() { return fieldName; } - public Boolean getOnlyReadLatest() { return onlyReadLatest; } - public String getEncoding() { return encoding; } - public String getType() { return type; } + @Nullable + public abstract String getEncoding(); - private final String qualifierEncoded; - private final String fieldName; - private final Boolean onlyReadLatest; - private final String encoding; - private final String type; + @Nullable + public abstract String getType(); - static final class Builder { - private String qualifierEncoded; - private String fieldName; - private Boolean onlyReadLatest; - private String encoding; - private String type; + @AutoValue.Builder + public abstract static class Builder { - private Builder() {} /** * Qualifier of the column. @@ -74,19 +56,13 @@ private Builder() {} * column qualifier. However, if the qualifier is not a valid BigQuery field * identifier, a valid identifier must be provided as field_name. */ - Builder setQualifierEncoded(String qualifierEncoded) { - this.qualifierEncoded = qualifierEncoded; - return this; - } + public abstract Builder setQualifierEncoded(String qualifierEncoded); /** * If the qualifier is not a valid BigQuery field identifier, a valid identifier must * be provided as the column field name and is used as field name in queries. */ - Builder setFieldName(String fieldName) { - this.fieldName = fieldName; - return this; - } + public abstract Builder setFieldName(String fieldName); /** * If this is set, only the latest version of value in this column are exposed. @@ -94,10 +70,7 @@ Builder setFieldName(String fieldName) { * 'onlyReadLatest' can also be set at the column family level. However, the setting * at the column level takes precedence if 'onlyReadLatest' is set at both levels. */ - Builder setOnlyReadLatest(Boolean onlyReadLatest) { - this.onlyReadLatest = onlyReadLatest; - return this; - } + public abstract Builder setOnlyReadLatest(Boolean onlyReadLatest); /** * The encoding of the values when the type is not STRING. @@ -108,10 +81,7 @@ Builder setOnlyReadLatest(Boolean onlyReadLatest) { * Encoding can also be set at the column family level. However, the setting at the * column level takes precedence if 'encoding' is set at both levels. */ - Builder setEncoding(String encoding) { - this.encoding = encoding; - return this; - } + public abstract Builder setEncoding(String encoding); /** * The type to convert the value in cells of this column. @@ -124,65 +94,17 @@ Builder setEncoding(String encoding) { * level takes precedence if 'type' is set at both levels. * */ - Builder setType(String type) { - this.type = type; - return this; - } + public abstract Builder setType(String type); - BigtableColumn build() {return new BigtableColumn(this);} - } - - BigtableColumn(Builder builder) { - qualifierEncoded = builder.qualifierEncoded; - fieldName = builder.fieldName; - onlyReadLatest = builder.onlyReadLatest; - encoding = builder.encoding; - type = builder.type; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("qualifierEncoded", qualifierEncoded) - .add("fieldName", fieldName) - .add("onlyReadLatest", onlyReadLatest) - .add("encoding", encoding) - .add("type", type) - .toString(); - } - - @Override - public final int hashCode() { - return Objects.hash( - qualifierEncoded, - fieldName, - onlyReadLatest, - encoding, - type); - } - - @Override - public final boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (obj == null || !obj.getClass().equals(BigtableColumn.class)) { - return false; - } - BigtableColumn other = (BigtableColumn) obj; - return qualifierEncoded == other.qualifierEncoded - && fieldName == other.fieldName - && onlyReadLatest == other.onlyReadLatest - && encoding == other.encoding - && type == other.type; + public abstract BigtableColumn build(); } static Builder newBuilder() { - return new Builder(); + return new AutoValue_BigtableColumn.Builder(); } static BigtableColumn fromPb(com.google.api.services.bigquery.model.BigtableColumn column) { - Builder builder = new BigtableColumn.Builder(); + Builder builder = newBuilder(); builder.setQualifierEncoded(column.getQualifierEncoded()); builder.setFieldName(column.getFieldName()); builder.setOnlyReadLatest(column.getOnlyReadLatest()); @@ -193,11 +115,30 @@ static BigtableColumn fromPb(com.google.api.services.bigquery.model.BigtableColu com.google.api.services.bigquery.model.BigtableColumn toPb() { com.google.api.services.bigquery.model.BigtableColumn column = new com.google.api.services.bigquery.model.BigtableColumn() - .setQualifierEncoded(qualifierEncoded) - .setFieldName(fieldName) - .setOnlyReadLatest(onlyReadLatest) - .setEncoding(encoding) - .setType(type); + .setQualifierEncoded(getQualifierEncoded()) + .setFieldName(getFieldName()) + .setOnlyReadLatest(getOnlyReadLatest()) + .setEncoding(getEncoding()) + .setType(getType()); return column; } + + + static final Function FROM_PB_FUNCTION = + new Function() { + @Override + public BigtableColumn apply( + com.google.api.services.bigquery.model.BigtableColumn pb) { + return BigtableColumn.fromPb(pb); + } + }; + + static final Function TO_PB_FUNCTION = + new Function() { + @Override + public com.google.api.services.bigquery.model.BigtableColumn apply( + BigtableColumn column) { + return column.toPb(); + } + }; } diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java index acc8d061a162..f08f3d402ec7 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java @@ -19,6 +19,7 @@ import com.google.common.base.Function; import com.google.common.base.MoreObjects; import com.google.common.collect.Lists; +import com.google.auto.value.AutoValue; import java.io.Serializable; import java.util.List; import java.util.Objects; @@ -33,83 +34,36 @@ * Bigtable. */ +@AutoValue +public abstract class BigtableColumnFamily { -public class BigtableColumnFamily implements Serializable { - - static final Function FROM_PB_FUNCTION = - new Function() { - @Override - public BigtableColumnFamily apply( - com.google.api.services.bigquery.model.BigtableColumnFamily pb) { - return BigtableColumnFamily.fromPb(pb); - } - }; - - static final Function TO_PB_FUNCTION = - new Function() { - @Override - public com.google.api.services.bigquery.model.BigtableColumnFamily apply( - BigtableColumnFamily columnFamily) { - return columnFamily.toPb(); - } - }; private static final long serialVersionUID = 1L; - public String getFamilyID() { - return familyID; - } - - public List getColumns() { - return columns; - } - - public String getEncoding() { - return encoding; - } - - public Boolean getOnlyReadLatest() { - return onlyReadLatest; - } + public abstract String getFamilyID(); - public String getType() { - return type; - } + public abstract List getColumns(); - private final String familyID; - private final List columns; - private final String encoding; - private final Boolean onlyReadLatest; - private final String type; + public abstract String getEncoding(); - static final class Builder { + public abstract Boolean getOnlyReadLatest(); - private String familyID; - private List columns; - private String encoding; - private Boolean onlyReadLatest; - private String type; + public abstract String getType(); - private Builder() { - } + @AutoValue.Builder + public abstract static class Builder { /** * Identifier of the column family. */ - Builder setFamilyID(String familyID) { - this.familyID = familyID; - return this; - } + public abstract Builder setFamilyID(String familyID); /** * Lists of columns that should be exposed as individual fields as opposed to a list of (column * name, value) pairs. All columns whose qualifier matches a qualifier in this list can be * accessed as .. Other columns can be accessed as a list through .Column field. */ - Builder setColumns(List columns) { - this.columns = columns; - return this; - } + public abstract Builder setColumns(List columns); /** * The encoding of the values when the type is not STRING. @@ -120,20 +74,14 @@ Builder setColumns(List columns) { * This can be overridden for a specific column by listing that column in 'columns' and * specifying an encoding for it. */ - Builder setEncoding(String encoding) { - this.encoding = encoding; - return this; - } + public abstract Builder setEncoding(String encoding); /** * If true, only the latest version of values are exposed for all columns in this column family. * This can be overridden for a specific column by listing that column in 'columns' and * specifying a different setting for that column. */ - Builder setOnlyReadLatest(Boolean onlyReadLatest) { - this.onlyReadLatest = onlyReadLatest; - return this; - } + public abstract Builder setOnlyReadLatest(Boolean onlyReadLatest); /** * The type to convert the value in cells of this column family. The values are expected to be @@ -144,71 +92,19 @@ Builder setOnlyReadLatest(Boolean onlyReadLatest) { * The default type is BYTES. This can be overridden for a specific column by listing that * column in 'columns' and specifying a type for it. */ - Builder setType(String type) { - this.type = type; - return this; - } + public abstract Builder setType(String type); - BigtableColumnFamily build() { - return new BigtableColumnFamily(this); - } - } - - - BigtableColumnFamily(Builder builder) { - familyID = builder.familyID; - columns = builder.columns; - encoding = builder.encoding; - onlyReadLatest = builder.onlyReadLatest; - type = builder.type; - - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("familyID", familyID) - .add("columns", columns) - .add("encoding", encoding) - .add("onlyReadLatest", onlyReadLatest) - .add("type", type) - .toString(); - } - - @Override - public final int hashCode() { - return Objects.hash( - familyID, - columns, - encoding, - onlyReadLatest, - type); - } - - @Override - public final boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (obj == null || !obj.getClass().equals(BigtableColumnFamily.class)) { - return false; - } - BigtableColumnFamily other = (BigtableColumnFamily) obj; - return familyID == other.familyID - && encoding == other.encoding - && onlyReadLatest == other.onlyReadLatest - && type == other.type - && Objects.equals(columns, other.columns); + public abstract BigtableColumnFamily build(); } static Builder newBuilder() { - return new Builder(); + return new AutoValue_BigtableColumnFamily.Builder(); } static BigtableColumnFamily fromPb( com.google.api.services.bigquery.model.BigtableColumnFamily columnFamily) { - Builder builder = new BigtableColumnFamily.Builder(); + Builder builder = newBuilder(); builder.setFamilyID(columnFamily.getFamilyId()); builder.setColumns(Lists.transform(columnFamily.getColumns(), BigtableColumn.FROM_PB_FUNCTION)); builder.setEncoding(columnFamily.getEncoding()); @@ -220,15 +116,33 @@ static BigtableColumnFamily fromPb( com.google.api.services.bigquery.model.BigtableColumnFamily toPb() { com.google.api.services.bigquery.model.BigtableColumnFamily colFamilyPb = new com.google.api.services.bigquery.model.BigtableColumnFamily() - .setFamilyId(familyID) - .setEncoding(encoding) - .setOnlyReadLatest(onlyReadLatest) - .setType(type); - if (columns != null) { - colFamilyPb.setColumns(Lists.transform(columns, BigtableColumn.TO_PB_FUNCTION)); + .setFamilyId(getFamilyID()) + .setEncoding(getEncoding()) + .setOnlyReadLatest(getOnlyReadLatest()) + .setType(getType()); + if (getColumns() != null) { + colFamilyPb.setColumns(Lists.transform(getColumns(), BigtableColumn.TO_PB_FUNCTION)); } return colFamilyPb; } + + static final Function FROM_PB_FUNCTION = + new Function() { + @Override + public BigtableColumnFamily apply( + com.google.api.services.bigquery.model.BigtableColumnFamily pb) { + return BigtableColumnFamily.fromPb(pb); + } + }; + + static final Function TO_PB_FUNCTION = + new Function() { + @Override + public com.google.api.services.bigquery.model.BigtableColumnFamily apply( + BigtableColumnFamily columnFamily) { + return columnFamily.toPb(); + } + }; } From b4bf8095bb8458d60e37a365ceba746fc6426586 Mon Sep 17 00:00:00 2001 From: Seth Hollyman Date: Tue, 19 Jun 2018 10:09:22 -0700 Subject: [PATCH 6/8] excise unused imports, address codacy kvetching about declaration order. --- .../java/com/google/cloud/bigquery/BigtableColumn.java | 3 --- .../com/google/cloud/bigquery/BigtableColumnFamily.java | 3 --- .../java/com/google/cloud/bigquery/BigtableOptions.java | 8 +++++--- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java index aa14b19bd4d1..bc8688218145 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java @@ -17,10 +17,7 @@ import com.google.common.base.Function; -import com.google.common.base.MoreObjects; import com.google.auto.value.AutoValue; -import java.io.Serializable; -import java.util.Objects; import javax.annotation.Nullable; @AutoValue diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java index f08f3d402ec7..9511afdb1b4e 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java @@ -17,12 +17,9 @@ import com.google.common.base.Function; -import com.google.common.base.MoreObjects; import com.google.common.collect.Lists; import com.google.auto.value.AutoValue; -import java.io.Serializable; import java.util.List; -import java.util.Objects; /** * List of column families to expose in the table schema along with their types. This list restricts diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java index adeaa6e3cbc3..a6601e2f1362 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java @@ -27,6 +27,10 @@ public class BigtableOptions extends FormatOptions { private static final long serialVersionUID = 1L; + private final Boolean ignoreUnspecifiedColumnFamilies; + private final Boolean readRowkeyAsString; + private final List columnFamilies; + public Boolean getIgnoreUnspecifiedColumnFamilies() { return ignoreUnspecifiedColumnFamilies; } @@ -39,9 +43,7 @@ public List getColumnFamilies() { return columnFamilies; } - private final Boolean ignoreUnspecifiedColumnFamilies; - private final Boolean readRowkeyAsString; - private final List columnFamilies; + static final class Builder { From a8807521b472f6fbb918f0a5cb836948494c4854 Mon Sep 17 00:00:00 2001 From: Seth Hollyman Date: Tue, 19 Jun 2018 12:20:35 -0700 Subject: [PATCH 7/8] Address reviewer comments: formatting/whitespace, serializable, asserts --- .../google/cloud/bigquery/BigtableColumn.java | 44 ++++++------- .../cloud/bigquery/BigtableColumnFamily.java | 6 +- .../cloud/bigquery/BigtableOptions.java | 14 ++-- .../google/cloud/bigquery/FormatOptions.java | 18 ++--- .../cloud/bigquery/BigtableOptionsTest.java | 65 ++++++++++--------- 5 files changed, 71 insertions(+), 76 deletions(-) diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java index bc8688218145..8f18b548cda3 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumn.java @@ -15,13 +15,13 @@ */ package com.google.cloud.bigquery; - import com.google.common.base.Function; import com.google.auto.value.AutoValue; +import java.io.Serializable; import javax.annotation.Nullable; @AutoValue -public abstract class BigtableColumn { +public abstract class BigtableColumn implements Serializable { private static final long serialVersionUID = 1L; @@ -43,53 +43,50 @@ public abstract class BigtableColumn { @AutoValue.Builder public abstract static class Builder { - /** * Qualifier of the column. * - * Columns in the parent column family that has this exact qualifier are exposed - * as . field. If the qualifier is valid UTF-8 string, it can be specified in the - * qualifier_string field. Otherwise, a base-64 encoded value must be set to qualifier_encoded. The column field name is the same as the - * column qualifier. However, if the qualifier is not a valid BigQuery field + * Columns in the parent column family that has this exact qualifier are exposed as . field. If + * the qualifier is valid UTF-8 string, it can be specified in the qualifier_string field. + * Otherwise, a base-64 encoded value must be set to qualifier_encoded. The column field name is + * the same as the column qualifier. However, if the qualifier is not a valid BigQuery field * identifier, a valid identifier must be provided as field_name. */ public abstract Builder setQualifierEncoded(String qualifierEncoded); /** - * If the qualifier is not a valid BigQuery field identifier, a valid identifier must - * be provided as the column field name and is used as field name in queries. + * If the qualifier is not a valid BigQuery field identifier, a valid identifier must be + * provided as the column field name and is used as field name in queries. */ public abstract Builder setFieldName(String fieldName); /** * If this is set, only the latest version of value in this column are exposed. * - * 'onlyReadLatest' can also be set at the column family level. However, the setting - * at the column level takes precedence if 'onlyReadLatest' is set at both levels. + * 'onlyReadLatest' can also be set at the column family level. However, the setting at the + * column level takes precedence if 'onlyReadLatest' is set at both levels. */ public abstract Builder setOnlyReadLatest(Boolean onlyReadLatest); /** - * The encoding of the values when the type is not STRING. - * Acceptable encoding values are: - * TEXT - indicates values are alphanumeric text strings. - * BINARY - indicates values are encoded using HBase Bytes.toBytes family of functions. + * The encoding of the values when the type is not STRING. Acceptable encoding values are: TEXT + * - indicates values are alphanumeric text strings. BINARY - indicates values are encoded using + * HBase Bytes.toBytes family of functions. * - * Encoding can also be set at the column family level. However, the setting at the - * column level takes precedence if 'encoding' is set at both levels. + * Encoding can also be set at the column family level. However, the setting at the column level + * takes precedence if 'encoding' is set at both levels. */ public abstract Builder setEncoding(String encoding); /** * The type to convert the value in cells of this column. * - * The values are expected to be encoded using HBase Bytes.toBytes function when using - * the BINARY encoding value. Following BigQuery types are allowed (case-sensitive): - * BYTES STRING INTEGER FLOAT BOOLEAN Default type is BYTES. - * - * 'type' can also be set at the column family level. However, the setting at the column - * level takes precedence if 'type' is set at both levels. + * The values are expected to be encoded using HBase Bytes.toBytes function when using the + * BINARY encoding value. Following BigQuery types are allowed (case-sensitive): BYTES STRING + * INTEGER FLOAT BOOLEAN Default type is BYTES. * + * 'type' can also be set at the column family level. However, the setting at the column level + * takes precedence if 'type' is set at both levels. */ public abstract Builder setType(String type); @@ -120,7 +117,6 @@ com.google.api.services.bigquery.model.BigtableColumn toPb() { return column; } - static final Function FROM_PB_FUNCTION = new Function() { @Override diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java index 9511afdb1b4e..2d9993919d33 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableColumnFamily.java @@ -15,10 +15,10 @@ */ package com.google.cloud.bigquery; - import com.google.common.base.Function; import com.google.common.collect.Lists; import com.google.auto.value.AutoValue; +import java.io.Serializable; import java.util.List; /** @@ -32,8 +32,7 @@ */ @AutoValue -public abstract class BigtableColumnFamily { - +public abstract class BigtableColumnFamily implements Serializable { private static final long serialVersionUID = 1L; @@ -98,7 +97,6 @@ static Builder newBuilder() { return new AutoValue_BigtableColumnFamily.Builder(); } - static BigtableColumnFamily fromPb( com.google.api.services.bigquery.model.BigtableColumnFamily columnFamily) { Builder builder = newBuilder(); diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java index a6601e2f1362..2d0e4692749a 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigtableOptions.java @@ -17,14 +17,11 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.Lists; -import java.io.Serializable; import java.util.List; import java.util.Objects; - public class BigtableOptions extends FormatOptions { - private static final long serialVersionUID = 1L; private final Boolean ignoreUnspecifiedColumnFamilies; @@ -43,15 +40,14 @@ public List getColumnFamilies() { return columnFamilies; } - - static final class Builder { private Boolean ignoreUnspecifiedColumnFamilies; private Boolean readRowkeyAsString; private List columnFamilies; - private Builder() {} + private Builder() { + } private Builder(BigtableOptions bigtableOptions) { this.ignoreUnspecifiedColumnFamilies = bigtableOptions.ignoreUnspecifiedColumnFamilies; @@ -142,7 +138,8 @@ static BigtableOptions fromPb(com.google.api.services.bigquery.model.BigtableOpt Builder builder = newBuilder(); builder.setIgnoreUnspecifiedColumnFamilies(options.getIgnoreUnspecifiedColumnFamilies()); builder.setReadRowkeyAsString(options.getReadRowkeyAsString()); - builder.setColumnFamilies(Lists.transform(options.getColumnFamilies(), BigtableColumnFamily.FROM_PB_FUNCTION)); + builder.setColumnFamilies( + Lists.transform(options.getColumnFamilies(), BigtableColumnFamily.FROM_PB_FUNCTION)); return builder.build(); } @@ -151,7 +148,8 @@ com.google.api.services.bigquery.model.BigtableOptions toPb() { .setIgnoreUnspecifiedColumnFamilies(ignoreUnspecifiedColumnFamilies) .setReadRowkeyAsString(readRowkeyAsString); if (columnFamilies != null) { - options.setColumnFamilies(Lists.transform(columnFamilies, BigtableColumnFamily.TO_PB_FUNCTION)); + options + .setColumnFamilies(Lists.transform(columnFamilies, BigtableColumnFamily.TO_PB_FUNCTION)); } return options; } diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FormatOptions.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FormatOptions.java index 3e2e6c4f31c7..71414fd8fc2b 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FormatOptions.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FormatOptions.java @@ -27,12 +27,11 @@ * Base class for Google BigQuery format options. These class define the format of external data * used by BigQuery, for either federated tables or load jobs. * - * Load jobs support the following formats: - * AVRO, CSV, DATASTORE_BACKUP, GOOGLE_SHEETS, JSON, ORC, PARQUET - * - * Federated tables can be defined against following formats: - * AVRO, BIGTABLE, CSV, DATASTORE_BACKUP, GOOGLE_SHEETS, JSON + * Load jobs support the following formats: AVRO, CSV, DATASTORE_BACKUP, GOOGLE_SHEETS, JSON, ORC, + * PARQUET * + * Federated tables can be defined against following formats: AVRO, BIGTABLE, CSV, DATASTORE_BACKUP, + * GOOGLE_SHEETS, JSON */ public class FormatOptions implements Serializable { @@ -53,7 +52,6 @@ public class FormatOptions implements Serializable { this.type = type; } - /** * Returns the external data format, as a string. */ @@ -131,11 +129,13 @@ public static FormatOptions parquet() { /** * Default options for the ORC format. */ - public static FormatOptions orc() { return new FormatOptions(ORC); } + public static FormatOptions orc() { + return new FormatOptions(ORC); + } /** - * Default options for the provided format. - */ + * Default options for the provided format. + */ public static FormatOptions of(String format) { if (checkNotNull(format).equals(CSV)) { return csv(); diff --git a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigtableOptionsTest.java b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigtableOptionsTest.java index 33e7c2bd223f..4ff214e0d063 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigtableOptionsTest.java +++ b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigtableOptionsTest.java @@ -15,6 +15,7 @@ */ package com.google.cloud.bigquery; +import static com.google.common.truth.Truth.assertThat; import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertTrue; @@ -23,7 +24,6 @@ public class BigtableOptionsTest { - private static final BigtableColumn COL1 = BigtableColumn.newBuilder() .setQualifierEncoded("aaa") .setFieldName("field1") @@ -51,28 +51,26 @@ public class BigtableOptionsTest { .setColumnFamilies(ImmutableList.of(TESTFAMILY)) .build(); - @Test public void testConstructors() { - // column - assertEquals(COL1.getQualifierEncoded(), "aaa"); - assertEquals(COL1.getFieldName(), "field1"); - assertTrue(COL1.getOnlyReadLatest()); - assertEquals(COL1.getEncoding(), "BINARY"); - assertEquals(COL1.getType(), "BYTES"); + assertThat(COL1.getQualifierEncoded()).isEqualTo("aaa"); + assertThat(COL1.getFieldName()).isEqualTo("field1"); + assertThat(COL1.getOnlyReadLatest()).isEqualTo(true); + assertThat(COL1.getEncoding()).isEqualTo("BINARY"); + assertThat(COL1.getType()).isEqualTo("BYTES"); // family - assertEquals(TESTFAMILY.getFamilyID(), "fooFamily"); - assertEquals(TESTFAMILY.getEncoding(), "TEXT"); - assertTrue(TESTFAMILY.getOnlyReadLatest()); - assertEquals(TESTFAMILY.getType(), "INTEGER"); - assertEquals(TESTFAMILY.getColumns(), ImmutableList.of(COL1, COL2)); + assertThat(TESTFAMILY.getFamilyID()).isEqualTo("fooFamily"); + assertThat(TESTFAMILY.getEncoding()).isEqualTo("TEXT"); + assertThat(TESTFAMILY.getOnlyReadLatest()).isEqualTo(true); + assertThat(TESTFAMILY.getType()).isEqualTo("INTEGER"); + assertThat(TESTFAMILY.getColumns()).isEqualTo(ImmutableList.of(COL1, COL2)); // options - assertTrue(OPTIONS.getIgnoreUnspecifiedColumnFamilies()); - assertTrue(OPTIONS.getReadRowkeyAsString()); - assertEquals(OPTIONS.getColumnFamilies(), ImmutableList.of(TESTFAMILY)); + assertThat(OPTIONS.getIgnoreUnspecifiedColumnFamilies()).isEqualTo(true); + assertThat(OPTIONS.getReadRowkeyAsString()).isEqualTo(true); + assertThat(OPTIONS.getColumnFamilies()).isEqualTo(ImmutableList.of(TESTFAMILY)); } @Test @@ -90,25 +88,30 @@ public void testEquals() { } private void compareBigtableColumn(BigtableColumn expected, BigtableColumn value) { - assertEquals(expected.getEncoding(), value.getEncoding()); - assertEquals(expected.getFieldName(), value.getFieldName()); - assertEquals(expected.getQualifierEncoded(), value.getQualifierEncoded()); - assertEquals(expected.getOnlyReadLatest(), value.getOnlyReadLatest()); - assertEquals(expected.getType(), value.getType()); + assertThat(expected).isEqualTo(value); + assertThat(expected.getEncoding()).isEqualTo(value.getEncoding()); + assertThat(expected.getFieldName()).isEqualTo(value.getFieldName()); + assertThat(expected.getQualifierEncoded()).isEqualTo(value.getQualifierEncoded()); + assertThat(expected.getOnlyReadLatest()).isEqualTo(value.getOnlyReadLatest()); + assertThat(expected.getType()).isEqualTo(value.getType()); } - private void compareBigtableColumnFamily(BigtableColumnFamily expected, BigtableColumnFamily value) { - assertEquals(expected, value); - assertEquals(expected.getFamilyID(), value.getFamilyID()); - assertEquals(expected.getOnlyReadLatest(), value.getOnlyReadLatest()); - assertEquals(expected.getColumns(), value.getColumns()); - assertEquals(expected.getEncoding(), value.getEncoding()); - assertEquals(expected.getType(), value.getType()); + private void compareBigtableColumnFamily(BigtableColumnFamily expected, + BigtableColumnFamily value) { + assertThat(expected).isEqualTo(value); + assertThat(expected.getFamilyID()).isEqualTo(value.getFamilyID()); + assertThat(expected.getOnlyReadLatest()).isEqualTo(value.getOnlyReadLatest()); + assertThat(expected.getColumns()).isEqualTo(value.getColumns()); + assertThat(expected.getEncoding()).isEqualTo(value.getEncoding()); + assertThat(expected.getType()).isEqualTo(value.getType()); + } private void compareBigtableOptions(BigtableOptions expected, BigtableOptions value) { - assertEquals(expected.getIgnoreUnspecifiedColumnFamilies(), value.getIgnoreUnspecifiedColumnFamilies()); - assertEquals(expected.getReadRowkeyAsString(), value.getReadRowkeyAsString()); - assertEquals(expected.getColumnFamilies(), value.getColumnFamilies()); + assertThat(expected).isEqualTo(value); + assertThat(expected.getIgnoreUnspecifiedColumnFamilies()) + .isEqualTo(value.getIgnoreUnspecifiedColumnFamilies()); + assertThat(expected.getReadRowkeyAsString()).isEqualTo(value.getReadRowkeyAsString()); + assertThat(expected.getColumnFamilies()).isEqualTo(value.getColumnFamilies()); } } \ No newline at end of file From 2b37821cedc1c4b57b460ffcebe79f34d5d7e0ed Mon Sep 17 00:00:00 2001 From: Seth Hollyman Date: Tue, 19 Jun 2018 12:42:42 -0700 Subject: [PATCH 8/8] unused imports (asserts) --- .../java/com/google/cloud/bigquery/BigtableOptionsTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigtableOptionsTest.java b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigtableOptionsTest.java index 4ff214e0d063..bcf886ecaed9 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigtableOptionsTest.java +++ b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigtableOptionsTest.java @@ -16,8 +16,6 @@ package com.google.cloud.bigquery; import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.assertTrue; import com.google.common.collect.ImmutableList; import org.junit.Test;