flink cdc 中 tiny(1) 变 Boolean 了怎么办?添加一行即可。
在使用 flink cdc 3.4 时,发现在 mysql 中的 tinyint(1) 会在 cdc 时改为 Boolean 。因为在 mysql 中, tinyint(1) 并不一定指代 Boolean , 其中有可能会有除 0/1外的其他值。所以默认情况下这种转换并不一定合适。
在其项目源文件 /flink-cdc/flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-mysql/src/main/java/org/apache/flink/cdc/connectors/mysql/utils/MySqlTypeUtils.java 中第 139 行附近也指出了。
case TINYINT:
// MySQL haven't boolean type, it uses tinyint(1) to represents boolean type
// user should not use tinyint(1) to store number although jdbc url parameter
// tinyInt1isBit=false can help change the return value, it's not a general way
// btw: mybatis and mysql-connector-java map tinyint(1) to boolean by default
return (column.length() == 1 && tinyInt1isBit)
? DataTypes.BOOLEAN()
: DataTypes.TINYINT();
所以,需要进行指定不让 cdc 将其转换为 Boolean ,比如:
################################################################################
# Description: Sync MySQL all tables to Doris
################################################################################
source:
type: mysql
hostname: localhost
port: 3306
username: root
password: 123456
tables: app_db.\.*
server-id: 5400-5404
server-time-zone: Asia/Shanghai
treat-tinyint1-as-boolean.enabled: false
sink:
type: doris
fenodes: 127.0.0.1:8030
username: root
password: ""
table.create.properties.light_schema_change: true
table.create.properties.replication_num: 1
pipeline:
name: Sync MySQL Database to Doris
parallelism: 2
注意其中的 treat-tinyint1-as-boolean.enabled: false 行,如此,提交任务后,得到的最终目标库中,tinyint(1) 仍然是 tinyint(1) 。
另一个可行但改动稍大的方案是将 tinyint(1) 变长,比如变成 tinyint(3) 这样的话就避开了这种转换,但是需要修改原始 mysql 表结构。
综合起来,还是加一行来得简便些。
- 原想把
treat-tinyint1-as-boolean.enabled: false直接写在标题中,奈何标题不能超过 60 个字。
本作品采用《CC 协议》,转载必须注明作者和本文链接
关于 LearnKu