tidb-incubator / TiBigData

TiDB connectors for Flink/Hive/Presto
Apache License 2.0
214 stars 56 forks source link

[BUG] TiDBCanalJsonDeserializationSchema无法解析含有大写字母的字段 #250

Closed heroWang closed 1 year ago

heroWang commented 1 year ago

Describe the bug

image

TiDBCatalog 从 tidb 加载schema 时, 对db, table, column 全部进行了 lowercase 处理 . 这在全量同步阶段没有问题. 但是在增量阶段以 TiDBCanalJsonDeserializationSchema为例, 从kafka 读取 ticdc 生成的数据时,由于 physicalDataType 中的字段名称都是小写的, data 中的字段名称是原始名称. 导致 JsonNode 根据lowercase字段名无法匹配到字段值

image

最后 emit 出去的 RowData. 含有大写字母的字段值都为 null.

What did you do 定义一张有大写字母字段的tidb表

tableEnv.sqlQuery("select XXX from test.test_table")

上面的 代码会报错: Column XXX not found in any table. did you mean xxx? 要求必须使用小写字母. 修改 sql 避免报错后. 全量取值正常. 增量取值则为空.

What do you expect 全量取值正常. 增量取值也正常.

What happens instead Screenshots

Flink/Presto/MapReduce/Trino/Hive and TiBigData version info Flink1.13.6

Additional context

heroWang commented 1 year ago

我的临时处理方案是在. JsonNode 解析为 RowData 之前, 把 JsonNode 中的 data 和 old 做 lowercase 处理. 但这样会影响性能, 期待有更好的处理方法.

//对 root.data 中的所有字段lowercase处理.
      dataToLowerCase(root.get("data"));
//对 root.old 中的所有字段lowercase处理.
      dataToLowerCase(root.get("old"));

如果我忽略了什么配置项. 也请指出. 谢谢.

xuanyu66 commented 1 year ago

The column name in TiDB is case-insensitive.

humengyu2012 commented 1 year ago

We use TiDB native client to get columns which will return us a TiTableInfo object, and the column names in TiTableInfo is lowercase. That's why we need to convert the column name to lowercase. If we use mysql driver to get columns names, we can get original column names rather than lowercase. We need some time to think about how to fix it.