Skip to content

Fix DateTime64 literals in distributed filter pushdown - #108425

Closed
cv4g wants to merge 1 commit into
masterfrom
fix-datetime64-distributed-filter-pushdown
Closed

cv4g wants to merge 1 commit into
masterfrom
fix-datetime64-distributed-filter-pushdown

Conversation

@cv4g

@cv4g cv4g commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #94612

Fix rebuilding pushed-down distributed filters with DateTime64 constants. tryBuildAdditionalFilterAST previously created ASTLiteral from the raw column field, so fromUnixTimestamp64Milli(0, 'UTC') was sent to shards as _CAST('0', 'DateTime64(3, \'UTC\')'), which raises CANNOT_PARSE_DATETIME.

The change uses the same typed-literal conversion as analyzer constants and adds a stateless regression test.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed distributed predicate pushdown for filters with DateTime64 constants, which could previously fail with CANNOT_PARSE_DATETIME.

Documentation entry for user-facing changes

  • Documentation is not required.

`tryBuildAdditionalFilterAST` rebuilt constants from `ActionsDAG` with
`IColumn::getField`, so `fromUnixTimestamp64Milli(0, 'UTC')` was pushed to
remote shards as `_CAST('0', 'DateTime64(3, \'UTC\')')`. The shard then failed
with `CANNOT_PARSE_DATETIME`.

Use `getFieldFromColumnForASTLiteral` to serialize typed literals before
wrapping them in `_CAST`, matching analyzer constant conversion.

Closes: #94612
@clickhouse-gh

clickhouse-gh Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d522c9d]

Summary: ❌

job_name test_name status info comment
Fast test FAIL
04340_datetime64_distributed_filter_pushdown FAIL cidb
Fast test (arm_darwin) DROPPED
Build (amd_debug) DROPPED
Build (amd_asan_ubsan) DROPPED
Build (amd_tsan) DROPPED
Build (amd_msan) DROPPED
Build (amd_binary) DROPPED
Build (arm_debug) DROPPED
Build (arm_asan_ubsan) DROPPED
Build (arm_tsan) DROPPED

AI Review

Summary
  • The PR fixes distributed predicate pushdown for DateTime64 constants by rebuilding pushed-down filter literals with getFieldFromColumnForASTLiteral before wrapping them in _CAST, matching analyzer constant conversion. The added stateless regression covers the linked CANNOT_PARSE_DATETIME failure shape. I found no unresolved correctness, compatibility, or safety issues in the current diff.
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 24, 2026
@scanhex12 scanhex12 self-assigned this Jun 25, 2026
@@ -0,0 +1,44 @@
-- Tags: no-parallel-replicas

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.

Why do we need this tag?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes distributed predicate pushdown when rebuilding additional filters that contain DateTime64 constants, preventing shard-side exceptions like CANNOT_PARSE_DATETIME caused by incorrectly reconstructed literals.

Changes:

  • Rebuild constant filter literals using getFieldFromColumnForASTLiteral so Date/DateTime/DateTime64 values are encoded as typed text literals before _CAST.
  • Add a stateless regression test covering DateTime64(3, 'UTC') filter pushdown through remote(...).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/Processors/QueryPlan/ReadFromRemote.cpp Uses typed literal extraction when converting ActionsDAG constants back into AST for pushed-down remote filters.
tests/queries/0_stateless/04340_datetime64_distributed_filter_pushdown.sql Adds a stateless query reproducer to ensure DateTime64 constants don’t break distributed filter pushdown.
tests/queries/0_stateless/04340_datetime64_distributed_filter_pushdown.reference Adds expected output for the new stateless regression test.

@yakov-olkhovskiy

Copy link
Copy Markdown
Member

I ran this solution against test suite in the (freshly updated) #95055, results:

Cases PR #108425 handles correctly

Case Path Why it works here
#94612 DateTime64(3) epoch fromUnixTimestamp64Milli(0,'UTC') (GROUP BY + pushdown) both date-time text parses fine (the PR's target)
Scalar Decimal64(5) high-scale ConstantNode master quotes decimals -> _CAST('123...567','Decimal64(5)') exact
DateTime64(9) UTC high-precision ConstantNode + pushdown 9-digit subsecond text round-trips exactly in UTC
Decimal64(5) pushdown boundary pushdown quoted-decimal text exact
Array/Tuple/Map of Decimal ConstantNode nested decimals quoted exactly
OR-to-IN high-scale Decimal ConstantNode (IN set) quoted-decimal text exact

Cases PR #108425 misses

Case Path #108425 result #95055 result
DateTime64(9,'Europe/Berlin') DST overlap ConstantNode THERE_IS_NO_COLUMN (1698543000 vs 1698539400 across shards) exact
DateTime64(9,'Europe/Berlin') DST overlap pushdown empty result (shard matches wrong instant) exact
DateTime('Europe/Berlin') DST overlap pushdown empty result exact (raw numeric literal)
Time64(9) scalar ConstantNode CANNOT_PARSE_TEXT (_CAST('999999999.123456789','Time64(9)')) exact
Variant(Time64(9)) ConstantNode CANNOT_CONVERT_TYPE (Decimal carrier not a Variant member) exact, type preserved
Dynamic(Time64) ConstantNode dynamicType -> Decimal(18,9)/String, not Time64(9) Time64(9)
Dynamic(Decimal) ConstantNode dynamicType diverges Decimal vs String across shards Decimal(18,5)
Dynamic(max_types=0) Decimal ConstantNode dynamicType diverges Decimal vs String Decimal(18,5)
JSON(a DateTime64(9,'Europe/Berlin')) DST ConstantNode/Object wrong instant 1698539400000000000 1698543000000000000

I would recommend to close this PR in favor of #95055
thanks @cv4g for pointing in right direction to solve this issue

@clickhouse-gh

clickhouse-gh Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Dear @scanhex12, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@cv4g cv4g closed this Aug 30, 2026
@cv4g
cv4g deleted the fix-datetime64-distributed-filter-pushdown branch August 30, 2026 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filter pushdown for distributed table with datetime

4 participants