Repository navigation
Conversation
…llable(Tuple)
`accurateCastOrNull(tuple(materialize([CAST('1', 'Int128')])), 'Nullable(Tuple(Array(UInt64)))')`
threw `LOGICAL_ERROR: Unexpected return type ... Got Nullable(Tuple(Array(Nullable(UInt64))))`
(STID 3262-3c86, Stress test (azure, amd_tsan) on master 95bfedb), and
`accurateCastOrDefault` with such a target read the wrongly typed column (`[1,2,300]` ->
`[144,230,155]` on 26.10.3.7).
Since 8f89508 (ClickHouse#119183) a tuple asks its elements to report a failed conversion as NULL
(`report_failures_as_null` -> `requested_result_is_nullable`), while the elements of an array
or a map are not asked and must convert strictly. Only the text conversions honored the flag.
The other producers of failure-NULLs keyed on `cast_type == CastType::accurateOrNull` alone:
the numeric, date/time and IPv4/IPv6 branches of `createWrapper`, `createDecimalWrapper`, the
NULL mode of `createFixedStringWrapper`, and the `createToNullableColumnWrapper` fallbacks of
`createWrapper`, `createDecimalWrapper`, `createEnumWrapper`, `createQBitWrapper`,
`prepareUnpackDictionaries` (NULL source) and `prepareImpl`. An unasked array element thus
came back as `Nullable(T)`, `ColumnArray` kept it, and the column type differed from the
declared one.
Each of these producers now reports a failure as NULL only when asked, and otherwise takes the
`accurateCast` branch it already had. Top-level `accurateCastOrNull` is unchanged (its result
is always Nullable, so it is asked), as are direct tuple elements and `Nullable` array
elements. `createArrayToQBitWrapper` (Array -> QBit and QBit -> QBit) relied on the unasked
Nullable to turn an element failure into a NULL row, so it now passes the request explicitly,
like `createTupleWrapper`; this also brings back the 26.10 result `\N` for
`accurateCastOrNull([1, NULL]::Array(Nullable(Float32)), 'QBit(Float32, 2)')`.
An array or map element that does not fit now fails as with `accurateCast`, as a malformed
String element and a NULL element already did.
Closes ClickHouse#132281
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…Null An Array or Map element of a Nullable(Tuple) is not asked to report a failed conversion as NULL, so it must convert as accurateCast does. Two producers still keyed on cast_type == accurateOrNull alone: - createVariantToColumnWrapper / createDynamicToColumnWrapper pre-probed every member with createWrapperIfCanConvert and inserted the target default for a member without a wrapper. In an unasked element a String '1' member failed the probe on '' and became 0, and an IPv4 member to Decimal32(2) became 0 (26.10.3.7 returns ([0]) for the String case). They now probe and drop only when asked: report_failures_as_null, or a NULL-capable target, which keeps the top level and direct tuple elements as before. Otherwise every member with values is converted strictly. - The AggregateFunction "not supported" tail returned a Nullable wrapper for any accurateOrNull, so an unasked element failed with ILLEGAL_COLUMN; it now honors requested_result_is_nullable and otherwise throws the accurateCast CANNOT_CONVERT_TYPE. A Variant or Dynamic target is NULL-capable, so it stays asked and is not changed. The test gains the second master CI query (STID 3262-3a0d, Stress test (azure, amd_msan)), the Variant/Dynamic and AggregateFunction element lines, and controls for the asked paths. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…appers
createVariantToColumnWrapper and createDynamicToColumnWrapper decide whether
an accurateCastOrNull conversion is asked to report a failure as NULL. The
previous commit tested isNullableOrLowCardinalityNullable(to_type), which is
false for a Variant target. A Dynamic source can be cast to a Variant, and a
Variant target is never wrapped in Nullable (getReturnTypeImpl and
createInternalCast leave a canContainNull type as is), so the top-level call
passed report_failures_as_null = false and the strict branch threw Code 70 for
a stored type the Variant cannot hold:
accurateCastOrNull(materialize(toUInt16(3)::Dynamic), 'Variant(UInt8, String)')
accurateCastOrNull(tuple(materialize([toUInt16(3)::Dynamic])),
'Nullable(Tuple(Array(Variant(UInt8))))')
Base and 26.10.3.7 return \N and ([NULL]) there. Both wrappers now use
canContainNull(*to_type), so a Dynamic source still probes and drops at the top
level, in accurateCastOrDefault and in an Array(Variant) element. For a Variant
source nothing changes: its to_type is never a Variant or Dynamic, those are
routed earlier in prepareUnpackDictionaries.
The test gains the four lines above (plus accurateCastOrDefault and an IPv4
value) and two Dynamic -> Decimal32(2) controls.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (rounds 1-3): 6 findings, 3 fixed, 2 DISAGREE, 1 nit noted
|
|
cc @yariks5s, could you review this? Under accurateCastOrNull, the numeric, date, IP, Decimal, FixedString, Variant and Dynamic conversions returned Nullable even for an Array or Map element that did not ask for it, so Nullable(Tuple(Array(T))) got a column of the wrong type (LOGICAL_ERROR) and accurateCastOrDefault misread it; each conversion now honors requested_result_is_nullable. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261118-000202 |
|
Workflow [PR], commit [9c97270] Summary: ❌
AI ReviewSummaryThe change fixes mismatched nested column types in Consumer coverage: tuple conversion extracts requested failure masks; array and map construction receive their declared element types; Final Verdict✅ Approve |
…astOrNull An Array or Map element of an accurateCastOrNull / accurateCastOrDefault target is not asked to report a failed conversion as NULL, so it converts as with accurateCast. Its String and FixedString to native integer conversion still used the ordinary parser, which wraps an out-of-range value: '300' to UInt8 gave 44, also for a Variant(String) or Dynamic member, where accurateCast throws CANNOT_PARSE_TEXT. Use the accurate parser there too. Found by the clickhouse-gh review of ClickHouse#132543. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes5 object files changed (+22.80 KiB total), 0 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units40 translation units recompiled, 352 s compile time in total, 40 of them have a recent master baseline. |
|
@nihalzp this should be the last of the bunch related to nullable tuples |
CI finish ledger - 9c97270Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261124-163029 |
Closes: #132281
Related: #119183
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
accurateCastOrNullandaccurateCastOrDefaultto aNullable(Tuple)with anArrayorMapelement: its elements now convert to their declared type, so the cast no longer throwsLOGICAL_ERRORandaccurateCastOrDefaultno longer returns wrong values. When a value does not fit, the numeric, date, IP,Decimal,FixedString,Variant,Dynamicand text-to-integer conversions of such an element now fail as withaccurateCast. Closes #132281.Description
On 26.10.3.7,
accurateCastOrNull(tuple(materialize([toUInt16(1)])), 'Nullable(Tuple(Array(UInt8)))')throwsLOGICAL_ERROR, andaccurateCastOrDefaultwith that target returns([144,230,155])for[1,2,300]. The AST fuzzer hit it in master stress tests (amd_tsan, amd_msan). It predates #119183 (26.10.3.7 fails too), so no revert.Since #119183 a tuple asks its elements to report a failed conversion as NULL; array and map elements are not asked, so they convert strictly. Only the text conversions honored that. The other conversions and the "not supported" fallbacks returned
Nullablefor everyaccurateCastOrNull, and an array element kept it. AVariantorDynamicelement instead dropped a member it could not convert and returned the default.These conversions now report a failure only when asked (
requested_result_is_nullable), else they act asaccurateCast.Array/QBittoQBitrelied on the unaskedNullableto make a failed element a NULL row, so it now asks, restoring the 26.10 result\NforaccurateCastOrNull([1, NULL]::Array(Nullable(Float32)), 'QBit(Float32, 2)'), which throws on master.Behavior change: in an array or map element, these conversions and text-to-integer parsing (
'300'toUInt8gave44) now fail as withaccurateCastwhen a value does not fit, as a malformedStringelement and aNULLelement already do on master. Top-level casts, direct tuple elements andNullableorVariantelement targets still return NULL.The new test aborts a master server at the CI query and passes with the fix; existing
accurateCast*,Nullable(Tuple)andQBittests pass unchanged.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/132543]