beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lc...@apache.org
Subject [beam] branch master updated: [BEAM-5406] Return null when a datetime data element is null. (#6410)
Date Tue, 18 Sep 2018 18:25:36 GMT
This is an automated email from the ASF dual-hosted git repository.

lcwik pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new f0dc8ee  [BEAM-5406] Return null when a datetime data element is null. (#6410)
f0dc8ee is described below

commit f0dc8eef932eb7c5547cf03e8d792f985dc9cdb0
Author: Shnitz <andrewktan@gmail.com>
AuthorDate: Tue Sep 18 14:25:27 2018 -0400

    [BEAM-5406] Return null when a datetime data element is null. (#6410)
---
 .../apache/beam/sdk/io/gcp/bigquery/BigQueryUtils.java    |  2 +-
 .../beam/sdk/io/gcp/bigquery/BigQueryUtilsTest.java       | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtils.java
b/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtils.java
index 4578ea4..ccab332 100644
--- a/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtils.java
+++ b/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtils.java
@@ -238,7 +238,7 @@ public class BigQueryUtils {
               new DateTimeFormatterBuilder()
                   .appendPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZZ")
                   .toFormatter();
-          value = ((Instant) value).toDateTime().toString(patternFormat);
+          value = value == null ? null : ((Instant) value).toDateTime().toString(patternFormat);
           break;
         default:
           value = row.getValue(i);
diff --git a/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtilsTest.java
b/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtilsTest.java
index a5167c0..1a0902a 100644
--- a/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtilsTest.java
+++ b/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtilsTest.java
@@ -83,6 +83,9 @@ public class BigQueryUtilsTest {
           .addValues(123L, 123.456, "test", new DateTime(123456), false)
           .build();
 
+  private static final Row NULL_FLAT_ROW =
+      Row.withSchema(FLAT_TYPE).addValues(null, null, null, null, null).build();
+
   private static final Row ARRAY_ROW =
       Row.withSchema(ARRAY_TYPE).addValues((Object) Arrays.asList(123L, 124L)).build();
 
@@ -173,4 +176,16 @@ public class BigQueryUtilsTest {
     assertThat(row, hasEntry("name", "test"));
     assertThat(row, hasEntry("valid", false));
   }
+
+  @Test
+  public void testToTableRow_null_row() {
+    TableRow row = toTableRow().apply(NULL_FLAT_ROW);
+
+    assertThat(row.size(), equalTo(5));
+    assertThat(row, hasEntry("id", null));
+    assertThat(row, hasEntry("value", null));
+    assertThat(row, hasEntry("name", null));
+    assertThat(row, hasEntry("timestamp", null));
+    assertThat(row, hasEntry("valid", null));
+  }
 }


Mime
View raw message