beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dhalp...@apache.org
Subject [2/2] incubator-beam git commit: Fix NullPointerException in AfterWatermark display data
Date Wed, 15 Jun 2016 19:53:05 GMT
Fix NullPointerException in AfterWatermark display data

Window transforms register display data for the associated trigger
function by calling its .toString() method. The AfterWatermark
trigger .toString() method was not properly handling cases where
there is no late firings registered.


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

Branch: refs/heads/master
Commit: e7f2f582afd48bf5e2aacb3a36471377cb927018
Parents: a1bb902
Author: Scott Wegner <swegner@google.com>
Authored: Wed Jun 15 09:51:59 2016 -0700
Committer: Dan Halperin <dhalperi@google.com>
Committed: Wed Jun 15 12:52:48 2016 -0700

----------------------------------------------------------------------
 .../sdk/transforms/windowing/AfterWatermark.java | 14 +++++++++-----
 .../transforms/windowing/AfterWatermarkTest.java | 19 +++++++++++++++++++
 2 files changed, 28 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/e7f2f582/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/windowing/AfterWatermark.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/windowing/AfterWatermark.java
b/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/windowing/AfterWatermark.java
index e48cc44..019a68d 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/windowing/AfterWatermark.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/windowing/AfterWatermark.java
@@ -31,6 +31,8 @@ import org.joda.time.Instant;
 import java.util.List;
 import java.util.Objects;
 
+import javax.annotation.Nullable;
+
 /**
  * <p>{@code AfterWatermark} triggers fire based on progress of the system watermark.
This time is a
  * lower-bound, sometimes heuristically established, on event times that have been fully
processed
@@ -106,6 +108,7 @@ public class AfterWatermark {
     private static final int LATE_INDEX = 1;
 
     private final OnceTrigger earlyTrigger;
+    @Nullable
     private final OnceTrigger lateTrigger;
 
     @SuppressWarnings("unchecked")
@@ -226,7 +229,6 @@ public class AfterWatermark {
     public String toString() {
       StringBuilder builder = new StringBuilder(TO_STRING);
 
-      Trigger earlyTrigger = subTriggers.get(EARLY_INDEX);
       if (!(earlyTrigger instanceof Never.NeverTrigger)) {
         builder
             .append(".withEarlyFirings(")
@@ -234,10 +236,12 @@ public class AfterWatermark {
             .append(")");
       }
 
-      builder
-          .append(".withLateFirings(")
-          .append(subTriggers.get(LATE_INDEX))
-          .append(")");
+      if (lateTrigger != null && !(lateTrigger instanceof Never.NeverTrigger)) {
+        builder
+            .append(".withLateFirings(")
+            .append(lateTrigger)
+            .append(")");
+      }
 
       return builder.toString();
     }

http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/e7f2f582/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/windowing/AfterWatermarkTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/windowing/AfterWatermarkTest.java
b/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/windowing/AfterWatermarkTest.java
index be0ec1c..d692cbf 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/windowing/AfterWatermarkTest.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/windowing/AfterWatermarkTest.java
@@ -345,6 +345,15 @@ public class AfterWatermarkTest {
   }
 
   @Test
+  public void testEarlyFiringsToString() {
+    Trigger trigger = AfterWatermark.pastEndOfWindow()
+        .withEarlyFirings(StubTrigger.named("t1"))
+        .buildTrigger();
+
+    assertEquals("AfterWatermark.pastEndOfWindow().withEarlyFirings(t1)", trigger.toString());
+  }
+
+  @Test
   public void testLateFiringsToString() {
     Trigger trigger = AfterWatermark.pastEndOfWindow()
         .withLateFirings(StubTrigger.named("t1"))
@@ -363,4 +372,14 @@ public class AfterWatermarkTest {
     assertEquals("AfterWatermark.pastEndOfWindow().withEarlyFirings(t1).withLateFirings(t2)",
         trigger.toString());
   }
+
+  @Test
+  public void testToStringExcludesNeverTrigger() {
+    Trigger trigger = AfterWatermark.pastEndOfWindow()
+        .withEarlyFirings(Never.ever())
+        .withLateFirings(Never.ever())
+        .buildTrigger();
+
+    assertEquals("AfterWatermark.pastEndOfWindow()", trigger.toString());
+  }
 }


Mime
View raw message