Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL TIME类型字段,值为负数-00:00:00.12时解析的值错误,解析为正数00:00:00.12,负号丢掉了 #4178

Closed
2 tasks done
clanmaps opened this issue May 19, 2022 · 1 comment
Labels
Milestone

Comments

@clanmaps
Copy link

  • 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,负号丢掉了

@agapple
Copy link
Member

agapple commented May 19, 2022

验证可修复

agapple added a commit that referenced this issue May 20, 2022
@agapple agapple added the bug label May 20, 2022
@agapple agapple added this to the v1.1.6 milestone May 20, 2022
@agapple agapple closed this as completed May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants