[MDEV-30145] JSON_TABLE: allow to retrieve the key when iterating on JSON objects Created: 2022-12-02 Updated: 2023-07-25 Resolved: 2023-07-24 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | JSON |
| Fix Version/s: | 11.2.1 |
| Type: | Task | Priority: | Critical |
| Reporter: | Christian Proust | Assignee: | Rucha Deodhar |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | JSON_TABLE, Preview_11.2 | ||
| Issue Links: |
|
||||||||||||||||||||
| Description |
|
When iterating on a JSON objects, there is currently no way to retrieve the key allowing to access to the current object. As an example:
Will produce:
But there is no way to retrieve:
The proposal is to add, as for "FOR ORDINALITY", the "FOR KEY" clause that would allow to retrieve the key when doing:
Final Implementation: Implementing keyvalue() function as part of the path can become complicated. Because keyvalue() will "transform" an object. Now, having this keyvalue() in path means the path will "return" something instead of only leading to some character in the json document. Also, there are few more "path functions"in addition to keyvalue() so supporting function in path qualifies for a completely new task. As an alternative though, we can have a separate json function (JSON_KEY_VALUE(<json_doc>, <path>)) which transforms an object into key-value pairs and have the result that this function returns as an argument in JSON_TABLE(). Another reason to rather have a function:
|
| Comments |
| Comment by Sergei Golubchik [ 2023-02-06 ] | ||||
|
I suspect the standard solution would be to use keyvalue function, like (completely untested)
which is something we don't support yet | ||||
| Comment by Rucha Deodhar [ 2023-05-25 ] | ||||
|
After discussing with HF, decided that implementing keyvalue() function as part of the path can become complicated. Because keyvalue() will transform an object, which means the path will "return" something instead of only leading to some character in the json. Also, we more functions in addition to keyvalue() so supporting function in path qualifies for a completely new task. Also this function can be used else where if needed and not restricted to path. Having what the description says ( key as a separate column, like key_list FOR KEY ) will also restrict it to json table. Let me know what you think. Sergei approved. Because it doesn't introduce a new non-standard syntax and it is consistent with what we're doing already (There is also type() function in standards, and we have JSON_TYPE() as equivalent). | ||||
| Comment by Rucha Deodhar [ 2023-05-26 ] | ||||
|
Patch: https://github.com/MariaDB/server/tree/bb-11.2-MDEV-30145 | ||||
| Comment by Alexey Botchkov [ 2023-06-07 ] | ||||
|
A couple of things to fix. | ||||
| Comment by Alexey Botchkov [ 2023-06-12 ] | ||||
|
still one comment to fix. | ||||
| Comment by Ramesh Sivaraman [ 2023-07-19 ] | ||||
|
okay to push |