Repository navigation
Fix a logical error and an ILLEGAL_COLUMN on json['key'] over a LowCardinality path - #119892
Conversation
`json['key']` on a `JSON` column whose typed path is a non-nullable `LowCardinality(T)` failed two ways. With a constant `Nullable(String)` key over a table column, the server hit `Unexpected return type from arrayElement. Expected LowCardinality(Nullable(T)). Got LowCardinality(T)` at the planner's partial-result fold (`ActionsDAG.cpp:1491`). `getReturnTypeImpl` promotes such a result with `makeExtractedSubcolumnsNullableOrLowCardinalityNullableSafe`, which puts the `Nullable` inside the dictionary, but the nullable-index branch of `executeImpl` spelled the matching column-side promotion in plain-`Nullable` terms: `DataTypeLowCardinality::isNullable()` is `false` and `removeNullable` does not descend into `LowCardinality`, so neither the strip nor the wrap happened and `executeJSON` returned the raw dictionary column. Nothing upstream repaired it, because `FunctionWithLowCardinalityFastPath` delegates only when an argument type carries `LowCardinality` or every argument is constant, and here the `LowCardinality` sits inside the `DataTypeObject`, which `recursiveRemoveLowCardinality` does not descend into. With an all-constant call the mixin does delegate, and the delegate's `LowCardinality` adapter strips the wrapper from `result_type` before dispatch, while `executeJSON` ignored its `result_type` and still returned a `ColumnLowCardinality`. Depending on the consumer that surfaced as `Invalid column type for ColumnUnique::insertRangeFrom` or as `LowCardinality(T) cannot be inside Nullable column`. Fix both by keeping the two sides of the promotion in the same vocabulary: hand the recursion `removeNullableOrLowCardinalityNullable(result_type)` and restore with `makeNullableOrLowCardinalityNullableSafe` when the declared result is LC-nullable, and let the extracted path drop its own `LowCardinality` when the caller asked for a type without one. `getReturnTypeImpl` is unchanged, and the result now matches `json.key` for every source and key shape. The first shape only ever appeared in randomized stress runs because `optimize_functions_to_subcolumns` (on by default, randomized 0/1 by `clickhouse-test`) rewrites the read to a subcolumn and casts it back to the declared type, hiding the mismatch. The regression test therefore pins the setting and keeps the enabled arm as a control. Co-Authored-By: Claude Opus 5 <[email protected]>
`recursiveRemoveLowCardinality` descends into `ColumnArray`, `ColumnTuple`, `ColumnMap`, `ColumnNullable` and `ColumnConst`, so it also stripped a `LowCardinality` nested inside the path's own type, which the declared result type keeps. `DataTypeArray`, `DataTypeMap` and `DataTypeTuple` all inherit `IDataType::lowCardinality() == false`, so the guard let those types through and the recursion then removed a wrapper they were entitled to: `json['arr']` on a `JSON(arr Array(LowCardinality(String)))` path produced `Array(String)` against a declared `Array(LowCardinality(String))`, aborting the same declared-vs-produced check this commit's parent set out to satisfy. The wrapper the caller removed is the top-level one: the `LowCardinality` adapter dispatches with `result_type`'s dictionary type, one level off. So remove exactly one level. Only `ColumnLowCardinality` and `ColumnConst` override `convertToFullColumnIfLowCardinality`, which leaves the container columns alone by construction rather than by a type test, and makes the narrowing inert on every shape that already worked: after `applyOuterNullMap` a promoted path is a top-level `ColumnLowCardinality` and is still converted. The regression test gains one column pair in the existing all-constant scenario. The table-column route reaches the same guard with the same `result_type`, and the guard reads only `result_type`, never the input column's shape or constness, so a second query there would add no coverage. Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model reviewReviewed cold against the resulting code, then re-reviewed by a second model, then adjudicated. Two Round 1 ❌
Round 2 Clean: no findings from either pass. I re-derived the two load-bearing claims myself rather than taking 💡 Kept as-is after checking: one commit per root cause; and |
Pre-PR validation gate (click to expand)
Verification: Session id: cron:clickhouse-impl-slot-40:20260914-054900 |
|
Workflow [PR], commit [597685f] Summary: ✅
AI ReviewSummaryThis PR fixes Missing context / blind spots
Final Verdict✅ No new review findings. LLVM Coverage ReportMeasured on commit 597685f.
Changed lines: Changed C/C++ lines covered: 15/16 (93.75%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 41 s compile time in total, 7 of them have a recent master baseline. |
|
@groeneai investigate integration tests failure. |
CI finish ledger - 45c16d7Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
How to read this head:
Session id: cron:our-pr-ci-monitor:20260914-133210 |
|
Investigated. Not caused by this PR: the diff is Docker Hub was denying Of those 3,308 rows, 3,306 are SKIPPED, one is OK, and exactly one is a red test: mine. The mechanism I want to fix is upstream of that: Separately, for whoever owns CI registry access: |
|
Fixing PR for the ledger's one open line: #120107. It stops the per-module |
…rayelement-json-nullable-key-lowcardinality
…rayelement-json-nullable-key-lowcardinality
Related: #107039
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Not required: the
json['key']overload this fixes is unreleased.Description
json['key']on aJSONcolumn whose typed path is a non-nullableLowCardinality(T)fails two ways:Nullable(String)key:Logical error: 'Unexpected return type from arrayElement. Expected LowCardinality(Nullable(IPv6)). Got LowCardinality(IPv6)', at the planner's partial-result fold (master CI report,query_ida68771de-1b69-44d3-a831-199f0ee3ef52);JSONsource:ILLEGAL_COLUMN(Invalid column type for ColumnUnique::insertRangeFrom, orcannot be inside Nullable column).getReturnTypeImplpromotes a nullable-key result withmakeExtractedSubcolumnsNullableOrLowCardinalityNullableSafe, which puts theNullableinside the dictionary, butexecuteImpl's nullable-index branch spelled the matching column-side promotion in plain-Nullableterms:DataTypeLowCardinality::isNullable()isfalseandremoveNullabledoes not descend into it, so neither the strip nor the wrap happened andexecuteJSONreturned the raw dictionary column. Separately, an all-constant call is dispatched with that wrapper already stripped fromresult_type, whileexecuteJSONstill returned aColumnLowCardinality.So: spell that branch's rule with the
LowCardinality-aware helpers, and let the extracted path drop its own wrapper when the caller asked for a type without one.getReturnTypeImplis unchanged, and the result now matchesjson.keyeverywhere I measured.The first shape only surfaces in randomized runs:
optimize_functions_to_subcolumns(default on, randomized in CI) rewrites the read to a subcolumn and casts it back, hiding the mismatch. The test pins it, with the enabled arm as a control.Noticed, not changed: the mixin's delegate guard tests argument types, so a
LowCardinalityresult with no such argument bypasses the adapter; harmless now that the function produces its declared type.Not for changelog: the bracket overload and its nullable-key support both landed on master on 2026-09-13, and no26.*release branch contains either. Relabel if you prefer.Workflow [PR]
Sync PR [sync-upstream/pr/119892]
Version info
26.10.1.86(included in26.10and later)