-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Closed
Description
- 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 v1.1.5
- mysql version 5.7.23
Issue Description
MySQL字段类型为TIME时,写入值-00:00:00.12,canal解析出来的值变成了正数00:00:00.12。只有当时分秒都为0,并且毫秒值为负数时才会触发该问题。
看了下代码,应该是RowsLogBuffer解析的bug,第735行,判断正数部分为0后生成时间前缀"00:00:00",感觉应该同时判断下毫秒值,毫秒为负数时前缀需要加上负号:
String second = null;
if (intpart == 0) {
second = frac < 0 ? "-00:00:00" : "00:00:00";
} else {
原代码如下:
String second = null;
if (intpart == 0) {
second = "00:00:00";
} else {
Steps to reproduce
建表语句如下:
CREATE DATABASE if not exists canal;
CREATE TABLE `canal`.`time2` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`start_time` TIME(2) NOT NULL COMMENT '时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='time2测试表';
执行如下SQL写入数据:
insert into canal.time2(start_time) value('-00:00:00.12');
Expected behaviour
canal可以正确解析出start_time负数字段值-00:00:00.12
Actual behaviour
实际上canal解析出来的start_time字段值变成了正数00:00:00.12,负号丢掉了