From 1643cf19cb88dc656c0c32ed4def29212b2f59b4 Mon Sep 17 00:00:00 2001 From: vam Date: Fri, 27 Jan 2017 14:26:17 -0800 Subject: [PATCH] BigQuery: Add support to FormatOptions for AVRO https://github.com/GoogleCloudPlatform/google-cloud-java/issues/1441 Added new constant in FormatOptions and a corresponding factory method. Updated test cases. Confirmed that AVRO does not require special treatment (like CSV does), so no additional changes are required. --- .../java/com/google/cloud/bigquery/FormatOptions.java | 8 ++++++++ .../java/com/google/cloud/bigquery/FormatOptionsTest.java | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FormatOptions.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FormatOptions.java index ef451e844a3e..40ec11ebf6b9 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FormatOptions.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FormatOptions.java @@ -32,6 +32,7 @@ public class FormatOptions implements Serializable { static final String CSV = "CSV"; static final String JSON = "NEWLINE_DELIMITED_JSON"; static final String DATASTORE_BACKUP = "DATASTORE_BACKUP"; + static final String AVRO = "AVRO"; private static final long serialVersionUID = -443376052020423691L; private final String type; @@ -94,6 +95,13 @@ public static FormatOptions datastoreBackup() { return new FormatOptions(DATASTORE_BACKUP); } + /** + * Default options for AVRO format. + */ + public static FormatOptions avro() { + return new FormatOptions(AVRO); + } + /** * Default options for the provided format. */ diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/FormatOptionsTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/FormatOptionsTest.java index bd231f0249e6..a019e347ba84 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/FormatOptionsTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/FormatOptionsTest.java @@ -30,9 +30,12 @@ public void testConstructor() { assertEquals(FormatOptions.JSON, options.getType()); options = new FormatOptions(FormatOptions.DATASTORE_BACKUP); assertEquals(FormatOptions.DATASTORE_BACKUP, options.getType()); + options = new FormatOptions(FormatOptions.AVRO); + assertEquals(FormatOptions.AVRO, options.getType()); } @Test + @SuppressWarnings("deprecation") public void testConstructorDeprecated() { FormatOptions options = new FormatOptions(FormatOptions.CSV); assertEquals(FormatOptions.CSV, options.type()); @@ -40,6 +43,8 @@ public void testConstructorDeprecated() { assertEquals(FormatOptions.JSON, options.type()); options = new FormatOptions(FormatOptions.DATASTORE_BACKUP); assertEquals(FormatOptions.DATASTORE_BACKUP, options.type()); + options = new FormatOptions(FormatOptions.AVRO); + assertEquals(FormatOptions.AVRO, options.type()); } @Test @@ -47,6 +52,7 @@ public void testFactoryMethods() { assertEquals(FormatOptions.CSV, FormatOptions.csv().getType()); assertEquals(FormatOptions.JSON, FormatOptions.json().getType()); assertEquals(FormatOptions.DATASTORE_BACKUP, FormatOptions.datastoreBackup().getType()); + assertEquals(FormatOptions.AVRO, FormatOptions.avro().getType()); } @Test