Skip to content

Fix JSON_QUERY/JSON_VALUE/JSON_EXISTS returning Dynamic instead of String/UInt8 on Dynamic arguments - #106877

Merged
Avogar merged 4 commits into
masterfrom
fix-json-query-dynamic-return-type
Jul 9, 2026
Merged

Avogar merged 4 commits into
masterfrom
fix-json-query-dynamic-return-type

Conversation

@Avogar

@Avogar Avogar commented Jun 9, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix JSON_QUERY/JSON_VALUE/JSON_EXISTS returning Dynamic instead of String/UInt8 on Dynamic arguments. Closes: #106461.

Version info

  • Merged into: 26.7.1.714 (included in 26.7 and later)

… of their declared types when input is Dynamic

Override `getReturnTypeForDefaultImplementationForDynamic` in `FunctionSQLJSON`
so that the `FunctionBaseDynamicAdaptor` uses the correct fixed return type
(`String` for `JSON_QUERY`/`JSON_VALUE`, `UInt8` for `JSON_EXISTS`) instead of
falling back to Dynamic.

Closes: #106461

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@Avogar Avogar changed the title Fix JSON_QUERY/JSON_VALUE/JSON_EXISTS returning Dynamic instead of String on Dynamic arguments Fix JSON_QUERY/JSON_VALUE/JSON_EXISTS returning Dynamic instead of String/UInt8 on Dynamic arguments Jun 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2e3e096]

Summary: ❌

job_name test_name status info comment
AST fuzzer (amd_debug, targeted) FAIL
Logical error: Cannot convert nested result of function A with type B to the expected result type C: D (STID: 4811-66fc) FAIL cidb
AST fuzzer (amd_debug, targeted, old_compatibility) FAIL
Logical error: Cannot convert nested result of function A with type B to the expected result type C: D (STID: 4811-66fc) FAIL cidb

AI Review

Summary

This PR fixes the Dynamic adaptor so JSON_QUERY, JSON_VALUE, and JSON_EXISTS can declare an argument-shaped result type instead of falling back to Dynamic, including the tuple/array multi-path cases raised in the prior inline thread. I checked the current patch against the surrounding adaptor logic and the added stateless coverage, and I did not find a new correctness, compatibility, or safety issue in the current code.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 9, 2026
Comment thread src/Functions/FunctionSQLJSON.h Resolved
Avogar and others added 2 commits June 25, 2026 13:51
…:ClickHouse/ClickHouse into fix-json-query-dynamic-return-type
`FunctionSQLJSON` return type depends on argument types (multi-path
Tuple/Array paths produce nested return types). The no-argument
`getReturnTypeForDefaultImplementationForDynamic` could not account
for this, returning wrong types when Dynamic input was combined with
multi-path arguments.

Add a new virtual overload that accepts `const DataTypes &` and
defaults to delegating to the existing no-argument version, so all
128+ existing overrides are unaffected. `FunctionBaseDynamicAdaptor`
now calls the argument-aware version.

Related: #106461
Related: #106877

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@serxa serxa self-assigned this Jun 26, 2026
…:ClickHouse/ClickHouse into fix-json-query-dynamic-return-type
@clickhouse-gh

clickhouse-gh Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.90% 85.80% -0.10%
Functions 92.70% 92.70% +0.00%
Branches 78.00% 78.00% +0.00%

Changed lines: Changed C/C++ lines covered: 31/33 (93.94%) · Uncovered code

Full report · Diff report

@Avogar
Avogar added this pull request to the merge queue Jul 9, 2026
Merged via the queue into master with commit 17dd822 Jul 9, 2026
172 of 175 checks passed
@Avogar
Avogar deleted the fix-json-query-dynamic-return-type branch July 9, 2026 14:01
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 9, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Jul 10, 2026
…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]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…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]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
`FunctionSQLJSON` return type depends on argument types (multi-path
Tuple/Array paths produce nested return types). The no-argument
`getReturnTypeForDefaultImplementationForDynamic` could not account
for this, returning wrong types when Dynamic input was combined with
multi-path arguments.

Add a new virtual overload that accepts `const DataTypes &` and
defaults to delegating to the existing no-argument version, so all
128+ existing overrides are unaffected. `FunctionBaseDynamicAdaptor`
now calls the argument-aware version.

Related: ClickHouse#106461
Related: ClickHouse#106877

Co-Authored-By: Claude Opus 4.6 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ynamic-return-type

Fix `JSON_QUERY`/`JSON_VALUE`/`JSON_EXISTS` returning Dynamic instead of String/UInt8 on Dynamic arguments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect type returned from JSON_QUERY for Dynamic input

3 participants