Skip to content

AVRO-4269: [Java] Fix timestamp-nanos conversion before epoch#3813

Merged
nandorKollar merged 1 commit into
apache:mainfrom
emarussoo:AVRO-4269-fix-timestamp-nanos-before-epoch
Jun 18, 2026
Merged

AVRO-4269: [Java] Fix timestamp-nanos conversion before epoch#3813
nandorKollar merged 1 commit into
apache:mainfrom
emarussoo:AVRO-4269-fix-timestamp-nanos-before-epoch

Conversation

@emarussoo

Copy link
Copy Markdown
Contributor

What is the purpose of the change

Fixes TimestampNanosConversion.toLong for Instant values before the Unix epoch with a positive nanosecond component.
The affected code path handles cases where seconds < 0 and nanos > 0. In that branch, the implementation needs to adjust the positive nanosecond component relative to the previous epoch second.
The previous implementation subtracted 1_000_000, which is a microsecond-scale constant. Since this conversion handles the timestamp-nanos logical type, the adjustment must subtract 1_000_000_000L, the number of nanoseconds in one second.
For example, 1969-12-31T23:59:59.999999999Z is one nanosecond before the Unix epoch and should convert to -1L. Before this fix, it converted to 998999999L.
This PR updates the adjustment constant and adds a regression test for the affected pre-epoch nanos case.
Fixes: AVRO-4269

Verifying this change

This change adds a regression test for timestamp-nanos conversion before the epoch.

This change added tests and can be verified as follows:

  • mvn -Dtest=TestTimeConversions#timestampNanosConversionBeforeEpochWithPositiveNanos test
  • mvn -Dtest=TestTimeConversions test

Documentation

  • Does this pull request introduce a new feature? no
  • If yes, how is the feature documented? not applicable

@github-actions github-actions Bot added the Java Pull Requests for Java binding label Jun 7, 2026
@emarussoo

Copy link
Copy Markdown
Contributor Author

Hi everyone! No rush on the review, but whenever someone has a spare moment, could you please approve the workflows for this PR? Since I am a new contributor, the CI workflows need manual approval to run. It fixed the major issue reported in AVRO-4269. Thanks for your time!

@emarussoo

Copy link
Copy Markdown
Contributor Author

Hi @nandorKollar, thank you for taking the time to review my contributions for AVRO-4269. Please let me know if there are any further adjustments or actions required from my side to proceed with the merge. Thanks again for your time!

@nandorKollar nandorKollar merged commit 912ab25 into apache:main Jun 18, 2026
9 checks passed
@nandorKollar

Copy link
Copy Markdown
Contributor

Merged to master, thanks @emarussoo for the fix.

@RyanSkraba

Copy link
Copy Markdown
Contributor

Cherry-picked to branch-1.12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Java Pull Requests for Java binding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants