kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ewe...@apache.org
Subject kafka git commit: KAFKA-3864: make field.get return field's default value when needed
Date Mon, 20 Jun 2016 19:33:00 GMT
Repository: kafka
Updated Branches:
  refs/heads/0.10.0 412d2da29 -> 8d63690ef


KAFKA-3864: make field.get return field's default value when needed

And not the containing struct's default value.

The contribution is my original work and that I license the work to the project under the
project's open source license.

ewencp

Author: Rollulus <roelboel@xs4all.nl>

Reviewers: Ewen Cheslack-Postava <ewen@confluent.io>

Closes #1528 from rollulus/kafka-3864

(cherry picked from commit 4544ee448703b8c1900adcb7a605380eb99a00a2)
Signed-off-by: Ewen Cheslack-Postava <me@ewencp.org>


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

Branch: refs/heads/0.10.0
Commit: 8d63690ef5b3cbf040b1eeb091f2949581ae1aa6
Parents: 412d2da
Author: Rollulus <roelboel@xs4all.nl>
Authored: Mon Jun 20 12:30:27 2016 -0700
Committer: Ewen Cheslack-Postava <me@ewencp.org>
Committed: Mon Jun 20 12:32:56 2016 -0700

----------------------------------------------------------------------
 .../java/org/apache/kafka/connect/data/Struct.java   |  4 ++--
 .../org/apache/kafka/connect/data/StructTest.java    | 15 +++++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/8d63690e/connect/api/src/main/java/org/apache/kafka/connect/data/Struct.java
----------------------------------------------------------------------
diff --git a/connect/api/src/main/java/org/apache/kafka/connect/data/Struct.java b/connect/api/src/main/java/org/apache/kafka/connect/data/Struct.java
index a598259..f0bf865 100644
--- a/connect/api/src/main/java/org/apache/kafka/connect/data/Struct.java
+++ b/connect/api/src/main/java/org/apache/kafka/connect/data/Struct.java
@@ -85,8 +85,8 @@ public class Struct {
      */
     public Object get(Field field) {
         Object val = values[field.index()];
-        if (val == null && schema.defaultValue() != null) {
-            val = schema.defaultValue();
+        if (val == null && field.schema().defaultValue() != null) {
+            val = field.schema().defaultValue();
         }
         return val;
     }

http://git-wip-us.apache.org/repos/asf/kafka/blob/8d63690e/connect/api/src/test/java/org/apache/kafka/connect/data/StructTest.java
----------------------------------------------------------------------
diff --git a/connect/api/src/test/java/org/apache/kafka/connect/data/StructTest.java b/connect/api/src/test/java/org/apache/kafka/connect/data/StructTest.java
index c73992b..11c9fb0 100644
--- a/connect/api/src/test/java/org/apache/kafka/connect/data/StructTest.java
+++ b/connect/api/src/test/java/org/apache/kafka/connect/data/StructTest.java
@@ -28,6 +28,7 @@ import java.util.Map;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNull;
 
 public class StructTest {
 
@@ -160,6 +161,20 @@ public class StructTest {
         struct.validate();
     }
 
+    @Test
+    public void testMissingFieldWithDefaultValue() {
+        Schema schema = SchemaBuilder.struct().field("field", DEFAULT_FIELD_SCHEMA).build();
+        Struct struct = new Struct(schema);
+        assertEquals((byte) 0, struct.get("field"));
+    }
+
+    @Test
+    public void testMissingFieldWithoutDefaultValue() {
+        Schema schema = SchemaBuilder.struct().field("field", REQUIRED_FIELD_SCHEMA).build();
+        Struct struct = new Struct(schema);
+        assertNull(struct.get("field"));
+    }
+
 
     @Test
     public void testEquals() {


Mime
View raw message