debezium-timestamp-converter icon indicating copy to clipboard operation
debezium-timestamp-converter copied to clipboard

Handle zeroed out time when seconds are :00

Open nadflinn opened this issue 1 year ago • 0 comments

It looks like the datetime type for MySQL does not return the correct value when the seconds part of the datetime is :00. For example, the datetime 2023-04-15T12:34:00 in MySQL will end up as 2023-04-15T00:00:00 after being processed by this converter.

I have narrowed this behavior down to the fact that a Java LocalDateTime object is passed to the converter here for datetime: https://github.com/debezium/debezium/blob/main/debezium-connector-mysql/src/main/java/io/debezium/connector/mysql/RowDeserializers.java#L406

The issue is that when the seconds parameter is :00 the string that is returned omits the seconds piece.

So if you run something like:

import java.time.LocalDateTime;

public class Program
{
    public static void main(String[] args) {
	System.out.println(LocalDateTime.of(2023, 4, 15, 12, 34, 5, 0).toString());
        System.out.println(LocalDateTime.of(2023, 4, 15, 12, 34, 0, 0).toString());
	}
}

You get:

2023-04-15T12:34:05
2023-04-15T12:34

The second example comes back without a seconds portion of the datetime string and this doesn't match the time portion of the existing regex for this converter. This results in the entire time portion being zeroed out to -> 2023-04-15T00:00:00.

The result is that roughly 1 out of 60 timestamps will be wrong (assuming a random distribution of events).

This PR updates the regex to match the time group with just hour and minute portions.

nadflinn avatar Apr 15 '23 21:04 nadflinn