[FLINK-39748][postgres] Fix snapshot timestamp drift for historical TIMESTAMP/DATE columns#4412
Open
JNSimba wants to merge 2 commits into
Open
[FLINK-39748][postgres] Fix snapshot timestamp drift for historical TIMESTAMP/DATE columns#4412JNSimba wants to merge 2 commits into
JNSimba wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This closes FLINK-39748.
The Postgres CDC snapshot path reads column values via a bare
rs.getObject(i + 1)inPostgresScanFetchTask. For TIMESTAMP / TIMESTAMPTZ / DATE columns, the PG JDBC driver constructs the returnedjava.sql.Timestamp/java.sql.DatethroughGregorianCalendar(default Julian/Gregorian cutover at 1582-10-15) using the JVM default time zone. This makes pre-cutover dates drift by N days (e.g.0001-01-01by 2 days), and also adds an LMT delta on JVMs whose default zone has an LMT segment (e.g.Asia/Shanghaiis+08:05:43until 1901, vs+08:00:00after).The Postgres logical decoding (streaming) path does not pass through
GregorianCalendar, so the same row produces different Debezium records on snapshot vs streaming, breaking idempotent UPSERT semantics for downstream sinks.This patch:
Routes the snapshot path through
PostgresConnection.getColumnValue, which already does per-type dispatch forMONEY/BIT/NUMERIC/TIME/TIMETZ, by replacing the barers.getObject(i + 1)inPostgresScanFetchTask.createDataEventsForTablewithjdbcConnection.getColumnValue(rs, i + 1, column, table, databaseSchema). This mirrors how Debezium's ownRelationalSnapshotChangeEventSourcereads rows.Extends the switch in
PostgresConnection.getColumnValuewith three new cases forPgOid.TIMESTAMP/TIMESTAMPTZ/DATE, reading the columns asjava.time.LocalDateTime/OffsetDateTime/LocalDateviars.getObject(columnIndex, ...class). This bypassesGregorianCalendar. PG+/-infinitysentinels are preserved asTimestamp(Long.MAX/MIN_VALUE)to keep the existing downstream contract.A regression test in
PostgresScanFetchTaskTestsnapshots boundary dates (0001-01-01,1582-10-04,1582-10-15,1900-12-31,1901-01-02, and a microsecond-precision value) for TIMESTAMP and DATE columns and asserts the produced Debezium record values match the proleptic-UTC expectation.