Skip to content

Fix date_bin month bins counting intra-second milliseconds twice - #19265

Closed
DaZuiZui wants to merge 1 commit into
apache:masterfrom
DaZuiZui:fix-date-bin-month-fraction
Closed

DaZuiZui wants to merge 1 commit into
apache:masterfrom
DaZuiZui:fix-date-bin-month-fraction

Conversation

@DaZuiZui

Copy link
Copy Markdown
Contributor

Description

Fixes #19264.

date_bin and date_bin_gapfill with a month or year interval shifted a bin boundary later by the whole milliseconds already present inside that second. date_bin(1mo, time, 500) returned 1000 instead of 500.

DateBinFunctionColumnTransformer.convertToTimestamp added toEpochMilli() and the full getNano(). toEpochMilli() already contains the whole milliseconds of that second, and getNano() is the nanosecond-of-second, so those milliseconds were counted twice. The method now encodes the Instant from getEpochSecond() and getNano().

The method is private. Its three callers (dateBin, dateBinStartEnd, and the month step of date_bin_gapfill) share it, so the query result and the gap-fill step stay on the same boundary. Hour and day bins use integer arithmetic and are unchanged. A month bin that lands on an exact second is unchanged because the nanosecond-of-second is 0.


This PR has:

  • been self-reviewed.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage.

Key changed/added classes (or packages if there are too many classes) in this PR
  • DateBinFunctionColumnTransformer
  • DateBinFunctionTest

convertToTimestamp added toEpochMilli() and the full nanosecond-of-second, so a month or year bin boundary that is not an exact second was shifted by those milliseconds. Encode the Instant from its epoch second and nanosecond-of-second instead. Hour and day bins are unchanged.

Fixes apache#19264.

Signed-off-by: DaZuiZui <y51288033@outlook.com>
@DaZuiZui DaZuiZui closed this Nov 13, 2026
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] date_bin month bins add the origin's intra-second milliseconds twice

1 participant