From bd58ee509d5663189d74485e92d70d70d44da43b Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 3 Dec 2015 22:35:36 +0100 Subject: [PATCH] Make FormatOptions.csv return CsvOptions, remove getters from ExternalDataConfiguration --- .../google/gcloud/bigquery/CsvOptions.java | 5 ++-- .../bigquery/ExternalDataConfiguration.java | 27 +++++++------------ .../google/gcloud/bigquery/FormatOptions.java | 4 +-- .../ExternalDataConfigurationTest.java | 7 ++--- 4 files changed, 16 insertions(+), 27 deletions(-) diff --git a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/CsvOptions.java b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/CsvOptions.java index 5c52cd78cc8f..40655e2c0c36 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/CsvOptions.java +++ b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/CsvOptions.java @@ -203,6 +203,7 @@ public Builder toBuilder() { @Override public String toString() { return MoreObjects.toStringHelper(this) + .add("type", type()) .add("allowJaggedRows", allowJaggedRows) .add("allowQuotedNewLines", allowQuotedNewLines) .add("encoding", encoding) @@ -214,8 +215,8 @@ public String toString() { @Override public int hashCode() { - return Objects.hash(allowJaggedRows, allowQuotedNewLines, encoding, fieldDelimiter, quote, - skipLeadingRows); + return Objects.hash(type(), allowJaggedRows, allowQuotedNewLines, encoding, fieldDelimiter, + quote, skipLeadingRows); } @Override diff --git a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ExternalDataConfiguration.java b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ExternalDataConfiguration.java index 5d55080a88d5..9e049c4f13d6 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ExternalDataConfiguration.java +++ b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ExternalDataConfiguration.java @@ -179,8 +179,8 @@ public String compression() { * Returns whether BigQuery should allow extra values that are not represented in the table * schema. If true, the extra values are ignored. If false, records with extra columns are treated * as bad records, and if there are too many bad records, an invalid error is returned in the job - * result. The default value is false. The value of {@link #format()} determines what BigQuery - * treats as an extra value. + * result. The default value is false. The value of {@link #formatOptions()} determines what + * BigQuery treats as an extra value. * * @see * Ignore Unknown Values @@ -204,16 +204,6 @@ public Schema schema() { return schema; } - /** - * Returns the source format of the external data. - * - * - * Source Format - */ - public String format() { - return formatOptions.type(); - } - /** * Returns the fully-qualified URIs that point to your data in Google Cloud Storage. Each URI can * contain one '*' wildcard character that must come after the bucket's name. Size limits @@ -227,11 +217,12 @@ public List sourceUris() { } /** - * Returns additional properties used to parse CSV data (used when {@link #format()} is set to - * CSV). Returns {@code null} if not set. + * Returns the source format, and possibly some parsing options, of the external data. Supported + * formats are {@code CSV} and {@code NEWLINE_DELIMITED_JSON}. */ - public CsvOptions csvOptions() { - return formatOptions instanceof CsvOptions ? (CsvOptions) formatOptions : null; + @SuppressWarnings("unchecked") + public F formatOptions() { + return (F) formatOptions; } /** @@ -292,8 +283,8 @@ com.google.api.services.bigquery.model.ExternalDataConfiguration toPb() { if (sourceUris != null) { externalConfigurationPb.setSourceUris(sourceUris); } - if (csvOptions() != null) { - externalConfigurationPb.setCsvOptions(csvOptions().toPb()); + if (formatOptions instanceof CsvOptions) { + externalConfigurationPb.setCsvOptions(((CsvOptions) formatOptions).toPb()); } return externalConfigurationPb; } diff --git a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/FormatOptions.java b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/FormatOptions.java index 8a6884daf65d..e1f9d5aeb545 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/FormatOptions.java +++ b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/FormatOptions.java @@ -63,8 +63,8 @@ public boolean equals(Object obj) { /** * Default options for CSV format. */ - public static FormatOptions csv() { - return new FormatOptions(CSV); + public static CsvOptions csv() { + return CsvOptions.builder().build(); } /** diff --git a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ExternalDataConfigurationTest.java b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ExternalDataConfigurationTest.java index cba03317ccb9..f9b7c31e1071 100644 --- a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ExternalDataConfigurationTest.java +++ b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ExternalDataConfigurationTest.java @@ -43,7 +43,6 @@ public class ExternalDataConfigurationTest { .description("FieldDescription3") .build(); private static final Schema TABLE_SCHEMA = Schema.of(FIELD_SCHEMA1, FIELD_SCHEMA2, FIELD_SCHEMA3); - private static final String SOURCE_FORMAT = "CSV"; private static final Integer MAX_BAD_RECORDS = 42; private static final Boolean IGNORE_UNKNOWN_VALUES = true; private static final String COMPRESSION = "GZIP"; @@ -76,11 +75,10 @@ public void testToBuilderIncomplete() { @Test public void testBuilder() { assertEquals(COMPRESSION, CONFIGURATION.compression()); - assertEquals(CSV_OPTIONS, CONFIGURATION.csvOptions()); + assertEquals(CSV_OPTIONS, CONFIGURATION.formatOptions()); assertEquals(IGNORE_UNKNOWN_VALUES, CONFIGURATION.ignoreUnknownValues()); assertEquals(MAX_BAD_RECORDS, CONFIGURATION.maxBadRecords()); assertEquals(TABLE_SCHEMA, CONFIGURATION.schema()); - assertEquals(SOURCE_FORMAT, CONFIGURATION.format()); assertEquals(SOURCE_URIS, CONFIGURATION.sourceUris()); } @@ -96,11 +94,10 @@ private void compareConfiguration(ExternalDataConfiguration expected, ExternalDataConfiguration value) { assertEquals(expected, value); assertEquals(expected.compression(), value.compression()); - assertEquals(expected.csvOptions(), value.csvOptions()); + assertEquals(expected.formatOptions(), value.formatOptions()); assertEquals(expected.ignoreUnknownValues(), value.ignoreUnknownValues()); assertEquals(expected.maxBadRecords(), value.maxBadRecords()); assertEquals(expected.schema(), value.schema()); - assertEquals(expected.format(), value.format()); assertEquals(expected.sourceUris(), value.sourceUris()); } }