Repository navigation
convertColumnToType: tag-faithful Bool; migrate values() off Field - #112308
Conversation
`convertColumnToTypeOrNull`'s `Field` fallback does `IColumn::get(0, field)` to reconstruct a value and then delegates to `convertFieldToType`. `get` reconstructs the `Field` using the storage column's `NearestFieldType`, which does not round-trip the `Bool` tag: a `DataTypeBool` column is a plain `ColumnUInt8`, so `get` yields a `UInt64` `Field`. `convertFieldToType` keys on that tag, so `Bool -> String` produced '1'/'0' instead of 'true'/'false' (and likewise for nested `Array(Bool)` / `Tuple(Bool)` / `Map(..., Bool)`), diverging from `convertFieldToType` even though the helper is documented and tested as its column twin. Re-tag `Bool` values in the reconstructed field (recursing through `Array`/`Tuple`/`Map`, unwrapping `Nullable`/`LowCardinality`) before delegating, so the conversion is faithful for tag-sensitive targets too. `Bool` is the only built-in type whose column `get` loses its `Field` tag - IPv4/IPv6/UUID/Decimal have dedicated columns and `Field` types - confirmed by extending the differential test with a matrix of `-> String` conversions (Bool/nested-Bool now pass; Enum/Date/Decimal/IPv4 were already faithful). No behavior change for current callers (all convert to numeric targets, which are value-preserving regardless of the tag). This unblocks migrating textual-conversion callers of the legacy `Field`-returning `evaluateConstantExpression` to the column API. Part of removing DB::Field. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [91da3b7] Summary: ❌
AI ReviewSummaryThis PR makes Final Verdict✅ No new findings. |
A review noted `ColumnVariant::get` erases a `Bool` alternative to the nested column's `UInt64` field, and for an ambiguous variant (e.g. `Variant(Bool, UInt8)`) the reconstructed `Field` no longer records which alternative was active - so `retagBoolInField` cannot recover it structurally the way it does for `Array`/`Tuple`/`Map`. Rather than add a `ColumnVariant`-aware path (which would also pull in `Dynamic`/`JSON`) for a case no caller needs, document the limitation honestly in the header and the helper comment: faithful for `Bool` under the structural carriers, not for `Bool` nested under `Variant`. Note that the legacy `Field` path (`convertFieldToType` on `(*column)[0]`) has the exact same limitation, so migrating a caller to this helper does not change that behavior. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
`TableFunctionValues` evaluated each argument with the legacy `Field`-returning
`evaluateConstantExpression` and coerced it with `convertFieldToTypeOrThrow`, materializing a `Field`
per value. Switch it to `evaluateConstantExpressionAsColumn` + `convertColumnToTypeOrThrow`, inserting
the converted size-1 column directly - no `Field`. The tuple (multi-column) path converts each tuple
element independently (same per-element semantics and error behavior as before), and structure
inference (`getTypesFromArgument`) now only reads the type. This is the first textual-conversion caller
moved to the now-tag-faithful column coercion; `values('x String', true)` returns 'true' via the column
path (previously via the `Field`-API literal shim).
Behavior is unchanged: verified against the existing `values` tests and a new stateless test covering
`Bool` -> textual as a single value, inside a tuple row, and inside an array column.
Part of removing DB::Field.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
A review noted that on a not-representable value (e.g. `values('x UInt8', 256)`)
`convertColumnToTypeOrThrow` threw a generic "Value in column of type UInt64 cannot be represented as
UInt8", dropping the offending literal that the previous `convertFieldToTypeOrThrow` reported ("Cannot
convert value '256' from ...") - which also made it hard to tell which element of a multi-column row
failed.
On the exceptional (not-representable) path, reconstruct the `Field` and delegate to
`convertFieldToTypeOrThrow` to reproduce that diagnostic exactly, with a defensive generic throw as an
unreachable guard. The `Field` is materialized only on this error path; the happy path in
`convertColumnToTypeOrNull` stays `Field`-free. This rides the fallback's existing `convertFieldToType`
delegation and is removed together with it when that fallback becomes column-native (throwing
conversions such as a bad string->number parse are unaffected - they already propagate their own error).
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Migrating `values` to the column API changes one user-visible behavior: a non-literal `Bool`-typed constant (wrapped in `CAST` / `Nullable` / `LowCardinality`) converted to a textual column now renders as 'true'/'false' instead of '1'/'0'. Previously such non-literal constants went through `evaluateConstantExpression` + `convertFieldToType`, which materialized `(*result_column)[0]` and collapsed the `Bool` tag to `UInt64`, so `String`-formatting produced '1'/'0'. The column-native path keeps the `Bool` type, which is consistent with direct `Bool` literals and with `CAST(... AS String)`. This is a deliberate fix, not a regression - the old '1'/'0' was an inconsistency, so it is not preserved. Pin the corrected behavior with an end-to-end regression, and note that a computed comparison (`1 > 0`) is `UInt8` rather than `Bool` and is therefore unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The merge with master brought several `04652_*` stateless tests, colliding with the number this test was originally assigned. Renumber it to the next free number to keep prefixes unique. Content unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 79/80 (98.75%) · Uncovered code |
yariks5s
left a comment
There was a problem hiding this comment.
LGTM, but seems like we do not completely remove Field here, we do it in convertColumnToType.cpp:153
| for (auto & entry : field.safeGet<Map>()) | ||
| { | ||
| auto & key_and_value = entry.safeGet<Tuple>(); | ||
| if (key_and_value.size() == 2) |
There was a problem hiding this comment.
Nit: looks like for Map this check is redundant and we can do assert here instead. But up to you, I don't see this as a problem
There was a problem hiding this comment.
it doesn't matter - this function is temporary to keep everything consistent during transition - will be removed at the end
Migrate the constant `IN` / set-building path off `DB::Field`.
`getSetElementsForConstantValue` now takes the right-hand side as a
`ColumnPtr` instead of a `Field`, and `createBlockFromCollection` iterates the
collection's member columns (`Array` elements as rows, `Tuple` elements as
subcolumns) instead of `Array`/`Tuple` of `Field`. Per-element conversion goes
through `convertColumnToType` (strict) via a new `convertColumnToTypeCheckEnum`,
the column twin of `convertFieldToTypeCheckEnum`; the not-representable vs
genuine-NULL distinction uses `convertColumnToType`'s null channel (`{}` vs a
size-1 NULL column) instead of inspecting `Field::isNull`. The dispatch
(`transform_null_in`, `Nullable(Tuple)` dual interpretation, tuple-vs-set
disambiguation) is preserved, with `Field` value inspections replaced by
column-native ones (`isNullAt`, homogeneous element-type checks).
Callers:
- analyzer (`CollectSets`, `resolveFunction`) pass `ConstantNode::getColumn`
instead of `ConstantNode::getValue` (no `Field` materialization);
- legacy `ActionsVisitor` evaluates set elements with
`evaluateConstantExpressionAsColumn` and assembles the collection column
directly (`buildCollectionColumnAndTypeFromASTFunction`).
Because the set is now built with `convertColumnToType` (tag-faithful for
`Bool` since #112308), a `Bool` set element converted to a textual left-hand
type is now the canonical `'true'`/`'false'` rather than the numeric collapse
`'1'`/`'0'` produced by the old `Field` path (`IColumn::get` erased the `Bool`
tag to `UInt64` before `convertFieldToType`). This is an incidental fix, kept
rather than pinned, on both the analyzer and legacy paths; regression test
`04692_bool_tag_faithful_in_set` covers it. This matches the `values` table
function and `CAST` behavior.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Two related steps in removing
DB::Fieldfrom constant-expression handling:Make
convertColumnToTypetag-faithful forBool. ItsFieldfallback reconstructs a valuewith
IColumn::get, which does not round-trip theBooltag (aDataTypeBoolcolumn is a plainColumnUInt8, sogetyieldsUInt64).convertFieldToTypekeys on that tag, soBool -> Stringreturned
'1'/'0'instead of'true'/'false'(and likewise for nestedArray(Bool)/Tuple(Bool)/Map(..., Bool)). The fallback now re-tagsBoolvalues (recursing throughArray/Tuple/Map, unwrappingNullable/LowCardinality) before delegating. Scope: faithful forBoolunder the structural carriers, not forBoolnested underVariant/Dynamic/JSON(
ColumnVariant::geterases the active alternative - the legacyFieldpath has the samelimitation). The
convertColumnToTypeOrThrowerror path reproducesconvertFieldToType's diagnostic.Migrate the
valuestable function offField.TableFunctionValuesnow evaluates itsarguments with
evaluateConstantExpressionAsColumnand coerces them withconvertColumnToTypeOrThrow(per element for the tuple path), inserting the converted columns directly instead of materializing a
Fieldper value.One user-visible behavior change (see the new stateless test): a non-literal
Bool-typed constant(wrapped via
CAST/Nullable/LowCardinality) inserted into a textualvaluescolumn now renders as'true'/'false'instead of'1'/'0'. Example:SELECT * FROM values('x String', CAST(true, 'Nullable(Bool)'))returnstrue(was1). DirectBoolliterals were already'true'and areunchanged; a computed comparison such as
1 > 0isUInt8(notBool) and is also unchanged. The old'1'/'0'was an inconsistency (direct literals andCAST(... AS String)already produce'true'/'false'), so this is a deliberate fix, not preserved.Related: #110945
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed the
valuestable function rendering a non-literalBoolconstant (e.g.CAST(true, 'Nullable(Bool)')) inserted into aString/textual column as1/0instead oftrue/false.Version info
26.8.1.570(included in26.8and later)