kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ewe...@apache.org
Subject [kafka] branch 1.1 updated: KAFKA-7476: Fix Date-based types in SchemaProjector
Date Fri, 05 Oct 2018 03:35:53 GMT
This is an automated email from the ASF dual-hosted git repository.

ewencp pushed a commit to branch 1.1
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/1.1 by this push:
     new ef6c69d  KAFKA-7476: Fix Date-based types in SchemaProjector
ef6c69d is described below

commit ef6c69d6285be12d5d4efe1dab9505d50636e00d
Author: Robert Yokota <rayokota@gmail.com>
AuthorDate: Thu Oct 4 20:34:50 2018 -0700

    KAFKA-7476: Fix Date-based types in SchemaProjector
    
    Various converters (AvroConverter and JsonConverter) produce a
    SchemaAndValue consisting of a logical schema type and a java.util.Date.
    This is a fix for SchemaProjector to properly handle the Date.
    
    Author: Robert Yokota <rayokota@gmail.com>
    
    Reviewers: Konstantine Karantasis <konstantine@confluent.io>, Ewen Cheslack-Postava
<ewen@confluent.io>
    
    Closes #5736 from rayokota/KAFKA-7476
    
    (cherry picked from commit 3edd8e7333ec0bb32ab5ae4ec4814fe30bb8f91d)
    Signed-off-by: Ewen Cheslack-Postava <me@ewencp.org>
---
 .../java/org/apache/kafka/connect/data/SchemaProjector.java   |  2 +-
 .../org/apache/kafka/connect/data/SchemaProjectorTest.java    | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/connect/api/src/main/java/org/apache/kafka/connect/data/SchemaProjector.java
b/connect/api/src/main/java/org/apache/kafka/connect/data/SchemaProjector.java
index ea31752..5400705 100644
--- a/connect/api/src/main/java/org/apache/kafka/connect/data/SchemaProjector.java
+++ b/connect/api/src/main/java/org/apache/kafka/connect/data/SchemaProjector.java
@@ -160,7 +160,7 @@ public class SchemaProjector {
         assert source.type().isPrimitive();
         assert target.type().isPrimitive();
         Object result;
-        if (isPromotable(source.type(), target.type())) {
+        if (isPromotable(source.type(), target.type()) && record instanceof Number)
{
             Number numberRecord = (Number) record;
             switch (target.type()) {
                 case INT8:
diff --git a/connect/api/src/test/java/org/apache/kafka/connect/data/SchemaProjectorTest.java
b/connect/api/src/test/java/org/apache/kafka/connect/data/SchemaProjectorTest.java
index 151114e..0db4eec 100644
--- a/connect/api/src/test/java/org/apache/kafka/connect/data/SchemaProjectorTest.java
+++ b/connect/api/src/test/java/org/apache/kafka/connect/data/SchemaProjectorTest.java
@@ -352,6 +352,17 @@ public class SchemaProjectorTest {
         projected = SchemaProjector.project(Timestamp.SCHEMA, 34567L, Timestamp.SCHEMA);
         assertEquals(34567L, projected);
 
+        java.util.Date date = new java.util.Date();
+
+        projected = SchemaProjector.project(Date.SCHEMA, date, Date.SCHEMA);
+        assertEquals(date, projected);
+
+        projected = SchemaProjector.project(Time.SCHEMA, date, Time.SCHEMA);
+        assertEquals(date, projected);
+
+        projected = SchemaProjector.project(Timestamp.SCHEMA, date, Timestamp.SCHEMA);
+        assertEquals(date, projected);
+
         Schema namedSchema = SchemaBuilder.int32().name("invalidLogicalTypeName").build();
         for (Schema logicalTypeSchema: logicalTypeSchemas) {
             try {


Mime
View raw message