Skip to content

[client-v2] Fix reading negative Time64 values with fractional seconds - #3456

Open
shafiktanbir wants to merge 1 commit into
ClickHouse:mainfrom
shafiktanbir:fix/client-v2-time64-negative-fraction
Open

shafiktanbir wants to merge 1 commit into
ClickHouse:mainfrom
shafiktanbir:fix/client-v2-time64-negative-fraction

Conversation

@shafiktanbir

@shafiktanbir shafiktanbir commented Nov 27, 2026 •

Copy link
Copy Markdown

Summary

DataTypeUtils.localTimeFromTime64Integer previously took Math.abs(value % factor) and truncated value / factor toward zero. For negative Time64 values with a non-zero fractional part, LocalDateTime.ofEpochSecond(seconds, nanoOfSecond, UTC) added the positive nanosecond offset to the truncated seconds, shifting the decoded value forward (for example, -01:02:03.456 became -01:02:02.544).

This change applies floor division when value % factor < 0, matching DataTypeUtils.instantFromTime64Integer. It also removes the resolved ReaderKnownIssues entry and updates the negative Time64 expectations in DataTypeTests and JdbcDataTypeTests.

Compatibility impact: No public API signatures or return types change. Callers reading negative Time64 values with fractional seconds via getDuration, getTemporalAmount, getLocalDateTime, getInstant, or JDBC getObject(..., LocalDateTime.class) now receive the exact negative value instead of a value shifted by up to two seconds. Zero and positive Time64 values, and negative values with a zero fraction, are unchanged.

Local verification:

  • TZ=UTC mvn -pl client-v2 -Dgroups=unit -DargLine="-Duser.timezone=UTC" test (496 tests run, 0 failures)
  • mvn -Dj8 -pl client-v2,jdbc-v2 -am -DskipTests test-compile (Java 8 compile check passed across all 6 reactor modules)

Closes #3419

Checklist


Note

Medium Risk
Behavior change for negative Time64 with sub-second parts affects client and JDBC temporal accessors; positive/zero paths are intended unchanged but callers may see different decoded values where the bug was present.

Overview
Fixes DataTypeUtils.localTimeFromTime64Integer so negative Time64 values with a fractional part decode correctly. The old path used Math.abs on the remainder and truncated seconds toward zero, which could shift decoded times by up to a couple of seconds (for example -01:02:03.456 landing around -01:02:02.544). localTimeFromTime64Integer now uses the same floor-style split as instantFromTime64Integer: when the remainder is negative, it normalizes nanoseconds and borrows one second.

Downstream readers (getDuration, getLocalDateTime, getInstant, JDBC LocalDateTime) pick up the fix without API changes. Tests and integration expectations for negative Time64 are updated, the resolved ReaderKnownIssues entry is removed, and a changelog note is added for #3419.

Reviewed by Cursor Bugbot for commit ffcb44e. Bugbot is set up for automated code reviews on this repo. Configure here.

@shafiktanbir
shafiktanbir requested review from a team and mzitnik as code owners November 27, 2026 11:52
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.

client-v2: a negative Time64 value with a fraction is read as a wrong value (-01:02:03.456 becomes -01:02:02.544)

1 participant