[fix](doc) document json_extract no-auto-broadcast over arrays#3749
Merged
morningman merged 2 commits intoMay 23, 2026
Merged
Conversation
Issue apache#3318: a user upgrading from Doris 2.0.2 to 2.1.11 noticed the same SQL returned different results: `json_extract('<array-of-objects>', '$.k')` returned `[v1, v2, ...]` on 2.0.2 but `NULL` on 2.1.11. The 2.1+ behavior is intentional and engine-correct, aligning with MySQL's `JSON_EXTRACT` semantics: `$.k` traverses only object members and does not auto-broadcast over array elements. Verified in `be/src/util/jsonb_document.h::findValue` (MEMBER_CODE returns nullptr when pval is not an object) on `branch-2.1`, `branch-3.0`, `branch-3.1`, `branch-4.0`, `branch-4.1`. Doc did not previously call this out. Add a line to each of the 8 maintained version json-extract pages (current/2.1/3.x/4.x, EN + zh) explaining: - `$.k` on an array returns NULL — no auto-broadcast - Use `$[i].k` for index access - Array-wildcard broadcasting via `$[*].k` was introduced in 4.0 (the wildcard `continue` on 2.1/3.x does not actually iterate elements — verified by reading `findValue` on each release branch) - For 2.1/3.x, suggest `LATERAL VIEW EXPLODE` patterns for per-element extraction Closes apache#3318
Closed
Issue apache#3318 reports that json_extract returns NULL when $.k is applied over a JSON array, with no clear path to the broadcasted result the user wants. The existing description note explains $[*].k as the 4.0+ solution but provides no runnable example. Add example 11 to the current and 4.x docs (EN + zh) contrasting $.k (NULL) and $[*].k (broadcasted array). Outputs verified against a 4.x cluster. Not added to 2.1/3.x docs since $[*].k returns NULL there too — the description already notes "supported from Doris 4.0 onward". Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Fixes #3318. A user upgrading from Doris 2.0.2 to 2.1.11 reported that the same SQL changed result:
```sql
SELECT json_extract(product_specific, '$.categoryId')
FROM ods_product_goods_full;
-- product_specific is varchar holding e.g. [{"categoryId":1000},{"categoryId":1003},...]
-- 2.0.2 returned [1000,1003,1006,1012,2,1015]
-- 2.1.11 returns NULL
```
The 2.1+ behavior is intentional and engine-correct: `$.k` traverses only object members and does not auto-broadcast over array elements (aligning with MySQL's `JSON_EXTRACT` semantics). Verified in `be/src/util/jsonb_document.h::findValue` on `branch-2.1`, `branch-3.0`, `branch-3.1`, `branch-4.0`, `branch-4.1`: the `MEMBER_CODE` case returns `nullptr` when `pval` is not a `T_Object`.
The doc previously did not call this out. This PR adds a single line to the path-syntax section on each of the 8 maintained version pages (current/2.1/3.x/4.x EN+zh):
Scope
8 files, +12 lines:
No existing examples changed; no behavior change in the engine.
Test plan
Closes #3318