Repository navigation
Conversation
`IDataType::equals` ignores custom names at every level, so `Array(UInt8)` equals `Array(Bool)`. `FunctionCast::prepareImpl` only compared the custom names of the outermost types before taking the identity shortcut, so `CAST([toUInt8(2)] AS Array(Bool))` reused the column and the `Bool` element kept the raw byte 2: it printed `true`, but `= true` was false, `has(.., true)` returned 0 and `toUInt8` returned 2. The scalar `CAST(toUInt8(2) AS Bool)` was already correct through `createUInt8ToBoolWrapper`. `haveSameCustomNames` walks both type trees positionally through `getNumberOfChildren` / `getChild` and requires equal custom names at every level. At the root it is the old predicate, so every top-level decision is unchanged. A pair that differs only in a nested custom name now takes the container wrappers (Array, Tuple, Map), which recurse to the `UInt8 -> Bool` wrapper for the differing leaf and to identity wrappers for the equal ones. This also covers `Dynamic -> Array(Bool)` and `Variant(Array(UInt8), ..) -> Array(Bool)`, which reach `prepareImpl` through `prepareUnpackDictionaries`. `createObjectWrapper` had its own identity for `JSON` types equal up to `SHARED` marks, which compares typed-path types with `equals`; it gets the same guard, so `JSON(a UInt8) -> JSON(a Bool)` takes the text round trip and parses 2 as `true`. Both changes are needed for the `JSON` case, because `prepareImpl` tries its own identity first. The removed `safe_convert_custom_types` comment was about IPv4/IPv6, which are separate types now. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Make the haveSameCustomNames comment accurate: Variant::equals does compare direct alternatives' custom names. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding) plus my own cold review (4 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261106-015000 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261106-005400 |
|
Workflow [PR], commit [7e519be] Summary: ✅
AI ReviewSummaryThis PR normalizes nested Final VerdictStatus: ✅ Approve |
|
cc @Avogar @Algunenano, could you review this and add the |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes4 object files changed (+119.73 KiB total), 0 added.
719 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 units7 translation units recompiled, 58 s compile time in total, 7 of them have a recent master baseline. |
Refusing the identity for every nested custom-name difference had two side effects: - A container of Variant whose alternatives differ only in a geometry alias, e.g. Array(Variant(Array(Point), String)) to Array(Variant(Array(Tuple(Float64, Float64)), String)), went to the Variant wrapper, which matches alternatives by name and threw CANNOT_CONVERT_TYPE. Such aliases share the representation, so the identity is correct for them, as before. - A JSON cast that changes a typed path between UInt8 and Bool took the text round trip, which re-infers the types of unrelated dynamic paths (1.0 came back as Int64). Bool is the only custom name that constrains the values of its base type, so the identity is now refused only when some nested position turns UInt8 into Bool. For JSON with the same typed paths and parameters, only those typed path columns are converted; dynamic paths and shared data are reused as they are. The top-level safe_convert_custom_types check is restored unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Under accurateCastOrNull and accurateCastOrDefault, the Tuple wrapper
returns Nullable(Tuple) even for a non-Nullable target, to report
per-row conversion failures to its caller. The typed path conversion
installed that column directly into a path declared as Tuple(Bool) or
Array(Tuple(Bool)), so serialization downcast a ColumnNullable to
ColumnTuple (SIGSEGV in release, a failed assert_cast in debug):
SELECT accurateCastOrNull(materialize('{"a":[2]}'::JSON(a Tuple(UInt8))),
'JSON(a Tuple(Bool))');
The typed path types differ only in Bool custom names here, so the
conversion cannot fail. Prepare the path wrappers with a plain CAST,
which keeps the declared layout at every nesting level.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #129642
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
CASTof a container ofUInt8to the same container ofBool, for exampleCAST([toUInt8(2)] AS Array(Bool)),Tuple(Bool),Map(K, Bool), aJSONtyped path, or aDynamic/Variantvalue cast toArray(Bool): a value other than 0 and 1 was kept as is, so it was printed astruebut did not compare equal totrue, andtoUInt8returned the original value.Description
On 26.8.18.2, 26.3.42.3 and master,
SELECT CAST([toUInt8(2)] AS Array(Bool)) AS a, a[1] = true, toUInt8(a[1])returns[true] 0 2, soWHERE a[1] = truedrops the row andhas(a, true)is 0. The scalarCAST(toUInt8(2) AS Bool)returns 1.IDataType::equalsdoes not compare the custom names of nested types (Array(UInt8)equalsArray(Bool)), andFunctionCast::prepareImplcompared only the outermost custom names before reusing the column, so the nestedUInt8 -> Boolconversion never ran.Boolis the only custom name that restricts the values of its base type, so the identity is now refused only whenconvertsUInt8ToBoolfinds a nested position that turnsUInt8intoBool. The existingArray/Tuple/Mapwrappers then reach the scalar conversion; pairs that differ only in other custom names (geometry aliases,SimpleAggregateFunction) keep the identity.DynamicandVariantsources reachprepareImplthe same way. ForJSONwith the same typed paths and parameters,createObjectWrapperconverts only those typed path columns, with a plainCASTso thataccurateCastOrNullkeeps their declared layout, and reuses the dynamic paths and shared data, so unrelated values keep their types. A container ofVariantwhose alternative turnsUInt8intoBoolnow throwsCANNOT_CONVERT_TYPE, as the sameVariantcast already does at the top level.Not changed: conversions that do not go through
CAST(castColumnin format readers, theINSERT SELECTconversion handled in #129642,ALTER MODIFY COLUMNfromUInt8toBool), and aCASTtoSimpleAggregateFunction(any, Bool), which keeps the value even at the top level.Validation: new test
05556_cast_nested_uint8_to_boolfails on master (18 rows) and passes with the fix; 50/50 randomized runs; the 1843_cast_/bool/variant/dynamic/json/geo/tuple/mapstateless tests have the same results on both binaries.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/129664]