Skip to content

Fix Debezium logical converter for date to cover historical dates#469

Open
Navid Hassanzadeh (navidhsz) wants to merge 2 commits into
confluentinc:masterfrom
navidhsz:master
Open

Fix Debezium logical converter for date to cover historical dates#469
Navid Hassanzadeh (navidhsz) wants to merge 2 commits into
confluentinc:masterfrom
navidhsz:master

Conversation

@navidhsz
Copy link
Copy Markdown

By default, Postgres Debezium uses adaptive mode for handling date fields. In this mode, any date type is encoded as an Int32 representing the number of days since the Unix epoch. Dates before the epoch are represented as negative numbers. When Debezium sends an integer-encoded date, the BigQuery connector converts it to a string representation. However, this conversion can fail for certain historical dates before 1582, when the calendar changed from Julian to Gregorian. For example, the date 1500-03-10 is encoded as -171596, but BigQuery converts it to 1500-02-29, which is not a valid date, causing BigQuery to reject the record and send it to the DLQ (if configured). Another example is1582-10-01, which is encoded as -141441 by Debezium but shown as 1582-09-21 by the BigQuery connector.

@navidhsz Navid Hassanzadeh (navidhsz) requested a review from a team as a code owner October 28, 2025 14:16
Copilot AI review requested due to automatic review settings October 28, 2025 14:16
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug in the Debezium date conversion logic that caused historical dates (particularly those before 1582) to be incorrectly converted when handling Postgres Debezium date fields. The issue stemmed from using java.util.Date for conversion, which doesn't handle dates before the Gregorian calendar adoption correctly. The fix switches to using Java's LocalDate API for accurate date arithmetic across all calendar periods.

Key changes:

  • Replaced java.util.Date-based date conversion with LocalDate-based conversion in DateConverter
  • Added comprehensive parameterized tests covering historical dates from year 100 through the Gregorian calendar transition period

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
DebeziumLogicalConverters.java Replaced legacy date conversion using java.util.Date with LocalDate API to correctly handle historical dates before 1582
DebeziumLogicalConvertersTest.java Added parameterized tests covering edge cases including leap years and the Julian-to-Gregorian calendar transition period

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…convert/logicaltype/DebeziumLogicalConverters.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants