[fix](function) Reject even argument count of json_set/json_insert/json_replace at analysis time - #67804
Open
mrhhsg wants to merge 1 commit into
Open
[fix](function) Reject even argument count of json_set/json_insert/json_replace at analysis time#67804mrhhsg wants to merge 1 commit into
mrhhsg wants to merge 1 commit into
Conversation
…n_replace at analysis time
### What problem does this PR solve?
Issue Number: None
Problem Summary:
`json_set`, `json_insert` and `json_replace` (and their `jsonb_*` aliases) take a
JSON document followed by path/value pairs, so the argument count must be odd.
The FE only checked `arity >= 3`, so a call whose last path had no value, e.g.
`json_set('{}', '$.a', 1, '$.b')`, passed analysis and `EXPLAIN` succeeded. The
error was only raised by the BE at execution time:
```
[INVALID_ARGUMENT]Function jsonb_set must have an odd number of arguments and more than 2 arguments, but got: 4
```
The total argument count is known at analysis time, so this PR adds
`checkLegalityBeforeTypeCoercion` to the three functions and rejects an even
argument count with a clear `AnalysisException` before type coercion and the
`to_json` rewrite. The BE check is kept as a defensive fallback.
### Release note
None
### Check List (For Author)
- Test:
- Unit Test: `CheckExpressionLegalityTest#testJsonModifyFunctionsRejectEvenArity`
- Regression test: `test_query_json_set`, `test_query_json_insert`, `test_query_json_replace`
(4/6-argument rejection including `EXPLAIN` and the `jsonb_*` aliases, legal 3/5-argument calls)
- Behavior changed: Yes (an even argument count is now rejected during FE analysis instead of failing at BE execution)
- Does this need documentation: No
Claude-Session: https://claude.ai/code/session_016LqgBtqMHamfbXB2sCDnuu
Member
Author
|
/review |
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
There was a problem hiding this comment.
Review result: no blocking issues found.
Critical checkpoint conclusions:
- Goal and proof: The change rejects even total arity for
json_set/json_insert/json_replaceduring Nereids analysis, before signature coercion and the value-to-JSON rewrite. The FE unit test covers all six canonical/alias names at invalid arities 4/6 and legal arities 3/5; regression cases cover normal queries, EXPLAIN, aliases, legal execution, and matching generated outputs. - Scope and clarity: The production change is a focused O(1) parity guard in the three parallel scalar classes and uses the correct Nereids
AnalysisExceptionboundary. - Conditions and parallel paths: The predicate matches the documented JSON-document-plus-path/value-pairs shape. All three functions and
jsonb_*aliases bind to these classes; direct-bound and EXPLAIN paths use the same pre-coercion hook, and no count-changing alternate rewrite was found. - Compatibility: The existing FE 3-argument constructor minimum plus the new odd-arity guard exactly matches BE
FunctionJsonbModify. The BE runtime guard remains in place for mixed-version or defensive fallback behavior; no protocol, symbol, or storage-format change is introduced. - Concurrency, lifecycle, configuration, persistence, transactions, data writes, and FE-BE variable passing: Not involved by this analysis-only change.
- Test and result review: Negative cases use the required test/exception form; the asserted FE wording is distinct from the BE runtime error, so the oracle proves analysis-time rejection. The new single-row outputs are deterministic and consistent with insert/set/replace semantics. Tests were reviewed but not executed locally because this automated review environment prohibits builds/test runs; current GitHub CheckStyle and repository hygiene checks are passing.
- Observability and performance: The error includes function context, actual arity, and SQL text; no additional metrics/logging are warranted. Runtime performance is unchanged, and analysis adds only a constant-time check.
- Additional concerns: No substantiated correctness, compatibility, performance, or coverage issue remained after the main sweep and three independent Round 1 reviews.
User focus: No additional user-provided review focus was supplied; the full PR was reviewed.
Review status: Complete for head 83ae1facb891353ccbba1601be85ab5736421362; Round 1 converged with NO_NEW_VALUABLE_FINDINGS from every required subagent.
mrhhsg
marked this pull request as ready for review
September 11, 2026 02:02
mrhhsg
requested review from
924060929,
englefly,
morrySnow and
starocean999
as code owners
September 11, 2026 02:02
Member
Author
|
run buildall |
Contributor
FE UT Coverage ReportIncrement line coverage |
Contributor
TPC-H: Total hot run time: 16746 ms |
Contributor
TPC-DS: Total hot run time: 81575 ms |
Contributor
ClickBench: Total hot run time: 14.56 s |
morrySnow
approved these changes
Sep 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
Issue Number: None
Problem Summary:
json_set,json_insertandjson_replace(and theirjsonb_*aliases) take aJSON document followed by path/value pairs, so the argument count must be odd.
The FE only checked
arity >= 3, so a call whose last path had no value, e.g.json_set('{}', '$.a', 1, '$.b'), passed analysis andEXPLAINsucceeded. Theerror was only raised by the BE at execution time:
The total argument count is known at analysis time, so this PR adds
checkLegalityBeforeTypeCoercionto the three functions and rejects an evenargument count with a clear
AnalysisExceptionbefore type coercion and theto_jsonrewrite. The BE check is kept as a defensive fallback.Release note
None
Check List (For Author)
CheckExpressionLegalityTest#testJsonModifyFunctionsRejectEvenAritytest_query_json_set,test_query_json_insert,test_query_json_replace(4/6-argument rejection including
EXPLAINand thejsonb_*aliases, legal 3/5-argument calls)https://claude.ai/code/session_016LqgBtqMHamfbXB2sCDnuu