From f326b43cb920fbe72e37963d0c88c34e028906c9 Mon Sep 17 00:00:00 2001 From: Rucha Deodhar Date: Fri, 15 Apr 2022 01:28:33 +0530 Subject: [PATCH] Fixing merge conflicts for 10.9 json task and related bugs --- mysql-test/main/func_json.result | 1144 +--------------------------- mysql-test/main/func_json.test | 1224 +----------------------------- 2 files changed, 37 insertions(+), 2331 deletions(-) diff --git a/mysql-test/main/func_json.result b/mysql-test/main/func_json.result index 027f5f38a3e..0bb5441b393 100644 --- a/mysql-test/main/func_json.result +++ b/mysql-test/main/func_json.result @@ -1740,6 +1740,9 @@ SELECT JSON_OVERLAPS('[1,2,{"A":B}]', '{"A":B}', '{"C":"string1"}'); ERROR 42000: Incorrect parameter count in the call to native function 'JSON_OVERLAPS' SELECT JSON_OVERLAPS('[1,2,{"A":B}]'); ERROR 42000: Incorrect parameter count in the call to native function 'JSON_OVERLAPS' +# +# MDEV-27990: Incorrect behavior of JSON_OVERLAPS() on warning +# SELECT JSON_OVERLAPS('',''); JSON_OVERLAPS('','') 0 @@ -1751,53 +1754,6 @@ JSON_OVERLAPS('true','tr') Warnings: Warning 4037 Unexpected end of JSON text in argument 2 to function 'json_overlaps' # -<<<<<<< HEAD -||||||| parent of 970dba92c3d... MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in json -<<<<<<< HEAD -<<<<<<< HEAD -||||||| constructed merge base -# End of 10.9 test -# -# -||||||| constructed merge base -# End of 10.9 test -# -# -======= ->>>>>>> MDEV-22224: Support JSON Path negative index -# Beginning of 10.9 Test -# -======= -# Beginning of 10.9 Test -# ->>>>>>> MDEV-28071: JSON_EXISTS returns always 1 if it is used range notation for -======= -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -||||||| constructed merge base -# End of 10.9 test -# -# -||||||| constructed merge base -# End of 10.9 test -# -# -======= ->>>>>>> MDEV-22224: Support JSON Path negative index -||||||| constructed merge base -======= -# End of 10.9 test -# -# ->>>>>>> MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in json -# Beginning of 10.9 Test -# -======= -# Beginning of 10.9 Test -# ->>>>>>> MDEV-28071: JSON_EXISTS returns always 1 if it is used range notation for ->>>>>>> 970dba92c3d... MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in json # MDEV-22224: Support JSON Path negative index # SET @json='{ @@ -2071,7 +2027,6 @@ SELECT JSON_VALUE(@json,'$.x[0]'); JSON_VALUE(@json,'$.x[0]') 0 # -<<<<<<< HEAD # MDEV-27911: Implement range notation for json path # SET @json= '[ @@ -2261,822 +2216,7 @@ NULL Warnings: Warning 4044 Wildcards or range in JSON path not allowed in argument 2 to function 'json_keys' # -# MDEV-28071: JSON_EXISTS returns always 1 if it is used range notation -# for json path -# -<<<<<<< HEAD -||||||| parent of 3834536ced0... MDEV-28071: JSON_EXISTS returns always 1 if it is used range notation for -||||||| constructed merge base -======= -# -# Beginning of 10.9 Test -# -# MDEV-22224: Support JSON Path negative index -# -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_ARRAY_APPEND(@json, '$.A[-2][-1]', 5); -JSON_ARRAY_APPEND(@json, '$.A[-2][-1]', 5) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, 13, {"key1": "value1"}, [15, 5]], true], "B": {"C": 1}, "D": 2} -SELECT JSON_ARRAY_APPEND(@json, '$.A[last-1][last]', 5); -JSON_ARRAY_APPEND(@json, '$.A[last-1][last]', 5) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, 13, {"key1": "value1"}, [15, 5]], true], "B": {"C": 1}, "D": 2} -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_ARRAY_INSERT(@json, '$.A[-2][-2]', 5); -JSON_ARRAY_INSERT(@json, '$.A[-2][-2]', 5) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, 13, {"key1": "value1"}, 5, [15]], true], "B": {"C": 1}, "D": 2} -SELECT JSON_ARRAY_INSERT(@json, '$.A[last-1][last-1]', 5); -JSON_ARRAY_INSERT(@json, '$.A[last-1][last-1]', 5) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, 13, {"key1": "value1"}, 5, [15]], true], "B": {"C": 1}, "D": 2} -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_CONTAINS(@json, '15', '$.A[-2][-1]'); -JSON_CONTAINS(@json, '15', '$.A[-2][-1]') -1 -SELECT JSON_CONTAINS(@json, '15', '$.A[last-1][last]'); -JSON_CONTAINS(@json, '15', '$.A[last-1][last]') -1 -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_CONTAINS_PATH(@json, 'one', '$.A[-2]'); -JSON_CONTAINS_PATH(@json, 'one', '$.A[-2]') -1 -SELECT JSON_CONTAINS_PATH(@json, 'one', '$.A[last-1]'); -JSON_CONTAINS_PATH(@json, 'one', '$.A[last-1]') -1 -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_EXISTS(@json, '$.A[-2][-1]'); -JSON_EXISTS(@json, '$.A[-2][-1]') -1 -SELECT JSON_EXISTS(@json, '$.A[last-1][last]'); -JSON_EXISTS(@json, '$.A[last-1][last]') -1 -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_EXTRACT(@json, '$.A[-8][1]'); -JSON_EXTRACT(@json, '$.A[-8][1]') -5 -SELECT JSON_EXTRACT(@json, '$.A[last-7][1]'); -JSON_EXTRACT(@json, '$.A[last-7][1]') -5 -SET @json= '[{"A": 1, "B": 2, "C": {"D": 3}},{"A": 1, "B": 2, "C": {"D": 3}}]'; -SELECT JSON_KEYS(@json, '$[-1].C'); -JSON_KEYS(@json, '$[-1].C') -["D"] -SELECT JSON_KEYS(@json, '$[last].C'); -JSON_KEYS(@json, '$[last].C') -["D"] -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_LENGTH(@json, '$.A[-2][-3]'); -JSON_LENGTH(@json, '$.A[-2][-3]') -2 -SELECT JSON_LENGTH(@json, '$.A[last-1][last-2]'); -JSON_LENGTH(@json, '$.A[last-1][last-2]') -2 -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_QUERY(@json, '$.A[-8]'); -JSON_QUERY(@json, '$.A[-8]') -[4, 5, 6] -SELECT JSON_QUERY(@json, '$.A[last-7]'); -JSON_QUERY(@json, '$.A[last-7]') -[4, 5, 6] -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_REMOVE(@json, '$.A[-10]'); -JSON_REMOVE(@json, '$.A[-10]') -{"A": [[1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], true], "B": {"C": 1}, "D": 2} -SELECT JSON_REMOVE(@json, '$.A[last-9]'); -JSON_REMOVE(@json, '$.A[last-9]') -{"A": [[1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], true], "B": {"C": 1}, "D": 2} -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_REPLACE(@json, '$.A[-1]', 4); -JSON_REPLACE(@json, '$.A[-1]', 4) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], 4], "B": {"C": 1}, "D": 2} -SELECT JSON_REPLACE(@json, '$.A[last]', 4); -JSON_REPLACE(@json, '$.A[last]', 4) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], 4], "B": {"C": 1}, "D": 2} -SET @json = '["abc", [{"k": "10"}, "def"], {"x":"abc"}, {"y":"bcd"}]'; -SELECT JSON_SEARCH(@json, 'all', 'abc', NULL, '$[-2]'); -JSON_SEARCH(@json, 'all', 'abc', NULL, '$[-2]') -"$[2].x" -SELECT JSON_SEARCH(@json, 'all', 'abc', NULL, '$[last-1]'); -JSON_SEARCH(@json, 'all', 'abc', NULL, '$[last-1]') -"$[2].x" -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_SET(@json, '$.A[-4]', 100); -JSON_SET(@json, '$.A[-4]', 100) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, 100, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], true], "B": {"C": 1}, "D": 2} -SELECT JSON_SET(@json, '$.A[last-3]', 100); -JSON_SET(@json, '$.A[last-3]', 100) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, 100, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], true], "B": {"C": 1}, "D": 2} -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":123},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_VALUE(@json, '$.A[-2][-2].key1'); -JSON_VALUE(@json, '$.A[-2][-2].key1') -123 -SELECT JSON_VALUE(@json, '$.A[last-1][last-1].key1'); -JSON_VALUE(@json, '$.A[last-1][last-1].key1') -123 -# -# End of 10.9 Test -# -SET @json= '[ - [1, {"key1": "value1"}, 3], - [false, 5, 6], - [7, 8, [9, {"key2": 2}, 11]], - [15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]], - [19, 20], - 21, 22 - ]'; -SELECT JSON_EXISTS(@json, '$[2][2][1 to 2]'); -JSON_EXISTS(@json, '$[2][2][1 to 2]') -1 -SELECT JSON_EXISTS(@json, '$[2][2][4 to 6]'); -JSON_EXISTS(@json, '$[2][2][4 to 6]') -0 -SELECT JSON_EXISTS(@json, '$[2][2][1 to 4]'); -JSON_EXISTS(@json, '$[2][2][1 to 4]') -1 -# -# MDEV-22224: Support JSON Path negative index -# -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_ARRAY_APPEND(@json, '$.A[-2][-1]', 5); -JSON_ARRAY_APPEND(@json, '$.A[-2][-1]', 5) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, 13, {"key1": "value1"}, [15, 5]], true], "B": {"C": 1}, "D": 2} -SELECT JSON_ARRAY_APPEND(@json, '$.A[last-1][last]', 5); -JSON_ARRAY_APPEND(@json, '$.A[last-1][last]', 5) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, 13, {"key1": "value1"}, [15, 5]], true], "B": {"C": 1}, "D": 2} -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_ARRAY_INSERT(@json, '$.A[-2][-2]', 5); -JSON_ARRAY_INSERT(@json, '$.A[-2][-2]', 5) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, 13, {"key1": "value1"}, 5, [15]], true], "B": {"C": 1}, "D": 2} -SELECT JSON_ARRAY_INSERT(@json, '$.A[last-1][last-1]', 5); -JSON_ARRAY_INSERT(@json, '$.A[last-1][last-1]', 5) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, 13, {"key1": "value1"}, 5, [15]], true], "B": {"C": 1}, "D": 2} -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_CONTAINS(@json, '15', '$.A[-2][-1]'); -JSON_CONTAINS(@json, '15', '$.A[-2][-1]') -1 -SELECT JSON_CONTAINS(@json, '15', '$.A[last-1][last]'); -JSON_CONTAINS(@json, '15', '$.A[last-1][last]') -1 -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_CONTAINS_PATH(@json, 'one', '$.A[-2]'); -JSON_CONTAINS_PATH(@json, 'one', '$.A[-2]') -1 -SELECT JSON_CONTAINS_PATH(@json, 'one', '$.A[last-1]'); -JSON_CONTAINS_PATH(@json, 'one', '$.A[last-1]') -1 -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_EXISTS(@json, '$.A[-2][-1]'); -JSON_EXISTS(@json, '$.A[-2][-1]') -1 -SELECT JSON_EXISTS(@json, '$.A[last-1][last]'); -JSON_EXISTS(@json, '$.A[last-1][last]') -1 -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_EXTRACT(@json, '$.A[-8][1]'); -JSON_EXTRACT(@json, '$.A[-8][1]') -5 -SELECT JSON_EXTRACT(@json, '$.A[last-7][1]'); -JSON_EXTRACT(@json, '$.A[last-7][1]') -5 -SET @json= '[{"A": 1, "B": 2, "C": {"D": 3}},{"A": 1, "B": 2, "C": {"D": 3}}]'; -SELECT JSON_KEYS(@json, '$[-1].C'); -JSON_KEYS(@json, '$[-1].C') -["D"] -SELECT JSON_KEYS(@json, '$[last].C'); -JSON_KEYS(@json, '$[last].C') -["D"] -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_LENGTH(@json, '$.A[-2][-3]'); -JSON_LENGTH(@json, '$.A[-2][-3]') -2 -SELECT JSON_LENGTH(@json, '$.A[last-1][last-2]'); -JSON_LENGTH(@json, '$.A[last-1][last-2]') -2 -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_QUERY(@json, '$.A[-8]'); -JSON_QUERY(@json, '$.A[-8]') -[4, 5, 6] -SELECT JSON_QUERY(@json, '$.A[last-7]'); -JSON_QUERY(@json, '$.A[last-7]') -[4, 5, 6] -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_REMOVE(@json, '$.A[-10]'); -JSON_REMOVE(@json, '$.A[-10]') -{"A": [[1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], true], "B": {"C": 1}, "D": 2} -SELECT JSON_REMOVE(@json, '$.A[last-9]'); -JSON_REMOVE(@json, '$.A[last-9]') -{"A": [[1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], true], "B": {"C": 1}, "D": 2} -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_REPLACE(@json, '$.A[-1]', 4); -JSON_REPLACE(@json, '$.A[-1]', 4) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], 4], "B": {"C": 1}, "D": 2} -SELECT JSON_REPLACE(@json, '$.A[last]', 4); -JSON_REPLACE(@json, '$.A[last]', 4) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], 4], "B": {"C": 1}, "D": 2} -SET @json = '["abc", [{"k": "10"}, "def"], {"x":"abc"}, {"y":"bcd"}]'; -SELECT JSON_SEARCH(@json, 'all', 'abc', NULL, '$[-2]'); -JSON_SEARCH(@json, 'all', 'abc', NULL, '$[-2]') -"$[2].x" -SELECT JSON_SEARCH(@json, 'all', 'abc', NULL, '$[last-1]'); -JSON_SEARCH(@json, 'all', 'abc', NULL, '$[last-1]') -"$[2].x" -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_SET(@json, '$.A[-4]', 100); -JSON_SET(@json, '$.A[-4]', 100) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, 100, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], true], "B": {"C": 1}, "D": 2} -SELECT JSON_SET(@json, '$.A[last-3]', 100); -JSON_SET(@json, '$.A[last-3]', 100) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, 100, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], true], "B": {"C": 1}, "D": 2} -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":123},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_VALUE(@json, '$.A[-2][-2].key1'); -JSON_VALUE(@json, '$.A[-2][-2].key1') -123 -SELECT JSON_VALUE(@json, '$.A[last-1][last-1].key1'); -JSON_VALUE(@json, '$.A[last-1][last-1].key1') -123 -# -# MDEV-22224: Support JSON Path negative index -# -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_ARRAY_APPEND(@json, '$.A[-2][-1]', 5); -JSON_ARRAY_APPEND(@json, '$.A[-2][-1]', 5) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, 13, {"key1": "value1"}, [15, 5]], true], "B": {"C": 1}, "D": 2} -SELECT JSON_ARRAY_APPEND(@json, '$.A[last-1][last]', 5); -JSON_ARRAY_APPEND(@json, '$.A[last-1][last]', 5) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, 13, {"key1": "value1"}, [15, 5]], true], "B": {"C": 1}, "D": 2} -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_ARRAY_INSERT(@json, '$.A[-2][-2]', 5); -JSON_ARRAY_INSERT(@json, '$.A[-2][-2]', 5) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, 13, {"key1": "value1"}, 5, [15]], true], "B": {"C": 1}, "D": 2} -SELECT JSON_ARRAY_INSERT(@json, '$.A[last-1][last-1]', 5); -JSON_ARRAY_INSERT(@json, '$.A[last-1][last-1]', 5) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, 13, {"key1": "value1"}, 5, [15]], true], "B": {"C": 1}, "D": 2} -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_CONTAINS(@json, '15', '$.A[-2][-1]'); -JSON_CONTAINS(@json, '15', '$.A[-2][-1]') -1 -SELECT JSON_CONTAINS(@json, '15', '$.A[last-1][last]'); -JSON_CONTAINS(@json, '15', '$.A[last-1][last]') -1 -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_CONTAINS_PATH(@json, 'one', '$.A[-2]'); -JSON_CONTAINS_PATH(@json, 'one', '$.A[-2]') -1 -SELECT JSON_CONTAINS_PATH(@json, 'one', '$.A[last-1]'); -JSON_CONTAINS_PATH(@json, 'one', '$.A[last-1]') -1 -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_EXISTS(@json, '$.A[-2][-1]'); -JSON_EXISTS(@json, '$.A[-2][-1]') -1 -SELECT JSON_EXISTS(@json, '$.A[last-1][last]'); -JSON_EXISTS(@json, '$.A[last-1][last]') -1 -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_EXTRACT(@json, '$.A[-8][1]'); -JSON_EXTRACT(@json, '$.A[-8][1]') -5 -SELECT JSON_EXTRACT(@json, '$.A[last-7][1]'); -JSON_EXTRACT(@json, '$.A[last-7][1]') -5 -SET @json= '[{"A": 1, "B": 2, "C": {"D": 3}},{"A": 1, "B": 2, "C": {"D": 3}}]'; -SELECT JSON_KEYS(@json, '$[-1].C'); -JSON_KEYS(@json, '$[-1].C') -["D"] -SELECT JSON_KEYS(@json, '$[last].C'); -JSON_KEYS(@json, '$[last].C') -["D"] -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_LENGTH(@json, '$.A[-2][-3]'); -JSON_LENGTH(@json, '$.A[-2][-3]') -2 -SELECT JSON_LENGTH(@json, '$.A[last-1][last-2]'); -JSON_LENGTH(@json, '$.A[last-1][last-2]') -2 -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_QUERY(@json, '$.A[-8]'); -JSON_QUERY(@json, '$.A[-8]') -[4, 5, 6] -SELECT JSON_QUERY(@json, '$.A[last-7]'); -JSON_QUERY(@json, '$.A[last-7]') -[4, 5, 6] -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_REMOVE(@json, '$.A[-10]'); -JSON_REMOVE(@json, '$.A[-10]') -{"A": [[1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], true], "B": {"C": 1}, "D": 2} -SELECT JSON_REMOVE(@json, '$.A[last-9]'); -JSON_REMOVE(@json, '$.A[last-9]') -{"A": [[1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], true], "B": {"C": 1}, "D": 2} -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_REPLACE(@json, '$.A[-1]', 4); -JSON_REPLACE(@json, '$.A[-1]', 4) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], 4], "B": {"C": 1}, "D": 2} -SELECT JSON_REPLACE(@json, '$.A[last]', 4); -JSON_REPLACE(@json, '$.A[last]', 4) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], 4], "B": {"C": 1}, "D": 2} -SET @json = '["abc", [{"k": "10"}, "def"], {"x":"abc"}, {"y":"bcd"}]'; -SELECT JSON_SEARCH(@json, 'all', 'abc', NULL, '$[-2]'); -JSON_SEARCH(@json, 'all', 'abc', NULL, '$[-2]') -"$[2].x" -SELECT JSON_SEARCH(@json, 'all', 'abc', NULL, '$[last-1]'); -JSON_SEARCH(@json, 'all', 'abc', NULL, '$[last-1]') -"$[2].x" -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_SET(@json, '$.A[-4]', 100); -JSON_SET(@json, '$.A[-4]', 100) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, 100, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], true], "B": {"C": 1}, "D": 2} -SELECT JSON_SET(@json, '$.A[last-3]', 100); -JSON_SET(@json, '$.A[last-3]', 100) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, 100, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], true], "B": {"C": 1}, "D": 2} -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":123},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_VALUE(@json, '$.A[-2][-2].key1'); -JSON_VALUE(@json, '$.A[-2][-2].key1') -123 -SELECT JSON_VALUE(@json, '$.A[last-1][last-1].key1'); -JSON_VALUE(@json, '$.A[last-1][last-1].key1') -123 -# -<<<<<<< HEAD # MDEV-28075: JSON_VALUE returns first value from array not from range -||||||| parent of 970dba92c3d... MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in json -# MDEV-22224: Support JSON Path negative index -# -# MDEV-27911: Implement range notation for json path -======= -# MDEV-22224: Support JSON Path negative index -# -# Beginning of 10.9 Test -# -# MDEV-22224: Support JSON Path negative index -# -# MDEV-27911: Implement range notation for json path ->>>>>>> 970dba92c3d... MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in json # SET @json1= '[ [{"key1": "value1"}, {"key2": "value2"}], @@ -3100,13 +2240,6 @@ SELECT JSON_VALUE(@json, '$[2 to 3][0]'); JSON_VALUE(@json, '$[2 to 3][0]') 7 # -<<<<<<< HEAD -# Beginning of 10.9 Test -# -# MDEV-22224: Support JSON Path negative index -||||||| parent of 970dba92c3d... MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in json -# MDEV-27911: Implement range notation for json path -======= # MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in # json path (when range is used) # @@ -3124,263 +2257,26 @@ SELECT JSON_EXTRACT(@json, '$[-0 to -0]'); JSON_EXTRACT(@json, '$[-0 to -0]') [11] # -# MDEV-22224: Support JSON Path negative index ->>>>>>> 970dba92c3d... MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in json +# MDEV-28071: JSON_EXISTS returns always 1 if it is used range notation +# for json path # -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_ARRAY_APPEND(@json, '$.A[-2][-1]', 5); -JSON_ARRAY_APPEND(@json, '$.A[-2][-1]', 5) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, 13, {"key1": "value1"}, [15, 5]], true], "B": {"C": 1}, "D": 2} -SELECT JSON_ARRAY_APPEND(@json, '$.A[last-1][last]', 5); -JSON_ARRAY_APPEND(@json, '$.A[last-1][last]', 5) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, 13, {"key1": "value1"}, [15, 5]], true], "B": {"C": 1}, "D": 2} -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_ARRAY_INSERT(@json, '$.A[-2][-2]', 5); -JSON_ARRAY_INSERT(@json, '$.A[-2][-2]', 5) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, 13, {"key1": "value1"}, 5, [15]], true], "B": {"C": 1}, "D": 2} -SELECT JSON_ARRAY_INSERT(@json, '$.A[last-1][last-1]', 5); -JSON_ARRAY_INSERT(@json, '$.A[last-1][last-1]', 5) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, 13, {"key1": "value1"}, 5, [15]], true], "B": {"C": 1}, "D": 2} -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_CONTAINS(@json, '15', '$.A[-2][-1]'); -JSON_CONTAINS(@json, '15', '$.A[-2][-1]') +SET @json= '[ + [1, {"key1": "value1"}, 3], + [false, 5, 6], + [7, 8, [9, {"key2": 2}, 11]], + [15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]], + [19, 20], + 21, 22 + ]'; +SELECT JSON_EXISTS(@json, '$[2][2][1 to 2]'); +JSON_EXISTS(@json, '$[2][2][1 to 2]') 1 -SELECT JSON_CONTAINS(@json, '15', '$.A[last-1][last]'); -JSON_CONTAINS(@json, '15', '$.A[last-1][last]') +SELECT JSON_EXISTS(@json, '$[2][2][4 to 6]'); +JSON_EXISTS(@json, '$[2][2][4 to 6]') +0 +SELECT JSON_EXISTS(@json, '$[2][2][1 to 4]'); +JSON_EXISTS(@json, '$[2][2][1 to 4]') 1 -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_CONTAINS_PATH(@json, 'one', '$.A[-2]'); -JSON_CONTAINS_PATH(@json, 'one', '$.A[-2]') -1 -SELECT JSON_CONTAINS_PATH(@json, 'one', '$.A[last-1]'); -JSON_CONTAINS_PATH(@json, 'one', '$.A[last-1]') -1 -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_EXISTS(@json, '$.A[-2][-1]'); -JSON_EXISTS(@json, '$.A[-2][-1]') -1 -SELECT JSON_EXISTS(@json, '$.A[last-1][last]'); -JSON_EXISTS(@json, '$.A[last-1][last]') -1 -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_EXTRACT(@json, '$.A[-8][1]'); -JSON_EXTRACT(@json, '$.A[-8][1]') -5 -SELECT JSON_EXTRACT(@json, '$.A[last-7][1]'); -JSON_EXTRACT(@json, '$.A[last-7][1]') -5 -SET @json= '[{"A": 1, "B": 2, "C": {"D": 3}},{"A": 1, "B": 2, "C": {"D": 3}}]'; -SELECT JSON_KEYS(@json, '$[-1].C'); -JSON_KEYS(@json, '$[-1].C') -["D"] -SELECT JSON_KEYS(@json, '$[last].C'); -JSON_KEYS(@json, '$[last].C') -["D"] -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_LENGTH(@json, '$.A[-2][-3]'); -JSON_LENGTH(@json, '$.A[-2][-3]') -2 -SELECT JSON_LENGTH(@json, '$.A[last-1][last-2]'); -JSON_LENGTH(@json, '$.A[last-1][last-2]') -2 -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_QUERY(@json, '$.A[-8]'); -JSON_QUERY(@json, '$.A[-8]') -[4, 5, 6] -SELECT JSON_QUERY(@json, '$.A[last-7]'); -JSON_QUERY(@json, '$.A[last-7]') -[4, 5, 6] -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_REMOVE(@json, '$.A[-10]'); -JSON_REMOVE(@json, '$.A[-10]') -{"A": [[1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], true], "B": {"C": 1}, "D": 2} -SELECT JSON_REMOVE(@json, '$.A[last-9]'); -JSON_REMOVE(@json, '$.A[last-9]') -{"A": [[1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], true], "B": {"C": 1}, "D": 2} -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_REPLACE(@json, '$.A[-1]', 4); -JSON_REPLACE(@json, '$.A[-1]', 4) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], 4], "B": {"C": 1}, "D": 2} -SELECT JSON_REPLACE(@json, '$.A[last]', 4); -JSON_REPLACE(@json, '$.A[last]', 4) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, false, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], 4], "B": {"C": 1}, "D": 2} -SET @json = '["abc", [{"k": "10"}, "def"], {"x":"abc"}, {"y":"bcd"}]'; -SELECT JSON_SEARCH(@json, 'all', 'abc', NULL, '$[-2]'); -JSON_SEARCH(@json, 'all', 'abc', NULL, '$[-2]') -"$[2].x" -SELECT JSON_SEARCH(@json, 'all', 'abc', NULL, '$[last-1]'); -JSON_SEARCH(@json, 'all', 'abc', NULL, '$[last-1]') -"$[2].x" -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_SET(@json, '$.A[-4]', 100); -JSON_SET(@json, '$.A[-4]', 100) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, 100, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], true], "B": {"C": 1}, "D": 2} -SELECT JSON_SET(@json, '$.A[last-3]', 100); -JSON_SET(@json, '$.A[last-3]', 100) -{"A": [0, [1, 2, 3], [4, 5, 6], "seven", 0.8, true, 100, "eleven", [12, [13, 14], {"key1": "value1"}, [15]], true], "B": {"C": 1}, "D": 2} -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":123},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_VALUE(@json, '$.A[-2][-2].key1'); -JSON_VALUE(@json, '$.A[-2][-2].key1') -123 -SELECT JSON_VALUE(@json, '$.A[last-1][last-1].key1'); -JSON_VALUE(@json, '$.A[last-1][last-1].key1') -123 # # End of 10.9 Test # diff --git a/mysql-test/main/func_json.test b/mysql-test/main/func_json.test index 5b695618ed2..71f9c192237 100644 --- a/mysql-test/main/func_json.test +++ b/mysql-test/main/func_json.test @@ -1082,14 +1082,13 @@ SELECT JSON_OVERLAPS('{"A": 1, "B": 3}','[1, 2, true, false, [{"A": 1, "B": 2}, SELECT JSON_OVERLAPS('[1,2,{"A":B}]', '{"A":B}', '{"C":"string1"}'); --error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT SELECT JSON_OVERLAPS('[1,2,{"A":B}]'); + +--echo # +--echo # MDEV-27990: Incorrect behavior of JSON_OVERLAPS() on warning +--echo # SELECT JSON_OVERLAPS('',''); SELECT JSON_OVERLAPS('true','tr'); ---echo # ---echo # End of 10.9 test ---echo # ---echo # ---echo # Beginning of 10.9 Test --echo # --echo # MDEV-22224: Support JSON Path negative index --echo # @@ -1477,455 +1476,6 @@ SET @json='{ }'; SELECT JSON_KEYS(@json, '$.A[8][1 to 3]'); - ---echo # ---echo # MDEV-28071: JSON_EXISTS returns always 1 if it is used range notation ---echo # for json path ---echo # - -SET @json= '[ - [1, {"key1": "value1"}, 3], - [false, 5, 6], - [7, 8, [9, {"key2": 2}, 11]], - [15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]], - [19, 20], - 21, 22 - ]'; -SELECT JSON_EXISTS(@json, '$[2][2][1 to 2]'); -SELECT JSON_EXISTS(@json, '$[2][2][4 to 6]'); -SELECT JSON_EXISTS(@json, '$[2][2][1 to 4]'); ---echo # ---echo # MDEV-22224: Support JSON Path negative index ---echo # - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_ARRAY_APPEND(@json, '$.A[-2][-1]', 5); -SELECT JSON_ARRAY_APPEND(@json, '$.A[last-1][last]', 5); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_ARRAY_INSERT(@json, '$.A[-2][-2]', 5); -SELECT JSON_ARRAY_INSERT(@json, '$.A[last-1][last-1]', 5); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_CONTAINS(@json, '15', '$.A[-2][-1]'); -SELECT JSON_CONTAINS(@json, '15', '$.A[last-1][last]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_CONTAINS_PATH(@json, 'one', '$.A[-2]'); -SELECT JSON_CONTAINS_PATH(@json, 'one', '$.A[last-1]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_EXISTS(@json, '$.A[-2][-1]'); -SELECT JSON_EXISTS(@json, '$.A[last-1][last]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_EXTRACT(@json, '$.A[-8][1]'); -SELECT JSON_EXTRACT(@json, '$.A[last-7][1]'); - -SET @json= '[{"A": 1, "B": 2, "C": {"D": 3}},{"A": 1, "B": 2, "C": {"D": 3}}]'; -SELECT JSON_KEYS(@json, '$[-1].C'); -SELECT JSON_KEYS(@json, '$[last].C'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_LENGTH(@json, '$.A[-2][-3]'); -SELECT JSON_LENGTH(@json, '$.A[last-1][last-2]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_QUERY(@json, '$.A[-8]'); -SELECT JSON_QUERY(@json, '$.A[last-7]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_REMOVE(@json, '$.A[-10]'); -SELECT JSON_REMOVE(@json, '$.A[last-9]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_REPLACE(@json, '$.A[-1]', 4); -SELECT JSON_REPLACE(@json, '$.A[last]', 4); - -SET @json = '["abc", [{"k": "10"}, "def"], {"x":"abc"}, {"y":"bcd"}]'; -SELECT JSON_SEARCH(@json, 'all', 'abc', NULL, '$[-2]'); -SELECT JSON_SEARCH(@json, 'all', 'abc', NULL, '$[last-1]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_SET(@json, '$.A[-4]', 100); -SELECT JSON_SET(@json, '$.A[last-3]', 100); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":123},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_VALUE(@json, '$.A[-2][-2].key1'); -SELECT JSON_VALUE(@json, '$.A[last-1][last-1].key1'); - ---echo # ---echo # MDEV-22224: Support JSON Path negative index ---echo # - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_ARRAY_APPEND(@json, '$.A[-2][-1]', 5); -SELECT JSON_ARRAY_APPEND(@json, '$.A[last-1][last]', 5); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_ARRAY_INSERT(@json, '$.A[-2][-2]', 5); -SELECT JSON_ARRAY_INSERT(@json, '$.A[last-1][last-1]', 5); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_CONTAINS(@json, '15', '$.A[-2][-1]'); -SELECT JSON_CONTAINS(@json, '15', '$.A[last-1][last]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_CONTAINS_PATH(@json, 'one', '$.A[-2]'); -SELECT JSON_CONTAINS_PATH(@json, 'one', '$.A[last-1]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_EXISTS(@json, '$.A[-2][-1]'); -SELECT JSON_EXISTS(@json, '$.A[last-1][last]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_EXTRACT(@json, '$.A[-8][1]'); -SELECT JSON_EXTRACT(@json, '$.A[last-7][1]'); - -SET @json= '[{"A": 1, "B": 2, "C": {"D": 3}},{"A": 1, "B": 2, "C": {"D": 3}}]'; -SELECT JSON_KEYS(@json, '$[-1].C'); -SELECT JSON_KEYS(@json, '$[last].C'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_LENGTH(@json, '$.A[-2][-3]'); -SELECT JSON_LENGTH(@json, '$.A[last-1][last-2]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_QUERY(@json, '$.A[-8]'); -SELECT JSON_QUERY(@json, '$.A[last-7]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_REMOVE(@json, '$.A[-10]'); -SELECT JSON_REMOVE(@json, '$.A[last-9]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_REPLACE(@json, '$.A[-1]', 4); -SELECT JSON_REPLACE(@json, '$.A[last]', 4); - -SET @json = '["abc", [{"k": "10"}, "def"], {"x":"abc"}, {"y":"bcd"}]'; -SELECT JSON_SEARCH(@json, 'all', 'abc', NULL, '$[-2]'); -SELECT JSON_SEARCH(@json, 'all', 'abc', NULL, '$[last-1]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_SET(@json, '$.A[-4]', 100); -SELECT JSON_SET(@json, '$.A[last-3]', 100); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":123},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_VALUE(@json, '$.A[-2][-2].key1'); -SELECT JSON_VALUE(@json, '$.A[last-1][last-1].key1'); - --echo # --echo # MDEV-28075: JSON_VALUE returns first value from array not from range --echo # @@ -1948,546 +1498,6 @@ SET @json= '[ SELECT JSON_VALUE(@json, '$[*][0]'); SELECT JSON_VALUE(@json, '$[2 to 3][0]'); ---echo # -<<<<<<< HEAD -||||||| parent of 970dba92c3d... MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in json ---echo # MDEV-27911: Implement range notation for json path ---echo # - -SET @json= '[ - [1, {"key1": "value1"}, 3], - [false, 5, 6], - [7, 8, [9, {"key2": 2}, 11]], - [15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]], - [19, 20], - 21, 22 - ]'; -SELECT JSON_EXISTS(@json, '$[3][3][-2 to last]'); - -SET @json= '[ - [1, {"key1": "value1"}, 3], - [false, 5, 6], - [7, 8, [9, {"key2": 2}, 11]], - [15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]], - [19, 20], - 21, 22 - ]'; -SELECT JSON_SEARCH(@json, 'one', '12', NULL, '$[3][0 to 3]'); - -SET @json= '[ - [1, {"key1": "value1"}, 3], - [false, 5, 6], - [7, 8, [9, {"key2": 2}, 11]], - [12, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]], - [19, 20] - ]'; -SELECT JSON_VALUE(@json, '$[0][1 to 2].key1'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_QUERY(@json, '$.A[-2][-3 to -1]'); - -SET @json= '[ - [1, {"key1": "value1"}, 3], - [false, 5, 6], - [7, 8, [9, {"key2": 2}, 11]], - [15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]], - [19, 20], - 21, 22 - ]'; -SELECT JSON_EXTRACT(@json, '$[0 to 3][2]'); -SELECT JSON_EXTRACT(@json, '$[3][3][last-1 to last]'); -SELECT JSON_EXTRACT(@json, '$[3][3][-2 to -1]'); - ---echo # Checking errors - -SET @json= '[ - [1, {"key1": "value1"}, 3], - [false, 5, 6], - [7, 8, [9, {"key2": 2}, 11]], - [15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]], - [19, 20], - 21, 22 - ]'; -SELECT JSON_CONTAINS_PATH(@json,'one', '$[3][0 to 3]'); - -SET @json= '[ - [1, {"key1": "value1"}, 3], - [false, 5, 6], - [7, 8, [9, {"key2": 2}, 11]], - [15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]], - [19, 20], - 21, 22 - ]'; -SELECT JSON_CONTAINS(@json, '$[3][0 to 3]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_ARRAY_INSERT(@json, '$.A[0 to last-1]', 5); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_ARRAY_APPEND(@json, '$.A[*]', 7); - -SET @json= '[ - [1, {"key1": "value1"}, 3], - [false, 5, 6], - [7, 8, [9, {"key2": 2}, 11]], - [12, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]], - [19, 20] - ]'; -SELECT JSON_SET(@json, '$[0][1 to 2].key1', 1); - -SET @json= '[ - [1, {"key1": "value1"}, 3], - [false, 5, 6], - [7, 8, [9, {"key2": 2}, 11]], - [15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]], - [19, 20], - 21, 22 - ]'; -SELECT JSON_REPLACE(@json, '$[1][last-2 to last]', 4); - -SET @json= '[ - [1, {"key1": "value1"}, 3], - [false, 5, 6], - [7, 8, [9, {"key2": 2}, 11]], - [15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]], - [19, 20], - 21, 22 - ]'; -SELECT JSON_REMOVE(@json, '$[1][-6 to last-2]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_KEYS(@json, '$.A[8][1 to 3]'); - ---echo # ---echo # MDEV-22224: Support JSON Path negative index ---echo # - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_ARRAY_APPEND(@json, '$.A[-2][-1]', 5); -SELECT JSON_ARRAY_APPEND(@json, '$.A[last-1][last]', 5); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_ARRAY_INSERT(@json, '$.A[-2][-2]', 5); -SELECT JSON_ARRAY_INSERT(@json, '$.A[last-1][last-1]', 5); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_CONTAINS(@json, '15', '$.A[-2][-1]'); -SELECT JSON_CONTAINS(@json, '15', '$.A[last-1][last]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_CONTAINS_PATH(@json, 'one', '$.A[-2]'); -SELECT JSON_CONTAINS_PATH(@json, 'one', '$.A[last-1]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_EXISTS(@json, '$.A[-2][-1]'); -SELECT JSON_EXISTS(@json, '$.A[last-1][last]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_EXTRACT(@json, '$.A[-8][1]'); -SELECT JSON_EXTRACT(@json, '$.A[last-7][1]'); - -SET @json= '[{"A": 1, "B": 2, "C": {"D": 3}},{"A": 1, "B": 2, "C": {"D": 3}}]'; -SELECT JSON_KEYS(@json, '$[-1].C'); -SELECT JSON_KEYS(@json, '$[last].C'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_LENGTH(@json, '$.A[-2][-3]'); -SELECT JSON_LENGTH(@json, '$.A[last-1][last-2]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_QUERY(@json, '$.A[-8]'); -SELECT JSON_QUERY(@json, '$.A[last-7]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_REMOVE(@json, '$.A[-10]'); -SELECT JSON_REMOVE(@json, '$.A[last-9]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_REPLACE(@json, '$.A[-1]', 4); -SELECT JSON_REPLACE(@json, '$.A[last]', 4); - -SET @json = '["abc", [{"k": "10"}, "def"], {"x":"abc"}, {"y":"bcd"}]'; -SELECT JSON_SEARCH(@json, 'all', 'abc', NULL, '$[-2]'); -SELECT JSON_SEARCH(@json, 'all', 'abc', NULL, '$[last-1]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_SET(@json, '$.A[-4]', 100); -SELECT JSON_SET(@json, '$.A[last-3]', 100); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":123},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_VALUE(@json, '$.A[-2][-2].key1'); -SELECT JSON_VALUE(@json, '$.A[last-1][last-1].key1'); - ---echo # -======= ---echo # MDEV-27911: Implement range notation for json path ---echo # - -SET @json= '[ - [1, {"key1": "value1"}, 3], - [false, 5, 6], - [7, 8, [9, {"key2": 2}, 11]], - [15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]], - [19, 20], - 21, 22 - ]'; -SELECT JSON_EXISTS(@json, '$[3][3][-2 to last]'); - -SET @json= '[ - [1, {"key1": "value1"}, 3], - [false, 5, 6], - [7, 8, [9, {"key2": 2}, 11]], - [15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]], - [19, 20], - 21, 22 - ]'; -SELECT JSON_SEARCH(@json, 'one', '12', NULL, '$[3][0 to 3]'); - -SET @json= '[ - [1, {"key1": "value1"}, 3], - [false, 5, 6], - [7, 8, [9, {"key2": 2}, 11]], - [12, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]], - [19, 20] - ]'; -SELECT JSON_VALUE(@json, '$[0][1 to 2].key1'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_QUERY(@json, '$.A[-2][-3 to -1]'); - -SET @json= '[ - [1, {"key1": "value1"}, 3], - [false, 5, 6], - [7, 8, [9, {"key2": 2}, 11]], - [15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]], - [19, 20], - 21, 22 - ]'; -SELECT JSON_EXTRACT(@json, '$[0 to 3][2]'); -SELECT JSON_EXTRACT(@json, '$[3][3][last-1 to last]'); -SELECT JSON_EXTRACT(@json, '$[3][3][-2 to -1]'); - ---echo # Checking errors - -SET @json= '[ - [1, {"key1": "value1"}, 3], - [false, 5, 6], - [7, 8, [9, {"key2": 2}, 11]], - [15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]], - [19, 20], - 21, 22 - ]'; -SELECT JSON_CONTAINS_PATH(@json,'one', '$[3][0 to 3]'); - -SET @json= '[ - [1, {"key1": "value1"}, 3], - [false, 5, 6], - [7, 8, [9, {"key2": 2}, 11]], - [15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]], - [19, 20], - 21, 22 - ]'; -SELECT JSON_CONTAINS(@json, '$[3][0 to 3]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_ARRAY_INSERT(@json, '$.A[0 to last-1]', 5); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_ARRAY_APPEND(@json, '$.A[*]', 7); - -SET @json= '[ - [1, {"key1": "value1"}, 3], - [false, 5, 6], - [7, 8, [9, {"key2": 2}, 11]], - [12, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]], - [19, 20] - ]'; -SELECT JSON_SET(@json, '$[0][1 to 2].key1', 1); - -SET @json= '[ - [1, {"key1": "value1"}, 3], - [false, 5, 6], - [7, 8, [9, {"key2": 2}, 11]], - [15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]], - [19, 20], - 21, 22 - ]'; -SELECT JSON_REPLACE(@json, '$[1][last-2 to last]', 4); - -SET @json= '[ - [1, {"key1": "value1"}, 3], - [false, 5, 6], - [7, 8, [9, {"key2": 2}, 11]], - [15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]], - [19, 20], - 21, 22 - ]'; -SELECT JSON_REMOVE(@json, '$[1][-6 to last-2]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_KEYS(@json, '$.A[8][1 to 3]'); - - --echo # --echo # MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in --echo # json path (when range is used) @@ -2500,222 +1510,22 @@ SELECT JSON_EXTRACT(@json, '$[-0 to 0]'); SELECT JSON_EXTRACT(@json, '$[-0 to -0]'); --echo # ---echo # MDEV-22224: Support JSON Path negative index +--echo # MDEV-28071: JSON_EXISTS returns always 1 if it is used range notation +--echo # for json path --echo # -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_ARRAY_APPEND(@json, '$.A[-2][-1]', 5); -SELECT JSON_ARRAY_APPEND(@json, '$.A[last-1][last]', 5); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_ARRAY_INSERT(@json, '$.A[-2][-2]', 5); -SELECT JSON_ARRAY_INSERT(@json, '$.A[last-1][last-1]', 5); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_CONTAINS(@json, '15', '$.A[-2][-1]'); -SELECT JSON_CONTAINS(@json, '15', '$.A[last-1][last]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_CONTAINS_PATH(@json, 'one', '$.A[-2]'); -SELECT JSON_CONTAINS_PATH(@json, 'one', '$.A[last-1]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, 13, {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_EXISTS(@json, '$.A[-2][-1]'); -SELECT JSON_EXISTS(@json, '$.A[last-1][last]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_EXTRACT(@json, '$.A[-8][1]'); -SELECT JSON_EXTRACT(@json, '$.A[last-7][1]'); - -SET @json= '[{"A": 1, "B": 2, "C": {"D": 3}},{"A": 1, "B": 2, "C": {"D": 3}}]'; -SELECT JSON_KEYS(@json, '$[-1].C'); -SELECT JSON_KEYS(@json, '$[last].C'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_LENGTH(@json, '$.A[-2][-3]'); -SELECT JSON_LENGTH(@json, '$.A[last-1][last-2]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_QUERY(@json, '$.A[-8]'); -SELECT JSON_QUERY(@json, '$.A[last-7]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_REMOVE(@json, '$.A[-10]'); -SELECT JSON_REMOVE(@json, '$.A[last-9]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_REPLACE(@json, '$.A[-1]', 4); -SELECT JSON_REPLACE(@json, '$.A[last]', 4); - -SET @json = '["abc", [{"k": "10"}, "def"], {"x":"abc"}, {"y":"bcd"}]'; -SELECT JSON_SEARCH(@json, 'all', 'abc', NULL, '$[-2]'); -SELECT JSON_SEARCH(@json, 'all', 'abc', NULL, '$[last-1]'); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":"value1"},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_SET(@json, '$.A[-4]', 100); -SELECT JSON_SET(@json, '$.A[last-3]', 100); - -SET @json='{ - "A": [0, - [1, 2, 3], - [4, 5, 6], - "seven", - 0.8, - true, - false, - "eleven", - [12, [13, 14], {"key1":123},[15]], - true], - "B": {"C": 1}, - "D": 2 - }'; -SELECT JSON_VALUE(@json, '$.A[-2][-2].key1'); -SELECT JSON_VALUE(@json, '$.A[last-1][last-1].key1'); +SET @json= '[ + [1, {"key1": "value1"}, 3], + [false, 5, 6], + [7, 8, [9, {"key2": 2}, 11]], + [15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]], + [19, 20], + 21, 22 + ]'; +SELECT JSON_EXISTS(@json, '$[2][2][1 to 2]'); +SELECT JSON_EXISTS(@json, '$[2][2][4 to 6]'); +SELECT JSON_EXISTS(@json, '$[2][2][1 to 4]'); --echo # ->>>>>>> 970dba92c3d... MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in json --echo # End of 10.9 Test --echo #