Details
-
Task
-
Status: Closed (View Workflow)
-
Minor
-
Resolution: Fixed
Description
Creating a function that checks for intersection between objects would be really helpful.
For example, if we have the following 2 objects:
{'a': '1', 'b': '1', 'c': '1', 'd': '1'} {'b': '1', 'd': '1'}And we would like to find/check for the intersection between them, we do not have a way to achieve that.
This post (https://stackoverflow.com/questions/44687872/find-intersection-of-mysql-json-objects-or-arrays) on Stackoverflow.com can possibly explain what I mean.
Final Implementation:
The idea was to have simple functions that the user can combine to produce the exact result one wants. Having two object how do we know what the user desires - to get the intersection for same keys, or same key/value pairs.
If objects have same key with an array as a value - does the user need the value of the first object, or the second or the intersection of these arrays? WE can't know for sure, and having small exact functions allows user to combine them to get what they need.
Hence tweaked the implementation made by gsoc student a little and also added more json functions. So Now we have:
- JSON_ARRAY_INTERSECT() : Find intersection between two jsons of array type,
- JSON_OBJECT_FILTER_KEYS(): This will take two args. first will be an object and second will be array. It will output those key-value pairs from json object that are there in the array.
- JSON_OBJECT_TO_ARRAY(Obj) : Converts key-value pairs in the outer most level to array.
Idea: Alexey Botchkov
Implementation: Ruixiang Tan and Rucha Deodhar
Attachments
Issue Links
- causes
-
MDEV-33149 JSON_ARRAY_INTERSECT function crashes the server when called with empty json arrays, UBSAN runtime error: member access within null pointer of type 'struct String' in Item_func_json_array_intersect::prepare_json_and_create_hash
- Confirmed
- relates to
-
MDEV-31411 JSON_ARRAY_INTERSECT/JSON_OBJECT_FILTER_KEYS should fetch data from a table similar to other JSON functions
- Closed
-
MDEV-31543 ASAN heap-buffer-overflow in strncpy when fetching keys using JSON_OBJECT_FILTER_KEYS function
- Closed