beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Work logged] (BEAM-5406) NullPointerException when converting Null Datetime to TableRow
Date Tue, 18 Sep 2018 18:26:00 GMT

     [ https://issues.apache.org/jira/browse/BEAM-5406?focusedWorklogId=145417&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-145417
]

ASF GitHub Bot logged work on BEAM-5406:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 18/Sep/18 18:25
            Start Date: 18/Sep/18 18:25
    Worklog Time Spent: 10m 
      Work Description: lukecwik closed pull request #6410: [BEAM-5406] Return null when a
datetime data element is null.
URL: https://github.com/apache/beam/pull/6410
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 4578ea4b74c..ccab332429e 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 static TableRow toTableRow(Row row) {
               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 a5167c0034a..1a0902a4f66 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 @@
           .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 void testToTableRow_array_row() {
     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));
+  }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 145417)
    Time Spent: 20m  (was: 10m)

> NullPointerException when converting Null Datetime to TableRow
> --------------------------------------------------------------
>
>                 Key: BEAM-5406
>                 URL: https://issues.apache.org/jira/browse/BEAM-5406
>             Project: Beam
>          Issue Type: Bug
>          Components: io-java-gcp
>    Affects Versions: 2.6.0
>            Reporter: Andrew Kujtan
>            Assignee: Chamikara Jayalath
>            Priority: Major
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> BigQueryUtils.toTableRow() throws a NPE for null Datetime column data. It should simply
return null.
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message