boluor commented on issue #3318:
URL: https://github.com/apache/doris-website/issues/3318#issuecomment-4524361000

   Thanks for the careful version-to-version comparison! The change you 
observed between 2.0.2 and 2.1.11 is intentional engine behavior, not a 
regression: `$.k` no longer auto-broadcasts over arrays, aligning with MySQL's 
`JSON_EXTRACT` semantics. Verified in 
[`be/src/util/jsonb_document.h::findValue`](https://github.com/apache/doris/blob/branch-2.1/be/src/util/jsonb_document.h)
 — the `MEMBER_CODE` case only descends when the current value is a `T_Object`; 
on an array it returns `nullptr` (NULL).
   
   The doc didn't previously call this out, so users have no way to know 
whether the new result is a bug or intended. PR #3749 adds a one-line 
clarification to all 8 maintained-version `json-extract` pages 
(current/2.1/3.x/4.x, EN + zh).
   
   For your specific query on 2.1.11, the workarounds are:
   1. `SELECT json_extract(product_specific, '$[0].categoryId')` if you only 
need a known index.
   2. For per-element extraction over the whole array on 2.1/3.x, use `LATERAL 
VIEW EXPLODE` to expand the JSON array first, then `json_extract` per row. 
Example:
      ```sql
      SELECT je.categoryId
      FROM ods_product_goods_full t
      LATERAL VIEW EXPLODE_JSON_ARRAY_JSON(t.product_specific) lv AS elem
      LATERAL VIEW INLINE (json_extract(elem, '$.categoryId')) je AS categoryId;
      ```
   3. On Doris 4.0+, `$[*].categoryId` correctly broadcasts and returns 
`[1000,1003,...]` in a single call (the wildcard `continue` on 2.1/3.x doesn't 
actually iterate, which is why `$[*].k` returns NULL on those branches too).
   
   Closing once PR #3749 merges. cc @KassieZ


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to