Repository navigation
Render a typed constant converted to String with its own text serialization - #118372
alexey-milovidov wants to merge 54 commits into
Conversation
…zation
Converting a constant of another type to `String` - which is what building the
set of `IN` against a `String` column does, and what the `values` table function
does - fell back to the query-literal formatter. For several types that is not
the value's text at all: a `Date` came out as its raw day number, a `Float64` as
`1.`, and a `UUID`, `IPv4`, `IPv6`, `DateTime64` or `Decimal` carried the quote
characters of the literal inside the string.
SELECT toString(toDate('2020-01-01')) IN (toDate('2020-01-01')); -- 0
SELECT '18262' IN (toDate('2020-01-01')); -- 1
SELECT '1.2.3.4' IN (toIPv4('1.2.3.4')); -- 0
SELECT x FROM values('x String', toDate('2020-01-01')); -- '18262'
`IN` therefore disagreed with `CAST(x AS String)` and `toString`, and over a
table it dropped the row that should match while returning one that should not.
The conversion now renders the value with the text serialization of the source
type, as the `Enum` case added by #112647 already did for the same reason - the
literal formatter stays for a constant whose source type is unknown.
Closes: #117240
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [e6e3175] Summary: ✅
AI ReviewSummaryReviewed head Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes19 object files changed (+199.80 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units88 translation units recompiled, 518 s compile time in total, 88 of them have a recent master baseline. |
…ed-constant-117240
…ed-constant-117240
…e `CAST` uses them Address review: the set of `IN` and the `values` table function converted a typed constant to `String` with default `FormatSettings`, while `CAST(x AS String)` in the same query uses the session's settings for the types it serializes generically, so `'yes' IN (true)` was `0` under `bool_true_representation = 'yes'` although `CAST(true AS String)` is `yes`. `GetSetElementParams` now carries the query's `FormatSettings` (filled from the context in `CollectSets`, `ActionsVisitor` and the constant-folding path of `resolveFunction`), and `TableFunctionValues` passes them too. `convertFieldToType` applies them exactly where `CAST` does: numbers, decimals, dates and times keep the fixed text of `FormatImpl` in `FunctionsConversion.h`, so `date_time_output_format` changes neither `CAST` nor the set, and every other type is serialized with the query's settings. The test pins both halves: `DateTime` under `date_time_output_format = 'unix_timestamp'` and `Bool` under `bool_true_representation = 'yes'`, for scalar and tuple `IN`, `values` and a table query. Co-Authored-By: Claude Fable 5.1 <[email protected]>
`date_time_output_format` is not an example of a setting that applies: `CAST` renders a `DateTime` with fixed text, and the set follows `CAST`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ed-constant-117240
…tFieldToType`
The `Array`, `Tuple` and `Map` branches recursed with a `nullptr` type hint, so a nested
element converted to `String` fell back to the query-literal formatter:
`values('x Array(String)', [toDate('2020-01-01')])` gave `['18262']` and
`['2020-01-01'] IN ([toDate('2020-01-01')])` was `0`, while `CAST` gives `['2020-01-01']`.
Now the nested element, key and value types of a matching source type are passed down.
The test also pins that `output_format_decimal_trailing_zeros` does not reach the set, as
in `CAST` (a `Decimal` is already classified as fixed text by `WhichDataType::isNumber`).
Address review: #118372
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…type hint The `Array`/`Tuple`/`Map` recursion of `convertFieldToType` now passes the source element type down, so an `Enum` element inside an array converted to `String` gets its name, not its number. The test pinned the old (wrong) value as a known limitation; assert the correct one. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118372&sha=26f8cb226b94c264205a3d8522b6110e9275d7f2&name_0=PR&name_1=Fast%20test PR: #118372 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ames `GetSetElementParams` now holds `FormatSettings`, which is large. It was constructed inline in `CollectSetsVisitor::enterImpl`, which is inlined into the recursive `InDepthQueryTreeVisitorWithContext::visit`, so every level of recursion carried it. On the deep expression of `04041_defaults_long_dependency` (a chain of 1000 `DEFAULT` columns) this overflowed the stack in `Stateless tests (arm_binary, parallel)`. Add an overload of `getSetElementsForConstantValue` that takes the context and builds the parameters itself, out of line, and use it from `CollectSetsVisitor`, `QueryAnalyzer::resolveFunction` and `ActionsVisitor`. The parameters are passed by reference inside `SetUtils.cpp`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118372&sha=fc3d72a385d845647adb4a81416fd41f0b141434&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29 #118372 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e branches of `convertFieldToType` `convertFieldToType` unwraps only the target `Nullable`, so for a source of type `Nullable(Tuple(Date, UUID))` the tuple branch got the wrapped hint, the `typeid_cast` to `DataTypeTuple` failed, and the elements were rendered as query literals again. Unwrap `Nullable` and `LowCardinality` from the hint in the `Array`, `Tuple` and `Map` branches as the `String` branch already does, and add a regression to `05100_string_set_from_typed_constant`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 CI status:
@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118372&sha=fc3d72a385d845647adb4a81416fd41f0b141434&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29 and provide a fix in a separate PR. If the fix is already in progress (possibly #121089), link it here. |
|
The fix is already in progress: #121089 (mine, open, waiting for review). The job's The failed query with |
…at settings The old-interpreter fast path for a literal `array(...)` on the right side of `IN` casts each element to the common supertype with `convertColumnToTypeOrThrow` before the set is built. It used default `FormatSettings`, so with `String` as the supertype `['yes', 'x'] IN ([true, 'x'])` was `0` under `bool_true_representation = 'yes'`, while `CAST([true, 'x'] AS Array(String))` is `['yes', 'x']`. Pass the query's format settings, from an out-of-line helper so that `FormatSettings` stays off the frames of the recursive visitor. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 |
…endered to `String` `05321_sqlite_pushdown_enum_constant` was added on master and pins the old behaviour of a one-element tuple key `tuple(s) IN (tuple(E))`: the local set held the `Enum` constant's value as text (`'3'`), and the filter pushed to SQLite followed it. This PR intentionally renders a typed constant converted to `String` with its own text serialization, so the set now holds the `Enum` name (`'7'`), consistent with the bare `s IN (E)` case, and the pushed filter follows it. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118372&sha=latest&name_0=PR PR: #118372 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 CI status: the only failing test, |
… does `CAST(x AS Time)` of a `Date` or `Date32` gives `00:00:00`, but the `Field` conversion wrote the day's Unix timestamp. Now that nested element hints are passed down, this reached `Array(Time)` in the set of `IN` and in the `values` table function, where a timestamp beyond the `Time` range (`2106-02-07`) wrapped to `-06:28:16` in the `Int32` storage and matched an unrelated row. Address review: #118372 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ime64` as midnight
The previous commit converts a `Date` / `Date32` constant to `Time` / `Time64` as midnight, as `CAST`
does, instead of the day's Unix timestamp. So `t64 IN (toDate32('9999-12-31'))` now matches the
stored `00:00:00` (and still does not overflow). The test pinned the old behaviour; update it.
CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118372&sha=latest&name_0=PR&name_1=Fast%20test
PR: #118372
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 CI status for bfe3693: every test job passes. The only failure is |
…o its day
With the source element type now passed down to the elements of an `Array`,
`Tuple` or `Map`, a nested `DateTime` / `DateTime64` constant reached the
`Date` / `Date32` branches of `convertFieldToType`, which truncate the time of
day even under `strict`. So `[toDate('2020-01-01')] IN
([toDateTime('2020-01-01 12:00:00', 'UTC')])` returned 1 while the comparison
with `=` returns 0. Under `strict`, such a value is now not representable;
materialization (`CAST`, `values`) still truncates it.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… destination type A `NULL` member replaced with the default of the destination type by `input_format_null_as_default` was then converted as a value of the source type: a `DateTime64` default was read as a `Date` (`BAD_GET`), and a `DateTime` default as a day number. Such a member is now used as is. The regression is covered by `05459_set_nested_datetime_to_date_time_of_day`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118372&sha=7cb89e02a314d31a580eee1e9bf903c78bc124e5&name_0=PR&name_1=Stress%20test%20%28amd_debug%29 ( |
|
Acknowledged. This one is not covered by my open #127913, so I'm working on a separate fix and will link the PR here. The query is from Unlike the earlier hits of this shape, the query never reached |
|
The fix is #128209. A fault thrown on the client thread mid-query makes |
The previous commit rejected a `DateTime` / `DateTime64` with a time of day in
the `Date` / `Date32` branches of `convertFieldToType` under `strict`. Those
branches also convert a scalar constant wrapped in `Dynamic`, so
`d IN (CAST(toDateTime('2020-01-02 05:00:00') AS Dynamic))` stopped matching
while the plain `d IN (toDateTime('2020-01-02 05:00:00'))` still truncates,
which broke `05060_enum_in_variant_dynamic_in_set` and
`05137_dynamic_constant_folding_distributed` in the Fast test:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118372&sha=5d59c531384ff95629ef03268f61858b0dca5eab&name_0=PR&name_1=Fast%20test
The check now applies only to the members of an `Array`, `Tuple` or `Map`
constant, which is what the review asked for.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 The Fast test failures of |
…ested `Dynamic` / `Variant` member of a strict set
`convertAlternative` converted the recovered `DateTime` / `DateTime64` alternative of a
`Dynamic` / `Variant` member of a composite straight to `Date`, truncating the time of day; the
outer conversion then saw the member typed as `Date` already and skipped the check. So
`[toDate('2020-01-01')] IN (CAST([toDateTime('2020-01-01 12:00:00', 'UTC')], 'Array(Dynamic)'))`
was 1 while `=` is 0. Run `isDateTimeElementWithTimeOfDay` on the recovered alternative before
converting it. A scalar `Dynamic` constant does not reach `convertAlternative` and keeps truncating.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 The |
upgrade_runner.sh calls configure() twice over one embedded Keeper and data directory, and with RANDOMIZE_KEEPER_FEATURE_FLAGS=1 each call draws check_not_exists, create_if_not_exists and remove_recursive again, independently. When create_if_not_exists goes from 1 to 0, a coordinated refreshable view created during the stress phase (04811's APPEND view in a database recreated as Replicated) is attached against a Keeper that lost the flag, and RefreshTask stops it by design, logging an <Error> that the upgrade log scan reports. This failed the check on 3 unrelated PRs in 30 days (ClickHouse#118372, ClickHouse#117784, ClickHouse#114812); all 3 job logs show the 1 -> 0 flip. A real in-place upgrade does not downgrade its Keeper, so carry the flags the previous-release configure() drew into the upgraded server's keeper_port.xml and fail the job if they still differ, the same shape as the codec carry-over of ClickHouse#121249. Every job still draws random flags. Validated locally: the real code extracted from both scripts, run 2000 times in the CI image, restores the first draw 2000/2000 with no FAIL row; with the restore removed the new check fails 1765/2000. On a master build, restarting with create_if_not_exists turned off logs exactly the CI line, and restarting with the flags unchanged logs nothing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Interpreters/convertColumnToType.cpp
`IDataType::equals` ignores custom names, so with the source element type now passed down as a hint, a `UInt8` member reached the identity shortcut of `convertFieldToType` for a `Bool` target and stored the raw byte (e.g. 2) instead of `true`. Require the full type names to match too, as the identity check of `convertColumnToType` and `CAST` do. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…default probe `isDefaultValueInConstantSet` built its probe set with default format settings, so under e.g. `bool_true_representation = 'yes'` it disagreed with the set of `IN` itself and `optimize_inverse_dictionary_lookup` chose a wrong rewrite for missing dictionary keys. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed-constant-117240 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…w-aware helper Master added `resolveActiveAlternative(const ConstantValue &)` built on `resolveActiveAlternativeType`, which this PR replaced with `resolveActiveAlternative(const IColumn &, const DataTypePtr &, size_t)`. Use the new helper's `type` for row 0 of the constant. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed-constant-117240 Conflicts in `src/Analyzer/SetUtils.cpp` and `src/Planner/CollectSets.cpp`: master added `tryGetSetElementsForTupleOfPlainValues` and its call in `CollectSetsVisitor`, next to the out-of-line `getSetElementsForConstantValue(..., context)` overload of this branch. Both are kept. `tryGetSetElementsForTupleOfPlainValues` now takes `transform_null_in` alone instead of `GetSetElementParams`, because that struct holds the large `FormatSettings` in this branch and must not be built in the frame of the deeply recursive `CollectSetsVisitor` (stack overflow in `04041_defaults_long_dependency`). Co-Authored-By: Claude Fable 5.2 <[email protected]>
Converting a constant of another type to
String- which is what building the set ofINagainst aStringcolumn does, and what thevaluestable function does - fell back to the query-literal formatter. For several types that is not the value's text at all: aDatecame out as its raw day number, aFloat64as1., and aUUID,IPv4,IPv6,DateTime64orDecimalcarried the quote characters of the literal inside the string.INtherefore disagreed withCAST(x AS String)andtoString- and over a table it dropped the row that should match while returning one that should not.The conversion now renders the value with the text serialization of the source type, as the
Enumcase added by #112647 already did for the same reason ("INmust agree withCAST"); the literal formatter stays for a constant whose source type is unknown.A
FixedStringconstant is deliberately left alone: it has no rendering problem - itsFieldalreadyholds its bytes - what it has is the separate question of whether
INadopts the zero-paddingequivalence of the comparison functions.
convertFieldToTypeis also how the skip indexes derive thevalue to hash, and
convertConstantForArrayIndexFunctioninMergeTreeIndexBloomFilter.cpprelies onthe padded form to match the raw-byte comparison of
arrayIndex.hexecuteString, so trimming heremakes the index prune rows the function matches.
The rendering uses the query's format settings exactly where
CAST(x AS String)uses them:CASTwrites numbers, decimals, dates and times with fixed text (
FormatImplinFunctionsConversion.h), sodate_time_output_formatchanges neitherCASTnor the set, while it serializes the other types withthe session settings, so
'yes' IN (true)is1underbool_true_representation = 'yes', asCAST(true AS String)isyes. The set ofINand thevaluestable function both receive thesettings from the query context.
Closes: #117240
Related: #112647
Related: #116852
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fixed
INagainst aStringcolumn with a constant of another type (Date,DateTime,UUID,IPv4,IPv6,Decimal,Float) matching the wrong rows: the set held the query-literal rendering of the constant (aDateas its day number, anIPv4with quote characters) instead of the text thatCAST(x AS String)produces. Thevaluestable function is fixed the same way.Workflow [PR]
Sync PR [sync-upstream/pr/118372]