Repository navigation
Fix JSON_EXISTS/JSON_VALUE/JSON_QUERY LOGICAL_ERROR on Dynamic input with LowCardinality path elements - #109944
Conversation
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-5:20260709-221300 |
|
cc @Avogar — this fixes a LOGICAL_ERROR introduced by #106877 (JSON_* return concrete types over Dynamic) when a multi-path argument contains a |
|
Workflow [PR], commit [367cd4b] Summary: ❌
AI ReviewSummaryThis PR fixes the Dynamic-only return-type mismatch in Final Verdict✅ No new findings. The two earlier bot threads are addressed in the current code and both are now resolved. |
0ad3249 to
d02f0d4
Compare
|
Follow-up push (head d02f0d4) generalizes the fix: the earlier version only stripped LowCardinality on leaves and still aborted when the multi-path argument arrived wrapped in Nullable, which is the common case for a scalar subquery Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-2:20260710-083600 |
…path arg STID 4811-66fc (AST fuzzer). ClickHouse#106877 declared concrete result types over Dynamic input via getReturnTypeForDefaultImplementationForDynamic, but the Dynamic path received the raw path-argument type while the normal path only sees the type after the framework has stripped wrappers. The framework normalizes the second argument before executeImpl/buildPlan exactly one way: LowCardinality is removed recursively (defaultImplementationForLowCardinalityColumns), while Nullable is removed only at the top level (createBlockWithNestedColumns keeps any Nullable nested inside a Tuple/Array). Mirror that in the return-type helpers via normalizePathArgument, and recurse with the same bare-String/Tuple/Array acceptance the runtime plan uses, so the declared return type always agrees with what the plan accepts and produces. Nested wrapped path nodes (e.g. a scalar subquery producing Nullable(Tuple(...)) nested inside an outer tuple) are rejected as non-path types, identically on the normal and Dynamic paths. Related: ClickHouse#106877, ClickHouse#106461. Co-Authored-By: Claude Opus 4.8 <[email protected]>
d02f0d4 to
73f3a77
Compare
|
Good catch. Fixed in 73f3a77 by taking your second option: the return-type helpers now strip wrappers exactly the way the framework strips them before Concretely, Your repro now behaves identically on the Dynamic and the normal path: Regression coverage added to |
CI finish ledger — 73f3a77Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Not PR-caused: this PR only touches Session id: cron:our-pr-ci-monitor:20260710-140000 |
|
@Avogar could you take a look when you have a moment? This fixes the master-wide |
…regression
SELECT JSON_EXISTS(CAST('{"a":1}','Dynamic'), tuple(toLowCardinality('$.a')))
is the exact fuzzer-minimized repro from ClickHouse#110345, the single-element case of
the LowCardinality tuple-path family already fixed by normalizePathArgument
(recursiveRemoveLowCardinality). Covered here for direct traceability.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
CI finish ledger — c3d6927Every failure below has an owner: a fixing PR (ours or external). Only
The IT failure is the chronic flaky Session id: cron:our-pr-ci-monitor:20260715-010000 |
Avogar
left a comment
There was a problem hiding this comment.
The fix is in the wrong place. We should fix it in getReturnTypeForDynamic, smth like:
static DataTypePtr getReturnTypeForDynamic(const DataTypes & arguments, bool)
{
if (arguments.size() >= 2)
{
/// The SQL JSON functions use default implementation for Nullable/LowCardinality, but in case of Dynamic adaptor they are not executed yet, so we need to remove Nullable and LowCardinality here.
auto path = removeNullable(recursiveRemoveLowCardinality(arguments[1]));
if (isMultiPathType(path))
return buildReturnType(path, std::make_shared<DataTypeUInt8>());
}
return std::make_shared<DataTypeUInt8>();
}But with better phrased comment
…eForDynamic Per review: confine the wrapper stripping to the Dynamic return-type helpers (getReturnTypeForDynamic), where the framework has not yet removed Nullable/LowCardinality, instead of altering the shared isMultiPathType/ buildReturnType helpers. The shared helpers now operate on raw types, matching MultiPathExecutor::buildPlan and the normal (non-Dynamic) path where the framework strips wrappers before we are called. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Done in 1f36c82. Moved the Verified declared == executed across the input matrix on both paths (literal tuple, LC leaves, top-level scalar-subquery |
Avogar
left a comment
There was a problem hiding this comment.
Changes isMultiPathType -> isMultiPathTypeImple and buildReturnType -> buildReturnTypeImpl now seems not needed, revert them.
Also, clean up boated comments, they are too big and mostly useless
|
Agreed on both. Reverting the |
Per review: isMultiPathType/buildReturnType no longer need the *Impl split now that the Nullable/LowCardinality stripping lives in getReturnTypeForDynamic via normalizeDynamicPathArgument, so restore the originals unchanged from master. Trim the oversized comments. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Done in 367cd4b:
Verified on a debug build: original repros return (1,0)/(0), the nested-wrapped case throws |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 18/19 (94.74%) · Uncovered code |
CI finish ledger — 367cd4bEvery failure below has an owner: a fixing PR, or a full-effort fix task whose fixing-PR link will be posted here when it opens. None are caused by this PR (getReturnTypeForDynamic Nullable/LowCardinality normalization + comment trim).
Session id: cron:our-pr-ci-monitor:20260724-020000 |
|
Fixing PR for the Upgrade-check |
a2752fa
|
Hi @groeneai @Avogar — while reviewing this PR I found the following:
Could you review the test PR and add the |
|
Fixing PR for the Mechanism, since the ledger reason ("flaky") does not say much: the failure was not an ordering bug in the server but a readiness race in the test helper. The integration harness reports an instance as started as soon as a bare That also closes #111782. |
|
@alexey-milovidov could you apply
SELECT JSON_EXISTS('{"a": 1, "b": 2}'::Dynamic, tuple('$.a', '$.b'));26.6 and 26.3 have no The cherry-pick is clean: all three files this PR touched are byte-identical at 26.7 and at |
…ultipath-107585 Fix JSON_EXISTS/JSON_VALUE/JSON_QUERY LOGICAL_ERROR on Dynamic input with LowCardinality path elements
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Description
Closes: #110345 (single-element
tuple(toLowCardinality('$.a'))variant, same family).Related: #106877 (introduced this on master), #106461.
Master-only regression: #106877 merged into master on 2026-07-09, after the latest published release lines, so this is not misbehavior in an official stable release.
Found by the AST fuzzer (STID 4811-66fc). Reproducer:
aborted in debug/sanitizer builds with:
CI report (Stress test amd_tsan): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107585&sha=d74d9153a382&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29
Root cause. #106877 made
JSON_*functions declare a concrete result type overDynamicarguments viagetReturnTypeForDynamic. On the normal (non-Dynamic) path the framework stripsNullable/LowCardinalityfrom arguments beforegetReturnTypeImpl, but on the Dynamic path the adaptor has not stripped them yet, so raw wrapped path elements (e.g.LowCardinality(String), or aNullable(Tuple(...))from a scalar subquery) were not recognized as multi-path. The declared type collapsed to the scalar case while actual execution (on stripped arguments) produced the multi-pathTuple(UInt8, ...).FunctionDynamicAdaptorcould not reconcile declared vs executed and aborted withLOGICAL_ERROR.Fix. Normalize the path argument (
removeNullable(recursiveRemoveLowCardinality(...)), mirroring exactly what the framework strips before execution) insidegetReturnTypeForDynamicfor eachJSON_*impl, so the declared Dynamic return type matches what execution produces. The sharedisMultiPathType/buildReturnTypehelpers operate on raw types, matchingMultiPathExecutor::buildPlan. Regression coverage in04325_sql_json_functions_with_dynamic_input(literal tuple,LowCardinalityleaves, top-level scalar-subqueryNullable(Tuple), nested-wrapped rejected consistently on both paths,JSON_VALUE/JSON_QUERY,Array).Version info
26.8.1.85(included in26.8and later)