Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json function is not compatible with Mysql #22525

Closed
Tracked by #36993
hequn8128 opened this issue Jan 26, 2021 · 2 comments · Fixed by #37074
Closed
Tracked by #36993

Json function is not compatible with Mysql #22525

hequn8128 opened this issue Jan 26, 2021 · 2 comments · Fixed by #37074
Assignees
Labels
affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 component/json severity/major sig/execution SIG execution type/bug This issue is a bug.

Comments

@hequn8128
Copy link

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

2. What did you expect to see? (Required)

mysql version: 8.0.23

mysql> select json_extract( '[ { "a": [3,4] }, { "b": 2 } ]', '$[*].a' ) jdoc;
+----------+
| jdoc     |
+----------+
| [[3, 4]] |
+----------+
1 row in set (0.00 sec)

mysql> select json_extract( '[ { "a": 1 }, { "b": 2 } ]', '$[*].a' ) jdoc;
+------+
| jdoc |
+------+
| [1]  |
+------+
1 row in set (0.00 sec)

mysql> SELECT JSON_EXTRACT
    -> (
    -> '{ "a" : "foo", "b" : [ true, { "c" : 123 } ] }',
    -> '$.b[ 1 ].'
    -> );
ERROR 3143 (42000): Invalid JSON path expression. The error is around character position 9.

mysql> SELECT JSON_EXTRACT
    -> (
    -> '{ "a" : [ }',
    -> '$.b[ 1 ].c'
    -> );
ERROR 3141 (22032): Invalid JSON text in argument 1 to function json_extract: "Invalid value." at position 10.

mysql> SELECT JSON_EXTRACT('[1,2,[3,4,[5,6,{"a":7}]]]', '$**[*]**[0]');
+----------------------------------------------------------+
| JSON_EXTRACT('[1,2,[3,4,[5,6,{"a":7}]]]', '$**[*]**[0]') |
+----------------------------------------------------------+
| [1, 2, 3, 4, 5, 6, {"a": 7}, 7]                          |
+----------------------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT JSON_EXTRACT('[[0,1],[2,3],[4,[5,6]]]', '$**[0]');
+---------------------------------------------------+
| JSON_EXTRACT('[[0,1],[2,3],[4,[5,6]]]', '$**[0]') |
+---------------------------------------------------+
| [[0, 1], 0, 1, 2, 3, 4, 5, 6]                     |
+---------------------------------------------------+
1 row in set (0.00 sec)

mysql> select json_extract( '[1]', '$**[0]' );
+---------------------------------+
| json_extract( '[1]', '$**[0]' ) |
+---------------------------------+
| [1]                             |
+---------------------------------+
1 row in set (0.00 sec)

mysql> select json_object( null, 1 );
ERROR 3158 (22032): JSON documents may not contain NULL member names.

3. What did you see instead (Required)

mysql> select json_extract( '[ { "a": [3,4] }, { "b": 2 } ]', '$[*].a' ) jdoc;
+--------+
| jdoc   |
+--------+
| [3, 4] |
+--------+
1 row in set (0.00 sec)

mysql> select json_extract( '[ { "a": 1 }, { "b": 2 } ]', '$[*].a' ) jdoc;
+------+
| jdoc |
+------+
| 1    |
+------+
1 row in set (0.00 sec)

mysql> SELECT JSON_EXTRACT
    -> (
    -> '{ "a" : "foo", "b" : [ true, { "c" : 123 } ] }',
    -> '$.b[ 1 ].'
    -> );
+--------------------------------------------------------------------------------+
| JSON_EXTRACT
(
'{ "a" : "foo", "b" : [ true, { "c" : 123 } ] }',
'$.b[ 1 ].'
) |
+--------------------------------------------------------------------------------+
| {"c": 123}                                                                     |
+--------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT JSON_EXTRACT
    -> (
    -> '{ "a" : [ }',
    -> '$.b[ 1 ].c'
    -> );
ERROR 3140 (22032): Invalid JSON text: The document root must not be followed by other values.

mysql> SELECT JSON_EXTRACT('[1,2,[3,4,[5,6,{"a":7}]]]', '$**[*]**[0]');
+--------------------------------------------------------------------------------------+
| JSON_EXTRACT('[1,2,[3,4,[5,6,{"a":7}]]]', '$**[*]**[0]')                             |
+--------------------------------------------------------------------------------------+
| [1, 2, 3, 3, 4, 5, 5, 6, {"a": 7}, 7, 3, 4, 5, 5, 6, {"a": 7}, 7, 5, 6, {"a": 7}, 7] |
+--------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT JSON_EXTRACT('[[0,1],[2,3],[4,[5,6]]]', '$**[0]');
+---------------------------------------------------+
| JSON_EXTRACT('[[0,1],[2,3],[4,[5,6]]]', '$**[0]') |
+---------------------------------------------------+
| [[0, 1], 0, 0, 1, 2, 2, 3, 4, 4, 5, 5, 6]         |
+---------------------------------------------------+
1 row in set (0.00 sec)

mysql> select json_extract( '[1]', '$**[0]' );
+---------------------------------+
| json_extract( '[1]', '$**[0]' ) |
+---------------------------------+
| [1, 1]                          |
+---------------------------------+
1 row in set (0.00 sec)

mysql> select json_object( null, 1 );
ERROR 1105 (HY000): JSON documents may not contain NULL member names

4. What is your TiDB version? (Required)

mysql> SELECT tidb_version();
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                                              |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v4.0.0-beta.2-2047-g0aa476034
Edition: Community
Git Commit Hash: 0aa476034ae8a69040ab2b4fe455114ba0e21695
Git Branch: master
UTC Build Time: 2021-01-26 02:15:59
GoVersion: go1.15.6
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
@hequn8128 hequn8128 added the type/bug This issue is a bug. label Jan 26, 2021
@jebter jebter added this to the v5.0.0 ga milestone Mar 20, 2021
@zimulala zimulala removed this from the v5.0.0 ga milestone Mar 22, 2021
@lzmhhh123 lzmhhh123 self-assigned this Apr 26, 2021
@lzmhhh123
Copy link
Contributor

Maybe https://github.com/oliveagle/jsonpath could help us rebuild the jsonpath. TiDB's jsonpath needs to be restructure.

@jebter jebter added affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. labels Jan 11, 2022
@morgo
Copy link
Contributor

morgo commented Jun 29, 2022

Some other test cases / this might be a duplicate of: #34959

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 component/json severity/major sig/execution SIG execution type/bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants