Support date-and-time string literals in IN for Date columns - #111011
Open
Onyx2406 wants to merge 1 commit into
Open
Support date-and-time string literals in IN for Date columns#111011Onyx2406 wants to merge 1 commit into
Onyx2406 wants to merge 1 commit into
Conversation
A follow-up to ClickHouse#111000, which made comparison operators support comparing `Date`/`Date32` with a string containing a date and time, e.g. `d = '2026-01-01 00:00:00'`. The `IN` operator still threw `TYPE_MISMATCH` for `d IN ('2026-01-01 00:00:00')`. Now such a string element of an `IN` set is parsed as `DateTime64` with the scale 6, consistently with comparison operators, and it is kept in the set only if it is exactly the midnight of a date representable in the column type. Any other value (e.g. `'2026-01-01 12:00:00'`) cannot be equal to any value of a `Date`/`Date32` column, so it is excluded from the set, like other values that do not represent any possible value of the type of the filtered column. Strings that are parsable neither as a date nor as a date with a time still throw.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #111000
d IN ('2026-01-01 00:00:00')on aDatecolumn threwTYPE_MISMATCH, while the equivalent comparisond = '2026-01-01 00:00:00'works with #111000. This PR extends the same semantics toIN/NOT INset building. Best merged after #111000 (independent code, but the two together make string handling consistent across=andIN).Mechanism
All literal
INsets funnel through one conversion point (convertFieldToTypeCheckEnuminsrc/Analyzer/SetUtils.cpp, used by the analyzer, the planner and the legacy path). SinceINis pure equality, "compare through theDateTime64supertype" is exactly equivalent to: keep a string element iff it parses asDateTime64(6)and is the exact midnight of a day representable in the column type; otherwise the element can never equal anyDatevalue and is excluded from the set (the same principle the strict-INmachinery already applies to non-representable numeric literals). The set staysDate-typed, so index analysis and set indexes work unchanged. Unparsable strings throw the same errors as before.toDate('2026-01-01') IN ('2026-01-01 00:00:00')→ 1,IN ('2026-01-01 12:00:00')→ 0,NOT INaccordingly.Disclosed asymmetries (pre-existing, deliberately out of scope)
DateTimeelements truncate-match on master:d IN (toDateTime('... 12:00:00'))returns 1 (DateTime→Date truncation inconvertFieldToType), contradicting bothd = toDateTime('... 12:00:00')(0) and — after this PR — the string spelling (0). Changing that would alter long-standing behavior of typed elements and deserves its own discussion.INliterals), while=honors the session'sdate_time_input_formatafter Respect format settings when parsing query parameter values #110985/Support comparing Date with a String containing a date and time #111000 — a value parsable only withbest_effortstill throws inIN.tuple(d) IN (('...',))takes the generic tuple conversion and still throws — same structural gap that already exists for enum literals in tuples.INagainst aDateset is likewise untouched.Verified by code-path analysis plus the stateless test
04627_date_in_datetime_strings(midnight/noon, fractional seconds,NOT IN,Date32incl. pre-epoch, out-of-range dates, mixed lists,Nullable, MergeTree key filtering, unchanged error cases; session timezone pinned); no local build was run, so correctness relies on CI.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
INwith string literals containing a date and time now works forDateandDate32columns, consistent with the comparison operators.