Skip to content

fix(clickhouse): use parseDateTime64BestEffort to preserve millisecond precision#10533

Open
majiayu000 wants to merge 2 commits intocube-js:masterfrom
majiayu000:fix/issue-10326-clickhouse-millisecond-precision
Open

fix(clickhouse): use parseDateTime64BestEffort to preserve millisecond precision#10533
majiayu000 wants to merge 2 commits intocube-js:masterfrom
majiayu000:fix/issue-10326-clickhouse-millisecond-precision

Conversation

@majiayu000
Copy link
Copy Markdown

Check List

  • Tests have been run in packages where changes have been made if available
  • Linter has been run for changed code
  • Tests for the changes have been added if not covered yet
  • Docs have been added / updated if required

Issue Reference this PR resolves

Fixes #10326

Description of Changes Made

Replace all occurrences of parseDateTimeBestEffort with parseDateTime64BestEffort(…, 3) in ClickHouseQuery.ts to preserve millisecond precision in pre-aggregation WHERE clauses and time series queries.

parseDateTimeBestEffort returns DateTime (second precision), which silently truncates milliseconds from timestamps like 2024-01-01T00:00:00.000. parseDateTime64BestEffort is a drop-in replacement that returns DateTime64 with configurable sub-second precision. Precision 3 = milliseconds, consistent with the timezone-aware branch that already uses toDateTime64(..., 3).

Changes:

  1. dateTimeCast() — primary fix for the reported issue. WHERE clause timestamp casts now preserve milliseconds.
  2. seriesSql() — time series date_from/date_to parsing also updated for consistency.
  3. sqlTemplates() — Tesseract timestamp_literal and time_series_select templates updated.
  4. Updated stale comments referencing the old function name.
  5. Added unit test for dateTimeCast() verifying the output contains parseDateTime64BestEffort.

User-defined SQL in FILTER_PARAMS (e.g., in test fixtures) is intentionally left unchanged.

…d precision

Replace parseDateTimeBestEffort with parseDateTime64BestEffort(value, 3)
in ClickHouseQuery to prevent silent truncation of milliseconds in
pre-aggregation WHERE clauses, time series queries, and Tesseract
timestamp literals.

Fixes cube-js#10326

Signed-off-by: majiayu000 <1835304752@qq.com>
…Cast

Update 3 comments that still referenced parseDateTimeBestEffort after
the function was replaced with parseDateTime64BestEffort. Add unit
test for dateTimeCast() to verify both timezone and non-timezone paths
use DateTime64 with precision 3.

Signed-off-by: majiayu000 <1835304752@qq.com>
@github-actions github-actions bot added javascript Pull requests that update Javascript code pr:community Contribution from Cube.js community members. labels Mar 21, 2026
@majiayu000 majiayu000 marked this pull request as ready for review March 21, 2026 13:43
@majiayu000 majiayu000 requested a review from a team as a code owner March 21, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

javascript Pull requests that update Javascript code pr:community Contribution from Cube.js community members.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ClickHouse pre-aggregation WHERE clause loses millisecond precision

1 participant