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: [BEAM-468] NullableCoder should not ask valueCoder isRegisterByteSizeObserverCheap when value is null
Date Mon, 18 Jul 2016 22:42:24 GMT
[BEAM-468] NullableCoder should not ask valueCoder isRegisterByteSizeObserverCheap when value
is null


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

Branch: refs/heads/master
Commit: 66ba594e3730f87fe8d99b4550e3bac5a80e5178
Parents: 8410b47
Author: Luke Cwik <lcwik@google.com>
Authored: Mon Jul 18 13:14:33 2016 -0700
Committer: Dan Halperin <dhalperi@google.com>
Committed: Mon Jul 18 15:42:14 2016 -0700

----------------------------------------------------------------------
 .../apache/beam/sdk/coders/NullableCoder.java   |  3 +++
 .../beam/sdk/coders/NullableCoderTest.java      | 26 +++++++++++---------
 2 files changed, 18 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/66ba594e/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/NullableCoder.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/NullableCoder.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/NullableCoder.java
index a8ce873..4001b81 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/NullableCoder.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/NullableCoder.java
@@ -175,6 +175,9 @@ public class NullableCoder<T> extends StandardCoder<T> {
    */
   @Override
   public boolean isRegisterByteSizeObserverCheap(@Nullable T value, Context context) {
+    if (value == null) {
+      return true;
+    }
     return valueCoder.isRegisterByteSizeObserverCheap(value, context.nested());
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/66ba594e/sdks/java/core/src/test/java/org/apache/beam/sdk/coders/NullableCoderTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/coders/NullableCoderTest.java
b/sdks/java/core/src/test/java/org/apache/beam/sdk/coders/NullableCoderTest.java
index 1e669ac..5bfbe05 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/coders/NullableCoderTest.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/coders/NullableCoderTest.java
@@ -90,29 +90,33 @@ public class NullableCoderTest {
 
   @Test
   public void testWireFormatEncode() throws Exception {
-      CoderProperties.coderEncodesBase64(TEST_CODER, TEST_VALUES, TEST_ENCODINGS);
+    CoderProperties.coderEncodesBase64(TEST_CODER, TEST_VALUES, TEST_ENCODINGS);
   }
 
   @Test
   public void testEncodedSize() throws Exception {
-      NullableCoder<Double> coder = NullableCoder.of(DoubleCoder.of());
-      assertEquals(1, coder.getEncodedElementByteSize(null, Coder.Context.OUTER));
-      assertEquals(9, coder.getEncodedElementByteSize(5.0, Coder.Context.OUTER));
+    NullableCoder<Double> coder = NullableCoder.of(DoubleCoder.of());
+    assertEquals(1, coder.getEncodedElementByteSize(null, Coder.Context.OUTER));
+    assertEquals(9, coder.getEncodedElementByteSize(5.0, Coder.Context.OUTER));
   }
 
   @Test
   public void testObserverIsCheap() throws Exception {
-      NullableCoder<Double> coder = NullableCoder.of(DoubleCoder.of());
-      assertTrue(coder.isRegisterByteSizeObserverCheap(null, Coder.Context.OUTER));
-      assertTrue(coder.isRegisterByteSizeObserverCheap(5.0, Coder.Context.OUTER));
+    NullableCoder<Double> coder = NullableCoder.of(DoubleCoder.of());
+    assertTrue(coder.isRegisterByteSizeObserverCheap(5.0, Coder.Context.OUTER));
   }
 
   @Test
   public void testObserverIsNotCheap() throws Exception {
-      NullableCoder<List<String>> coder = NullableCoder.of(ListCoder.of(StringUtf8Coder.of()));
-      assertFalse(coder.isRegisterByteSizeObserverCheap(null, Coder.Context.OUTER));
-      assertFalse(coder.isRegisterByteSizeObserverCheap(
-          ImmutableList.of("hi", "test"), Coder.Context.OUTER));
+    NullableCoder<List<String>> coder = NullableCoder.of(ListCoder.of(StringUtf8Coder.of()));
+    assertFalse(coder.isRegisterByteSizeObserverCheap(
+        ImmutableList.of("hi", "test"), Coder.Context.OUTER));
+  }
+
+  @Test
+  public void testObserverIsAlwaysCheapForNullValues() throws Exception {
+    NullableCoder<List<String>> coder = NullableCoder.of(ListCoder.of(StringUtf8Coder.of()));
+    assertTrue(coder.isRegisterByteSizeObserverCheap(null, Coder.Context.OUTER));
   }
 
   @Test


Mime
View raw message