beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dhalp...@apache.org
Subject [2/3] beam git commit: Add tests for BigQueryIO table description.
Date Wed, 01 Feb 2017 18:22:04 GMT
Add tests for BigQueryIO table description.


Project: http://git-wip-us.apache.org/repos/asf/beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/8a0e10a3
Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/8a0e10a3
Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/8a0e10a3

Branch: refs/heads/master
Commit: 8a0e10a39e975b3a30397283bdaa46a4b2a553cb
Parents: 3e8810b
Author: Rafal Wojdyla <rav@spotify.com>
Authored: Mon Jan 23 18:14:47 2017 -0500
Committer: Rafal Wojdyla <rav@spotify.com>
Committed: Wed Feb 1 12:34:46 2017 -0500

----------------------------------------------------------------------
 .../sdk/io/gcp/bigquery/BigQueryIOTest.java     | 78 ++++++++++++++++----
 1 file changed, 62 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/beam/blob/8a0e10a3/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryIOTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryIOTest.java
b/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryIOTest.java
index 8b1b6dd..25704d1 100644
--- a/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryIOTest.java
+++ b/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryIOTest.java
@@ -642,6 +642,13 @@ public class BigQueryIOTest implements Serializable {
         return dataSize;
       }
     }
+
+    @Override
+    public Table patchTableDescription(TableReference tableReference,
+                                       @Nullable String tableDescription)
+        throws IOException, InterruptedException {
+      throw new UnsupportedOperationException("Unsupported");
+    }
   }
 
   @Rule public final transient TestPipeline p = TestPipeline.create();
@@ -681,21 +688,30 @@ public class BigQueryIOTest implements Serializable {
   private void checkWriteObject(
       BigQueryIO.Write.Bound bound, String project, String dataset, String table,
       TableSchema schema, CreateDisposition createDisposition,
-      WriteDisposition writeDisposition) {
+      WriteDisposition writeDisposition, String tableDescription) {
     checkWriteObjectWithValidate(
-        bound, project, dataset, table, schema, createDisposition, writeDisposition, true);
+        bound,
+        project,
+        dataset,
+        table,
+        schema,
+        createDisposition,
+        writeDisposition,
+        tableDescription,
+        true);
   }
 
   private void checkWriteObjectWithValidate(
       BigQueryIO.Write.Bound bound, String project, String dataset, String table,
       TableSchema schema, CreateDisposition createDisposition,
-      WriteDisposition writeDisposition, boolean validate) {
+      WriteDisposition writeDisposition, String tableDescription, boolean validate) {
     assertEquals(project, bound.getTable().get().getProjectId());
     assertEquals(dataset, bound.getTable().get().getDatasetId());
     assertEquals(table, bound.getTable().get().getTableId());
     assertEquals(schema, bound.getSchema());
     assertEquals(createDisposition, bound.createDisposition);
     assertEquals(writeDisposition, bound.writeDisposition);
+    assertEquals(tableDescription, bound.tableDescription);
     assertEquals(validate, bound.validate);
   }
 
@@ -1331,7 +1347,7 @@ public class BigQueryIOTest implements Serializable {
             BigQueryIO.Write.to("foo.com:project:somedataset.sometable");
     checkWriteObject(
         bound, "foo.com:project", "somedataset", "sometable",
-        null, CreateDisposition.CREATE_IF_NEEDED, WriteDisposition.WRITE_EMPTY);
+        null, CreateDisposition.CREATE_IF_NEEDED, WriteDisposition.WRITE_EMPTY, null);
   }
 
   @Test
@@ -1377,8 +1393,15 @@ public class BigQueryIOTest implements Serializable {
     BigQueryIO.Write.Bound bound =
         BigQueryIO.Write.to("foo.com:project:somedataset.sometable").withoutValidation();
     checkWriteObjectWithValidate(
-        bound, "foo.com:project", "somedataset", "sometable",
-        null, CreateDisposition.CREATE_IF_NEEDED, WriteDisposition.WRITE_EMPTY, false);
+        bound,
+        "foo.com:project",
+        "somedataset",
+        "sometable",
+        null,
+        CreateDisposition.CREATE_IF_NEEDED,
+        WriteDisposition.WRITE_EMPTY,
+        null,
+        false);
   }
 
   @Test
@@ -1386,7 +1409,7 @@ public class BigQueryIOTest implements Serializable {
     BigQueryIO.Write.Bound bound = BigQueryIO.Write.to("somedataset.sometable");
     checkWriteObject(
         bound, null, "somedataset", "sometable",
-        null, CreateDisposition.CREATE_IF_NEEDED, WriteDisposition.WRITE_EMPTY);
+        null, CreateDisposition.CREATE_IF_NEEDED, WriteDisposition.WRITE_EMPTY, null);
   }
 
   @Test
@@ -1398,7 +1421,7 @@ public class BigQueryIOTest implements Serializable {
     BigQueryIO.Write.Bound bound = BigQueryIO.Write.to(table);
     checkWriteObject(
         bound, "foo.com:project", "somedataset", "sometable",
-        null, CreateDisposition.CREATE_IF_NEEDED, WriteDisposition.WRITE_EMPTY);
+        null, CreateDisposition.CREATE_IF_NEEDED, WriteDisposition.WRITE_EMPTY, null);
   }
 
   @Test
@@ -1418,7 +1441,7 @@ public class BigQueryIOTest implements Serializable {
         BigQueryIO.Write.to("foo.com:project:somedataset.sometable").withSchema(schema);
     checkWriteObject(
         bound, "foo.com:project", "somedataset", "sometable",
-        schema, CreateDisposition.CREATE_IF_NEEDED, WriteDisposition.WRITE_EMPTY);
+        schema, CreateDisposition.CREATE_IF_NEEDED, WriteDisposition.WRITE_EMPTY, null);
   }
 
   @Test
@@ -1428,7 +1451,7 @@ public class BigQueryIOTest implements Serializable {
         .withCreateDisposition(CreateDisposition.CREATE_NEVER);
     checkWriteObject(
         bound, "foo.com:project", "somedataset", "sometable",
-        null, CreateDisposition.CREATE_NEVER, WriteDisposition.WRITE_EMPTY);
+        null, CreateDisposition.CREATE_NEVER, WriteDisposition.WRITE_EMPTY, null);
   }
 
   @Test
@@ -1438,7 +1461,7 @@ public class BigQueryIOTest implements Serializable {
         .withCreateDisposition(CreateDisposition.CREATE_IF_NEEDED);
     checkWriteObject(
         bound, "foo.com:project", "somedataset", "sometable",
-        null, CreateDisposition.CREATE_IF_NEEDED, WriteDisposition.WRITE_EMPTY);
+        null, CreateDisposition.CREATE_IF_NEEDED, WriteDisposition.WRITE_EMPTY, null);
   }
 
   @Test
@@ -1448,7 +1471,7 @@ public class BigQueryIOTest implements Serializable {
         .withWriteDisposition(WriteDisposition.WRITE_TRUNCATE);
     checkWriteObject(
         bound, "foo.com:project", "somedataset", "sometable",
-        null, CreateDisposition.CREATE_IF_NEEDED, WriteDisposition.WRITE_TRUNCATE);
+        null, CreateDisposition.CREATE_IF_NEEDED, WriteDisposition.WRITE_TRUNCATE, null);
   }
 
   @Test
@@ -1458,7 +1481,7 @@ public class BigQueryIOTest implements Serializable {
         .withWriteDisposition(WriteDisposition.WRITE_APPEND);
     checkWriteObject(
         bound, "foo.com:project", "somedataset", "sometable",
-        null, CreateDisposition.CREATE_IF_NEEDED, WriteDisposition.WRITE_APPEND);
+        null, CreateDisposition.CREATE_IF_NEEDED, WriteDisposition.WRITE_APPEND, null);
   }
 
   @Test
@@ -1468,19 +1491,38 @@ public class BigQueryIOTest implements Serializable {
         .withWriteDisposition(WriteDisposition.WRITE_EMPTY);
     checkWriteObject(
         bound, "foo.com:project", "somedataset", "sometable",
-        null, CreateDisposition.CREATE_IF_NEEDED, WriteDisposition.WRITE_EMPTY);
+        null, CreateDisposition.CREATE_IF_NEEDED, WriteDisposition.WRITE_EMPTY, null);
+  }
+
+  @Test
+  public void testBuildWriteWithWriteWithTableDescription() {
+    final String tblDescription = "foo bar table";
+    BigQueryIO.Write.Bound bound = BigQueryIO.Write
+        .to("foo.com:project:somedataset.sometable")
+        .withTableDescription(tblDescription);
+    checkWriteObject(
+        bound,
+        "foo.com:project",
+        "somedataset",
+        "sometable",
+        null,
+        CreateDisposition.CREATE_IF_NEEDED,
+        WriteDisposition.WRITE_EMPTY,
+        tblDescription);
   }
 
   @Test
   public void testBuildWriteDisplayData() {
     String tableSpec = "project:dataset.table";
     TableSchema schema = new TableSchema().set("col1", "type1").set("col2", "type2");
+    final String tblDescription = "foo bar table";
 
     BigQueryIO.Write.Bound write = BigQueryIO.Write
         .to(tableSpec)
         .withSchema(schema)
         .withCreateDisposition(CreateDisposition.CREATE_IF_NEEDED)
         .withWriteDisposition(WriteDisposition.WRITE_APPEND)
+        .withTableDescription(tblDescription)
         .withoutValidation();
 
     DisplayData displayData = DisplayData.from(write);
@@ -1491,6 +1533,8 @@ public class BigQueryIOTest implements Serializable {
         hasDisplayItem("createDisposition", CreateDisposition.CREATE_IF_NEEDED.toString()));
     assertThat(displayData,
         hasDisplayItem("writeDisposition", WriteDisposition.WRITE_APPEND.toString()));
+    assertThat(displayData,
+        hasDisplayItem("tableDescription", tblDescription));
     assertThat(displayData, hasDisplayItem("validation", false));
   }
 
@@ -2186,7 +2230,8 @@ public class BigQueryIOTest implements Serializable {
         StaticValueProvider.of(jsonTable),
         StaticValueProvider.of(jsonSchema),
         WriteDisposition.WRITE_EMPTY,
-        CreateDisposition.CREATE_IF_NEEDED);
+        CreateDisposition.CREATE_IF_NEEDED,
+        null);
 
     DoFnTester<KV<Long, Iterable<List<String>>>, String> tester =
DoFnTester.of(writeTables);
     for (KV<Long, Iterable<List<String>>> partition : partitions) {
@@ -2257,7 +2302,8 @@ public class BigQueryIOTest implements Serializable {
         StaticValueProvider.of(jsonTable),
         WriteDisposition.WRITE_EMPTY,
         CreateDisposition.CREATE_IF_NEEDED,
-        tempTablesView);
+        tempTablesView,
+        null);
 
     DoFnTester<String, Void> tester = DoFnTester.of(writeRename);
     tester.setSideInput(tempTablesView, GlobalWindow.INSTANCE, tempTables);


Mime
View raw message