Skip to content

[fix](doc) document json_extract no-auto-broadcast over arrays#3749

Merged
morningman merged 2 commits into
apache:masterfrom
boluor:fix-json-extract-array-semantics-3318
May 23, 2026
Merged

[fix](doc) document json_extract no-auto-broadcast over arrays#3749
morningman merged 2 commits into
apache:masterfrom
boluor:fix-json-extract-array-semantics-3318

Conversation

@boluor
Copy link
Copy Markdown
Contributor

@boluor boluor commented May 23, 2026

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):

  • `$.k` on an array returns NULL — no auto-broadcast
  • Use `$[i].k` for index access
  • Array-wildcard broadcasting via `$[*].k` was introduced in Doris 4.0 (the wildcard `continue` on 2.1/3.x does not actually iterate elements — also verified in branch source)
  • On 2.1 and 3.x, recommend `LATERAL VIEW EXPLODE` patterns for per-element extraction

Scope

8 files, +12 lines:

  • `docs/.../json-extract.md`
  • `versioned_docs/version-{2.1,3.x,4.x}/.../json-extract.md`
  • `i18n/zh-CN/.../{current,version-2.1,version-3.x,version-4.x}/.../json-extract.md`

No existing examples changed; no behavior change in the engine.

Test plan

  • Each of the 8 pages contains the new "no auto-broadcast" sentence
  • Dead-link check passes
  • Version-specific advice matches `findValue` source per branch

Closes #3318

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
@boluor boluor mentioned this pull request May 23, 2026
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>
@morningman morningman merged commit 6d8db7f into apache:master May 23, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue on docs

2 participants