Flink CDC 读取MySQL Decimal类型字符串处理

原表

MySqlSource

MySqlSource.<String>builder()
                    .hostname(hostname)
                    .port(port)
                    .databaseList(database)
                    .tableList(tableList)
                    .username(username)
                    .password(password)
                    .deserializer(new JsonDebeziumDeserializationSchema())
                    .startupOptions(startupOptions)
                    .connectionPoolSize(connectionPoolSize)
                    .fetchSize(fetchSize)
                    .splitSize(splitSize)
                    .build();

 读取到的数据

{
    "before": null, 
    "after": {
        "id": "eqp001", 
        "eqp_decimal": "BfY=", 
        "eqp_int": 45, 
        "eqp_datetime": 1687996800000, 
        "eqp_filter": "aaa"
    }, 
    "source": {
        "version": "1.6.4.Final", 
        "connector": "mysql", 
        "name": "mysql_binlog_source", 
        "ts_ms": 0, 
        "snapshot": "false", 
        "db": "develop", 
        "sequence": null, 
        "table": "equipment", 
        "server_id": 0, 
        "gtid": null, 
        "file": "", 
        "pos": 0, 
        "row": 0, 
        "thread": null, 
        "query": null
    }, 
    "op": "r", 
    "ts_ms": 1688351819480, 
    "transaction": null
}

 修改MySqlSource的反序列化

Map<String, Object> configs = new HashMap<>();
//转换decimal类型
configs.put(JsonConverterConfig.DECIMAL_FORMAT_CONFIG, DecimalFormat.NUMERIC.name());

MySqlSource.<String>builder()
                    .hostname(hostname)
                    .port(port)
                    .databaseList(database)
                    .tableList(tableList)
                    .username(username)
                    .password(password)
                    .deserializer(new JsonDebeziumDeserializationSchema(false,configs))
                    .startupOptions(startupOptions)
                    .connectionPoolSize(connectionPoolSize)
                    .fetchSize(fetchSize)
                    .splitSize(splitSize)
                    .build();

新读取到的数据 

{
    "before": null, 
    "after": {
        "id": "eqp001", 
        "eqp_decimal": 15.26, 
        "eqp_int": 45, 
        "eqp_datetime": 1687996800000, 
        "eqp_filter": "aaa"
    }, 
    "source": {
        "version": "1.6.4.Final", 
        "connector": "mysql", 
        "name": "mysql_binlog_source", 
        "ts_ms": 0, 
        "snapshot": "false", 
        "db": "develop", 
        "sequence": null, 
        "table": "equipment", 
        "server_id": 0, 
        "gtid": null, 
        "file": "", 
        "pos": 0, 
        "row": 0, 
        "thread": null, 
        "query": null
    }, 
    "op": "r", 
    "ts_ms": 1688352094669, 
    "transaction": null
}
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值