Skip to content

fix: preserve microsecond precision for Avro timestamp-micros in JDBC… - #119

Merged
orfeon merged 1 commit into
mercari:mainfrom
kratos0718:fix/timestamp-micros-precision-jdbc
Aug 5, 2026
Merged

orfeon merged 1 commit into
mercari:mainfrom
kratos0718:fix/timestamp-micros-precision-jdbc

Conversation

@kratos0718

Copy link
Copy Markdown
Contributor

… statements

ToStatementConverter converted timestamp-micros with Instant.ofEpochMilli(micros / 1000). The integer division discarded the sub-millisecond digits, so distinct timestamps collapsed onto the same value once bound to a PreparedStatement:

2026-07-30T12:48:16.123456Z -> 2026-07-30T12:48:16.123Z
2026-07-30T12:48:16.123789Z -> 2026-07-30T12:48:16.123Z

java.sql.Timestamp carries nanosecond precision, so build the Instant from microseconds directly with Instant.EPOCH.plus(micros, MICROS). That also fixes pre-1970 values, where integer division truncated toward zero and rounded the wrong way.

Other call sites that divide micros by 1000 target org.joda.time.Instant, which is millisecond-resolution by design, so they are left unchanged.

Fixes #118

Please read the CLA carefully before submitting your contribution to Mercari.
Under any circumstances, by submitting your contribution, you are deemed to accept and agree to be bound by the terms and conditions of the CLA.

https://www.mercari.com/cla/

… statements

ToStatementConverter converted timestamp-micros with
Instant.ofEpochMilli(micros / 1000). The integer division discarded the
sub-millisecond digits, so distinct timestamps collapsed onto the same
value once bound to a PreparedStatement:

  2026-07-30T12:48:16.123456Z -> 2026-07-30T12:48:16.123Z
  2026-07-30T12:48:16.123789Z -> 2026-07-30T12:48:16.123Z

java.sql.Timestamp carries nanosecond precision, so build the Instant
from microseconds directly with Instant.EPOCH.plus(micros, MICROS).
That also fixes pre-1970 values, where integer division truncated
toward zero and rounded the wrong way.

Other call sites that divide micros by 1000 target org.joda.time.Instant,
which is millisecond-resolution by design, so they are left unchanged.

Fixes mercari#118

@orfeon orfeon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for your contribution!

@orfeon
orfeon merged commit 55024ac into mercari:main Aug 5, 2026
1 check passed
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.

[Bug] Avro timestamp-micros loses microsecond precision when converted to JDBC Timestamp

2 participants