Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON类型"null"值bug #1762

Closed
2 tasks done
oscar-zyh opened this issue Apr 28, 2019 · 3 comments
Closed
2 tasks done

JSON类型"null"值bug #1762

oscar-zyh opened this issue Apr 28, 2019 · 3 comments
Labels

Comments

@oscar-zyh
Copy link

oscar-zyh commented Apr 28, 2019

  • I have searched the issues of this repository and believe that this is not a duplicate.
  • I have checked the FAQ of this repository and believe that this is not a duplicate.

environment

  • canal version 1.1.3
  • mysql version 5.7

Issue Description

canal 把 json 类型字段的 "null" 值转换成了 "NULL" 值,再往 mysql 插入这个字段会报错,json "NULL" 无法解析

MySQL 遵循 RFC 7159 规范使用 JSON
规范里面表明 JSON 的几个 literal 类型必须是小写:

  1. Values
    A JSON value MUST be an object, array, number, or string, or one of
    the following three literal names:
    false null true
    The literal names MUST be lowercase. No other literal names are
    allowed.
    value = false / null / true / object / array / number / string

所以 MySQL 的 json 字段合法值要么是字符串 "null",要么是空值 null/NULL,而字符串 "NULL" 不合法

canal 代码在:https://github.com/alibaba/canal/blob/master/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/JsonConversion.java

case LITERAL_NULL:
    buf.append("NULL");
    break

不知道这里的考虑是怎样的,能否改回 "null" ?

Steps to reproduce

create table t (data json);
insert into t values ('null');
insert into t values ('NULL');
insert into t values (NULL);

If there is an exception, please attach the exception trace:

mysql> insert into t values ('NULL');
ERROR 3140 (22032): Invalid JSON text: "Invalid value." at position 0 in value for column 't.data'.
@agapple
Copy link
Member

agapple commented May 11, 2019

应属于边界值问题, 可以考虑提交一个MR给我

@agapple agapple added the bug label May 11, 2019
ouyanghuangzheng added a commit to ouyanghuangzheng/canal that referenced this issue Jun 23, 2019
@sheiy
Copy link

sheiy commented Jul 4, 2019

啥时候合并?遇到了同样的问题

@agapple
Copy link
Member

agapple commented Aug 21, 2019

#1959

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants