原因 是在读取mysql的数据时候会在底层进行转换成byte数组来传递,但是decimal并没有转换回去,所以在输出时候是AA==这些
解决:
1,使用.debeziumProperties对cdc解析的底层框架decimal.handling.mode属性设置为string即可

  Properties properties = new Properties();
 properties.put("decimal.handling.mode", "string");
        MySqlSource<String> build =
                MySqlSource.<String>builder()
                        .hostname("localhost")
                        .debeziumProperties(properties)
                        .startupOptions(StartupOptions.initial())
                        .serverTimeZone("Asia/Shanghai")
                        .build();

2 注意反序列话类JsonDebeziumDeserializationSchema 点进去后他构造器可以传递一个map
在这里插入图片描述
再点击configure方法进入设置map属性的位置可以看到 JsonConverterConfig
在这里插入图片描述
点击进入JsonConverterConfig
在这里插入图片描述
这里就可以看到了对decimal的format

 Map<String, Object> configs = new HashMap<>();
 //声明decimal转换类型
        configs.put(JsonConverterConfig.DECIMAL_FORMAT_CONFIG, DecimalFormat.NUMERIC.name());
        MySqlSource<String> build =
                MySqlSource.<String>builder()
                       
                        .deserializer(new JsonDebeziumDeserializationSchema(false,configs))
                       .startupOptions(StartupOptions.initial())
                        .serverTimeZone("Asia/Shanghai")
                        .build();

两种方式都可以对decimal类型进行正常转换,建议使用第二种

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐