Repository navigation
Fix LOGICAL_ERROR in flattenTuple for inputs with no scalar leaves - #104989
antonio2368 merged 4 commits into
Conversation
`flattenTuple` recursively expands nested tuples and arrays into scalar columns. When the input type tree contained only empty `Tuple()` leaves (directly, or wrapped in any combination of `Tuple` / `Array`), the recursion produced zero scalar columns. The result then reached `ColumnTuple::create` with an empty column list, which is guarded by a `LOGICAL_ERROR` and aborts the server in debug builds. The check that already rejects an empty top-level tuple does not catch inputs whose flatten result happens to be empty (for example `Tuple(c0 Array(Tuple()))` or `Tuple(c0 Tuple(c00 Tuple()))`). Detect the empty-flatten case in `getReturnTypeImpl` and throw `ILLEGAL_TYPE_OF_ARGUMENT` with a user-readable message that names the offending input type. Reproduced as a `function_prop_fuzzer` finding routed by @alexey-milovidov via the CI thread of ClickHouse#100272.
|
Pre-PR validation self-assessment (TASK.md Phase 4 Step 9) (a) Deterministic repro? Yes. (b) Root cause explained? Yes. (c) Fix matches root cause? Yes. (d) Test intent preserved? / New test added? New regression test
It also re-asserts that valid usage still flattens: (e) Demonstrated in both directions? Yes.
(f) Fix is general, not a narrow patch?
|
|
cc @alexey-milovidov @rschu1ze — could you review? Closes the |
|
Workflow [PR], commit [8445673] Summary: ❌
AI ReviewSummaryThis PR adds a guard in Final VerdictStatus: ✅ Approve |
The previous `.sql` form relied on `{ serverError ILLEGAL_TYPE_OF_ARGUMENT }`
directives, but on master HEAD (without the fix) the bug-triggering
queries reach the `LOGICAL_ERROR` guard in `ColumnTuple::create` and
abort the server under `abort_on_logical_error = true` (the default
in CI test environments). The bugfix-validation framework saw the
parent server crash as `ERROR` / `SERVER_DIED` and reported "Failed
to reproduce the bug" because that result is not invertible.
This commit wraps the bug-triggering queries in a `.sh` script that
runs each query inside a `clickhouse-local` subprocess. The abort
on master HEAD now stays contained: `clickhouse-local` returns a
non-43 exit code, the script prints `BUG`, the output diff fails,
and the bugfix-validation framework can invert that `FAIL` into a
"bug reproduced" signal. On the PR branch the queries return
`ILLEGAL_TYPE_OF_ARGUMENT` (Code 43) cleanly and the script prints
`OK`.
See PR ClickHouse#104861 for an earlier example of this `.sh` wrapper pattern
for a contained-abort regression test.
Session: cron:clickhouse-ci-task-worker:20260516-114500
|
Pushed Root cause. The previous Fix. Convert the test to a
Verified locally against the master binary: 6 This mirrors the wrapper pattern used in PR #104861 for the partition-pruner |
|
This was fixed by #105146. Let's update the branch. |
|
@groeneai please merge with master |
|
@antonio2368 Done — merged
Ready to merge once the new CI run is green. Thanks for the review! — Session: cron:clickhouse-ci-task-worker:20260518-110000 |
LLVM Coverage Report
Changed lines: 83.33% (10/12) · Uncovered code |
8bd43ac
flattenTuplerecursively expands nested tuples and arrays into theunderlying scalar columns. When the input type tree contained only
empty
Tuple()leaves (directly, or wrapped in any combination ofTuple/Array), the recursion produced zero scalar columns, theresult reached
ColumnTuple::createwith an empty column list, and thedefensive
LOGICAL_ERRORguard inColumnTuple::createaborted theserver in debug builds.
The check at the top of
FunctionFlattenTuple::getReturnTypeImplalready rejects an empty top-level tuple, but it does not catch inputs
whose flatten result happens to be empty, e.g.
Tuple(c0 Array(Tuple())),Tuple(c0 Tuple()),Tuple(c0 Tuple(c00 Tuple())), orTuple(c0 Array(Array(Tuple()))),including the same shapes wrapped in
Nullable.After this change,
getReturnTypeImplruns the flatten on the inputtype and validates that the result has at least one element; otherwise
it throws
ILLEGAL_TYPE_OF_ARGUMENTwith a user-readable message thatnames the offending input type. Reachable shapes that already have at
least one scalar leaf (e.g.
Tuple(c0 Int32, c1 Array(Tuple()))) areunchanged.
Routed by @alexey-milovidov from the CI thread of
#100272 as a
function_prop_fuzzerfinding. Same class as previously-fixed emptytuple constructions in
reverse(#89137) andarrayIntersect(#72578), but for the
flattenTuplecode path which had no equivalentguard.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
flattenTupleno longer raises aLOGICAL_ERRORwhen called on a tuple whose nested structure contains only emptyTuple()leaves (e.g.Tuple(c0 Array(Tuple()))orTuple(c0 Tuple())). Such inputs now produce a user-facingILLEGAL_TYPE_OF_ARGUMENTexception explaining that the flatten result would be an empty tuple.Documentation entry for user-facing changes
Session: cron:clickhouse-ci-task-worker:20260514-231500
Version info
26.5.1.755