[ 
https://issues.apache.org/jira/browse/KAFKA-8713?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17044972#comment-17044972
 ] 

Randall Hauch commented on KAFKA-8713:
--------------------------------------

[~pan3793], I agree that the current behavior is incorrect. But correcting this 
would change behavior, and we'll have to worry about how this affects existing 
users that upgrade to a version where this might get fixed. And AK's policy is 
that such changes require a KIP to identify all potential compatibility 
concerns. For example, we should consider whether we need to introduce a 
configuration property on the JSON converter that enables/disables this 
behavior so that existing users don't see any changes unless they want to 
enable it.

> [Connect] JsonConverter NULL Values are replaced by default values even in 
> NULLABLE fields
> ------------------------------------------------------------------------------------------
>
>                 Key: KAFKA-8713
>                 URL: https://issues.apache.org/jira/browse/KAFKA-8713
>             Project: Kafka
>          Issue Type: Bug
>          Components: KafkaConnect
>    Affects Versions: 2.0.0, 2.0.1, 2.1.0, 2.2.0, 2.3.0, 2.2.1
>            Reporter: Cheng Pan
>            Priority: Major
>
> Class JsonConverter line: 582
> {code:java}
>     private static JsonNode convertToJson(Schema schema, Object logicalValue) 
> {
>         if (logicalValue == null) {
>             if (schema == null) // Any schema is valid and we don't have a 
> default, so treat this as an optional schema
>                 return null;
>             if (schema.defaultValue() != null)
>                 return convertToJson(schema, schema.defaultValue());
>             if (schema.isOptional())
>                 return JsonNodeFactory.instance.nullNode();
>             throw new DataException("Conversion error: null value for field 
> that is required and has no default value");
>         }
>         ....
>     }
> {code}
> h1.Expect:
> Value `null` is valid for an optional filed, even though the filed has a 
> default value.
>  Only when field is required, the converter return default value fallback 
> when value is `null`.
> h1.Actual:
> Always return default value if `null` was given.
> h1. Example:
> I'm not sure if the current behavior is the exactly expected, but at least on 
> MySQL, a table  define as 
> {code:sql}
> create table t1 {
>    name varchar(40) not null,
>    create_time datetime default '1999-01-01 11:11:11' null,
>    update_time datetime default '1999-01-01 11:11:11' null
> }
> {code}
> Just insert a record:
> {code:sql}
> INSERT INTO `t1` (`name`,  `update_time`) VALUES ('kafka', null);
> {code}
> The result is:
> {code:json}
> {
>     "name": "kafka",
>     "create_time": "1999-01-01 11:11:11",
>     "update_time": null
> }
> {code}
> But when I use debezium pull binlog and send the record to Kafka with 
> JsonConverter, the result changed to:
> {code:json}
> {
>     "name": "kafka",
>     "create_time": "1999-01-01 11:11:11",
>     "update_time": "1999-01-01 11:11:11"
> }
> {code}
> For more details, see: https://issues.jboss.org/browse/DBZ-1064



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to