[MDEV-31411] JSON_ARRAY_INTERSECT/JSON_OBJECT_FILTER_KEYS should fetch data from a table similar to other JSON functions Created: 2023-06-06  Updated: 2023-11-02  Resolved: 2023-11-02

Status: Closed
Project: MariaDB Server
Component/s: JSON
Affects Version/s: 11.2
Fix Version/s: 11.2.2

Type: Bug Priority: Critical
Reporter: Ramesh Sivaraman Assignee: Rucha Deodhar
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
Relates
relates to MDEV-26182 Create a function to check for JSON i... Closed

 Description   

11.1.0-dbg>show create table t1;
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                                                                                          |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `c1` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`c1`)),
  `c2` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`c2`))
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)
 
11.1.0-dbg>
 
11.1.0-dbg>select c1,c2 from t1;
+--------------+----------------+
| c1           | c2             |
+--------------+----------------+
| [1, 2, 3, 4] | [3, 4, 5, 6  ] |
+--------------+----------------+
1 row in set (0.000 sec)
 
11.1.0-dbg>select @obj1,@obj2;
+--------------+----------------+
| @obj1        | @obj2          |
+--------------+----------------+
| [1, 2, 3, 4] | [3, 4, 5, 6  ] |
+--------------+----------------+
1 row in set (0.000 sec)
 
11.1.0-dbg>SELECT json_array_intersect(@obj1,@obj2);
+-----------------------------------+
| json_array_intersect(@obj1,@obj2) |
+-----------------------------------+
| [3, 4]                            |
+-----------------------------------+
1 row in set (0.000 sec)
 
11.1.0-dbg>
 
Actual Result
 
11.1.0-dbg>SELECT json_array_intersect(c1, c2) from t1;
+------------------------------+
| json_array_intersect(c1, c2) |
+------------------------------+
| NULL                         |
+------------------------------+
1 row in set (0.000 sec)
 
11.1.0-dbg>
 
Expected result
11.1.0-dbg>SELECT json_array_intersect(c1, c2) from t1;
+-----------------------------------+
| json_array_intersect(c1, c2) |
+-----------------------------------+
| [3, 4]                            |
+-----------------------------------+
1 row in set (0.000 sec)
 
11.1.0-dbg>
 
JSON_OBJECT_FILTER_KEYS
-------------------------------------------
11.1.0-dbg>insert into t1 values ('{ "a": 1, "b": 2, "c": 3}', '{"b" : 10, "c": 20, "d": 30}');
Query OK, 1 row affected (0.018 sec)
 
11.1.0-dbg>
 
Actual Result
 
11.1.0-dbg>SELECT JSON_OBJECT_FILTER_KEYS (c1, json_array_intersect(json_keys(c1), json_keys(c2))) from t1;
+----------------------------------------------------------------------------------+
| JSON_OBJECT_FILTER_KEYS (c1, json_array_intersect(json_keys(c1), json_keys(c2))) |
+----------------------------------------------------------------------------------+
| NULL                                                                             |
+----------------------------------------------------------------------------------+
1 row in set (0.000 sec)
 
11.1.0-dbg>
 
Expected result
 
11.1.0-dbg>SELECT JSON_OBJECT_FILTER_KEYS (c1, json_array_intersect(json_keys(c1), json_keys(c2))) from t1;
+----------------------------------------------------------------------------------+
| JSON_OBJECT_FILTER_KEYS (c1, json_array_intersect(json_keys(c1), json_keys(c2))) |
+----------------------------------------------------------------------------------+
| {"b": 2, "c": 3}                                                              |
+----------------------------------------------------------------------------------+
1 row in set (0.000 sec)
 
11.1.0-dbg>



 Comments   
Comment by Rucha Deodhar [ 2023-07-04 ]

Patch: https://github.com/MariaDB/server/tree/bb-11.2-MDEV-31411

Comment by Alexey Botchkov [ 2023-07-18 ]

see comments to the patch.

Comment by Rucha Deodhar [ 2023-09-18 ]

holyfoot
Oops ! Sorry, wrong branch. Check the correct patch here: bb-11.2-MDEV-31411-json_intersect

Comment by Alexey Botchkov [ 2023-10-08 ]

ok to push.

Comment by Rucha Deodhar [ 2023-11-02 ]

pushed to 11.2

Generated at Thu Feb 08 10:23:40 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.