Repository navigation
Conversation
…owCardinality element Under accurateCastOrNull, a Nullable(Tuple) asks each element conversion to report a failed conversion as NULL, and extractTupleElementConversionFailures turns those NULLs into a NULL tuple. A non-nullable element reports them by returning Nullable(T), which the extractor strips. Nullable(LowCardinality(T)) is not a type, so for a LowCardinality(T) element prepareUnpackDictionaries converted to T with report_failures_as_null and inserted the resulting ColumnNullable into the declared non-nullable dictionary: ColumnUnique threw "ColumnUnique can't contain null values" (Code 49, an abort in debug builds). A LowCardinality(Nullable(String)) source always carries the NULL key, so even a non-NULL value threw; a Nullable(Nothing) source gave Code 44 instead. The tuple now converts a LowCardinality(T) element whose source type differs as LowCardinality(Nullable(T)), the type that carries NULL for a LowCardinality target (as cast_keep_nullable does). The extractor folds its NULLs into the failures and restores the declared dictionary with cloneWithDefaultOnNull, the analogue of stripping Nullable from a plain element. The conversion itself goes through the existing LowCardinality(Nullable(T)) path, including its Variant, Dynamic and onlyNull branches. An identical source type cannot fail nor carry a NULL, so it keeps its dictionary-encoded path. Every LowCardinality line of the new test prints the same as the same input with the plain element type. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A tuple element of declared type LowCardinality(T) is converted as LowCardinality(Nullable(T)) only when its source can fail. A source of type T or LowCardinality(T) converts by identity and never reports a failure, so it now keeps its previous conversion. This removes the measured ~26% (debug build) dictionary copy from String -> LowCardinality(String), the common shape; a type-changing conversion such as String -> LowCardinality(FixedString(2)) still pays it (~23%, debug build, 10M rows). The test gains a line with T and LowCardinality(T) sources next to an element whose conversion fails. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the two-line conversion_types comment in createTupleWrapper to one line. 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; 2 rounds, 3 distinct findings) plus my own review (5 findings).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261118-040502 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261118-023700 |
|
Workflow [PR], commit [a9d0161] Summary: ❌
AI ReviewSummaryThe PR fixes failure reporting for The temporary Findings❌ Blockers
SELECT CAST(t, 'Nullable(Tuple(String))')
FROM values('t Nullable(Tuple(Nullable(String)))',
(NULL), (tuple('a')));
-- Expected: NULL, ('a'); actual: exception Code 349.Final VerdictStatus: ❌ Block. Fix the remaining parent-null validation case with a focused regression test, or link an issue tracking this pre-existing defect. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units7 translation units recompiled, 69 s compile time in total, 7 of them have a recent master baseline. |
…le result A `LowCardinality(T)` tuple element now converts as `LowCardinality(Nullable(T))`, so its conversion goes through the nullable-result branch of `prepareRemoveNullable`. That branch passed no null map to the conversion when the source is not nullable, so a NULL row of a `Nullable(Tuple(...))` source was converted from its placeholder value. An `Enum` element under such a row (`arrayElementOrNull` past the end, `join_use_nulls`, ...) then threw `UNKNOWN_ELEMENT_OF_ENUM` for the placeholder 0 in `accurateCastOrNull` / `accurateCastOrDefault` to `LowCardinality(String)` or `LowCardinality(FixedString(N))`, which returned NULL before this PR. When neither type is nullable, `prepareRemoveNullable` returns the conversion itself, which gets the caller's null map. The nullable-result branch now passes it through too when the source is not nullable. The same change fixes `CAST` of such a row to `Nullable(Tuple(Nullable(String)))` and `Nullable(Tuple(LowCardinality(Nullable(String))))` from an `Enum` element, and to `Nullable(Tuple(Nullable(Enum8(...))))` from a `String` element, which threw on master (26.10.3.7 too). Co-Authored-By: Claude Opus 5.5 <[email protected]>
AI review of a later commit does not approve the PR, see the AI Review comment.
…oveNullable
A NULL row of a `Nullable(Tuple(...))` holds placeholder values in its
elements. When the element is itself `Nullable`, its null map can be zero
under such a row (e.g. after `CAST(... AS Nullable(Tuple(Nullable(Enum8(...)))))`),
and both nullable-source branches of `prepareRemoveNullable` replaced the
parent's null map with the element's. The enum wrappers then formatted the
placeholder `0` and threw `UNKNOWN_ELEMENT_OF_ENUM`:
SELECT accurateCastOrNull(
CAST(arrayElementOrNull([tuple(materialize('a'::Enum8('a' = 1)))], 2)
AS Nullable(Tuple(Nullable(Enum8('a' = 1))))),
'Nullable(Tuple(LowCardinality(String)))');
This throws on 26.10.3.7, on master 361455a and on the previous head of this
PR; plain `CAST` to `Nullable(Tuple(String))` and
`Nullable(Tuple(Nullable(String)))` throws the same way. Both branches now pass
the union of the two null maps.
The `LowCardinality` wrapper converts only the dictionary when the nested
types match, so it no longer forwards the row-aligned parent map there:
merging it with the dictionary's null map would read past the dictionary
(a PODArray bounds assertion in a debug build, measured by reverting that hunk).
Reported by the automated review:
ClickHouse#132577 (comment)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
| } | ||
|
|
||
| const ColumnNullable * nullable_source = typeid_cast<const ColumnNullable *>(arguments.front().column.get()); | ||
| const ColumnPtr source_with_parent_nulls = addParentNulls(arguments.front().column, parent_nullable_source); |
There was a problem hiding this comment.
[Blocker] Apply the parent mask before validating non-nullable elements
The new addParentNulls call runs after the memoryIsZero check above. If a nullable element's placeholder is itself NULL, ordinary CAST still rejects the row before reaching the merged parent mask, even though the entire source tuple is NULL and the target permits that.
Reproduced with the fast-test binary for a9d01616:
SELECT CAST(t, 'Nullable(Tuple(String))')
FROM values('t Nullable(Tuple(Nullable(String)))',
(NULL), (tuple('a')));This throws CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN instead of returning NULL and ('a'). The equivalent accurateCast succeeds. LowCardinality(Nullable(String)) to LowCardinality(String) also fails through the earlier containsNull check in prepareUnpackDictionaries.
Exclude parent-null rows before element validation, or make both checks reject only element nulls in parent-non-null rows. Add a focused regression that still rejects a non-null tuple containing a null element. This predates the PR; linking a tracking issue is sufficient if it is handled separately.
There was a problem hiding this comment.
This predates the PR: master before it (361455a) and 26.10.3.7 throw the same Code 349 for both queries, and the PR does not change the not-NULL precheck or the containsNull check. I am fixing it in a separate PR, which also covers the element parsing conversions that fail under NULL tuple rows, and will link it here.
There was a problem hiding this comment.
The separate PR is #132672: it converts only the non-NULL rows of a Nullable(Tuple) source, and its test keeps a NULL element under a non-NULL row throwing 349.
|
@nihalzp also need help here |
A NULL row of a Nullable(Tuple) stores placeholders in its elements ('' for
a String, a NULL in a Nullable element, 0 for an Enum). prepareRemoveNullable
ran the Tuple conversion over the nested column of every row, and the
element conversions do not all read the null map they are handed: the
function adaptors parse the placeholder '' (Code 32/38), the not-NULL
precheck of a Nullable element and the LowCardinality containsNull() check
see the element NULL under a NULL tuple row (Code 349), and an Enum
placeholder 0 serialized to String throws 691. So CAST, INSERT SELECT and
ALTER TABLE ... MODIFY COLUMN from a Nullable(Tuple) with NULL rows threw
instead of returning NULL for those rows; the ALTER left a stuck mutation
and an unreadable column.
accurateCast already filters the NULL rows out, converts, and expands the
result (exclude_source_nulls, ClickHouse#120674). Enable it for every cast type when
the source is a Nullable(Tuple) whose nested type changes. The filter costs
+1.2 ns/row per Int element and +4-5 ns/row per String element on blocks
that contain a NULL row (release 26.10.5.57, measured through accurateCast);
blocks without NULLs are unchanged. The nested values of NULL rows in the
result are now the column default, as with accurateCast.
Related: ClickHouse#132577
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #132543
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
accurateCastOrNullandaccurateCastOrDefaultto aNullable(Tuple)with aLowCardinalityelement, which threwLOGICAL_ERROR(ColumnUnique can't contain null values) when an element value did not fit, wasNULL, or came from aLowCardinality(Nullable)column. The result is now the same as for the plain element type:NULLwhen an element cannot be converted, the converted tuple otherwise.Description
On 26.10.3.7,
accurateCastOrNull(tuple(toLowCardinality(materialize(toNullable('ab')))), 'Nullable(Tuple(LowCardinality(String)))')throwsLOGICAL_ERRORinstead of returning('ab'), and so does any element value that does not fit ('abc'toLowCardinality(FixedString(2))) or isNULL; debug builds abort. Found by the automated review of #132543 (thread); it predates #119183.Under
accurateCastOrNullaNullable(Tuple)asks each element conversion to report a failure asNULL. A plain element does it by returningNullable(T), which the tuple strips while folding its null map into the tuple'sNULLs.Nullable(LowCardinality(T))is not a type, so aLowCardinality(T)element inserted theNULLinto its non-nullable dictionary. ALowCardinality(Nullable(String))source always carries theNULLkey, so even a non-NULLvalue threw.Now the tuple converts such an element as
LowCardinality(Nullable(T)), reads itsNULLs as failures and restores the declared dictionary withcloneWithDefaultOnNull. An element conversion now also gets the null map of the surroundingNullable(Tuple), merged with aNullableelement's own, so placeholders under itsNULLrows are not converted; this also fixesCASTof such a row toNullable(Tuple(Nullable(String)))from anEnumelement and toNullable(Tuple(String))from aNullable(Enum)one, which throwUNKNOWN_ELEMENT_OF_ENUMon 26.10.3.7.TandLowCardinality(T)sources keep their previous path; a successful conversion that changes the type (StringtoLowCardinality(FixedString(2))) costs ~23% more in a debug build.Tuple(LowCardinality(T))without the outerNullableis still refused (Code 43): the same check decides whetherINsets and the primary key analysis convert a key withaccurateCastOrNull.The new test aborts a master debug build at its first query and passes with the fix; its
LowCardinalitylines print what the plain element type prints. ExistingaccurateCast*,LowCardinalitycast andNullable(Tuple)tests pass unchanged.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/132577]