Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 58 additions & 22 deletions mysql-test/main/func_json.result
Original file line number Diff line number Diff line change
Expand Up @@ -5383,28 +5383,21 @@ json_array_intersect(@obj1, @obj2)
SET @obj1= '[1, 2, 3, 3, 3.0, "abc", true, true, {"key1":"val1" ]';
SET @obj2= '[3.0, 3, 5, "abc", "abc", true, {"key2":"val2"}, {"key1":"val1"}, {"key1":"val2"}]';
select json_array_intersect(@obj1, @obj2);
json_array_intersect(@obj1, @obj2)
[3.0, 3, "abc", true]
Warnings:
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_array_intersect' at position 53
ERROR HY000: Syntax error in JSON text in argument 1 to function 'json_array_intersect' at position 53
# Checking incorrect type for input
SET @obj1= '{"key1": "val1"}';
SET @arr1= '[ 1, 2, 3 ]';
SET @num1= '2';
SET @str1= '"abc"';
SET @bool1= 'true';
select json_array_intersect(@obj1, @arr1);
json_array_intersect(@obj1, @arr1)
NULL
ERROR HY000: Syntax error in JSON text in argument 1 to function 'json_array_intersect' at position 1
select json_array_intersect(@arr1, @obj1);
json_array_intersect(@arr1, @obj1)
NULL
ERROR HY000: Syntax error in JSON text in argument 2 to function 'json_array_intersect' at position 1
select json_array_intersect(@arr1, @num1);
json_array_intersect(@arr1, @num1)
NULL
ERROR HY000: Syntax error in JSON text in argument 2 to function 'json_array_intersect' at position 1
select json_array_intersect(@num1, @bool1);
json_array_intersect(@num1, @bool1)
NULL
ERROR HY000: Syntax error in JSON text in argument 1 to function 'json_array_intersect' at position 1
# JSON_OBJECT_FILTER_KEYS()
SET @obj1= '{ "a": 1, "b": 2, "c": 3}';
SET @obj2= '{"b" : 10, "c": 20, "d": 30}';
Expand All @@ -5428,16 +5421,13 @@ JSON_OBJECT_FILTER_KEYS(@obj1, @arr1)
NULL
# Incorrect type in input returns NULL
SELECT JSON_OBJECT_FILTER_KEYS(@obj1, @obj1);
JSON_OBJECT_FILTER_KEYS(@obj1, @obj1)
NULL
ERROR HY000: Syntax error in JSON text in argument 2 to function 'json_object_filter_keys' at position 1
SELECT JSON_OBJECT_FILTER_KEYS(@arr1, @arr1);
JSON_OBJECT_FILTER_KEYS(@arr1, @arr1)
NULL
ERROR HY000: Syntax error in JSON text in argument 1 to function 'json_object_filter_keys' at position 1
SET @obj1= '{ "a": 1, "b": {"key1": {"key2":"val2"}}, "c": [1, 2, 3] }';
SET @scalar1='2';
SELECT JSON_OBJECT_FILTER_KEYS(@obj1, @scalar1);
JSON_OBJECT_FILTER_KEYS(@obj1, @scalar1)
NULL
ERROR HY000: Syntax error in JSON text in argument 2 to function 'json_object_filter_keys' at position 1
# Checking syntax error
SET @obj1= '{ "a": 1, "b": 2, "c": 3}';
SET @obj2= '{"b" : 10, "c": 20, "d" 30}';
Expand All @@ -5448,9 +5438,8 @@ Warnings:
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_keys' at position 25
SET @obj1= '{ "a": 1, "b": {"key1": {"key2":"val2"}}, "c": [1, 2, 3] }';
SET @arr2= '[ "key2", "key1", "b" ';
SELECT JSON_OBJECT_FILTER_KEYS(@obj1, @arr1);
JSON_OBJECT_FILTER_KEYS(@obj1, @arr1)
NULL
SELECT JSON_OBJECT_FILTER_KEYS(@obj1, @arr2);
ERROR HY000: Unexpected end of JSON text in argument 2 to function 'json_object_filter_keys'
# JSON_OBJECT_TO_ARRAY()
SET @obj1= '{ "a": [1, 2, 3], "b": { "key1":"val1", "key2": {"key3":"val3"} }, "c": 3, "d" : 1, "e": "xyz", "f": true, "g" : null}';
SELECT JSON_OBJECT_TO_ARRAY(@obj1);
Expand All @@ -5472,6 +5461,8 @@ SET @arr1= '[1, 2, 3]';
SELECT JSON_OBJECT_TO_ARRAY(@arr1);
JSON_OBJECT_TO_ARRAY(@arr1)
NULL
Warnings:
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_object_to_array' at position 1
#
# MDEV-31411: JSON_ARRAY_INTERSECT/JSON_OBJECT_FILTER_KEYS should fetch
# data from a table similar to other JSON functions
Expand Down Expand Up @@ -5553,4 +5544,49 @@ full overlap jai
["2"] ["0"] NULL
["2"] ["2"] ["2"]
DROP TABLE t1;
# End of 11.4 Test
#
# MDEV-38033: JSON_SCHEMA_VALID function returning wrong result
#
SET @schema= '
{
"type": "object",
"properties":
{
"id": {
"type": "string",
"minLength": 1
},
"arr_fields": {
"type": "array",
"items": {
"type": "object",
"properties": {
"field1": {
"type": "string"
},
"field2": {
"type": "number"
}
},
"required": ["field1"]
}
}
}
}';
SET @value= '
{
"id": "zero",
"arr_fields": [
{
"field1": "A",
"field2": 123
},
{
"field1": "B"
}
]
}';
SELECT JSON_SCHEMA_VALID(@schema, @value);
JSON_SCHEMA_VALID(@schema, @value)
1
# End of 11.4 tests
60 changes: 58 additions & 2 deletions mysql-test/main/func_json.test
Original file line number Diff line number Diff line change
Expand Up @@ -4181,6 +4181,7 @@ select json_array_intersect(@obj1, @obj2);
--echo # Checking Syntax error for JSON_ARRAY_INTERSECT()
SET @obj1= '[1, 2, 3, 3, 3.0, "abc", true, true, {"key1":"val1" ]';
SET @obj2= '[3.0, 3, 5, "abc", "abc", true, {"key2":"val2"}, {"key1":"val1"}, {"key1":"val2"}]';
--error ER_JSON_SYNTAX
select json_array_intersect(@obj1, @obj2);

--echo # Checking incorrect type for input
Expand All @@ -4189,9 +4190,13 @@ SET @arr1= '[ 1, 2, 3 ]';
SET @num1= '2';
SET @str1= '"abc"';
SET @bool1= 'true';
--error ER_JSON_SYNTAX
select json_array_intersect(@obj1, @arr1);
--error ER_JSON_SYNTAX
select json_array_intersect(@arr1, @obj1);
--error ER_JSON_SYNTAX
select json_array_intersect(@arr1, @num1);
--error ER_JSON_SYNTAX
select json_array_intersect(@num1, @bool1);


Expand All @@ -4215,11 +4220,14 @@ SELECT JSON_OBJECT_FILTER_KEYS(@obj1, @arr1);

--echo # Incorrect type in input returns NULL

--error ER_JSON_SYNTAX
SELECT JSON_OBJECT_FILTER_KEYS(@obj1, @obj1);
--error ER_JSON_SYNTAX
SELECT JSON_OBJECT_FILTER_KEYS(@arr1, @arr1);

SET @obj1= '{ "a": 1, "b": {"key1": {"key2":"val2"}}, "c": [1, 2, 3] }';
SET @scalar1='2';
--error ER_JSON_SYNTAX
SELECT JSON_OBJECT_FILTER_KEYS(@obj1, @scalar1);

--echo # Checking syntax error
Expand All @@ -4230,7 +4238,8 @@ SELECT JSON_OBJECT_FILTER_KEYS (@obj1, json_array_intersect(json_keys(@obj1), js

SET @obj1= '{ "a": 1, "b": {"key1": {"key2":"val2"}}, "c": [1, 2, 3] }';
SET @arr2= '[ "key2", "key1", "b" ';
SELECT JSON_OBJECT_FILTER_KEYS(@obj1, @arr1);
--error ER_JSON_EOS
SELECT JSON_OBJECT_FILTER_KEYS(@obj1, @arr2);


--echo # JSON_OBJECT_TO_ARRAY()
Expand Down Expand Up @@ -4329,4 +4338,51 @@ SELECT full, overlap, json_array_intersect(full, overlap) as jai from t1;

DROP TABLE t1;

--echo # End of 11.4 Test
--echo #
--echo # MDEV-38033: JSON_SCHEMA_VALID function returning wrong result
--echo #

SET @schema= '
{
"type": "object",
"properties":
{
"id": {
"type": "string",
"minLength": 1
},
"arr_fields": {
"type": "array",
"items": {
"type": "object",
"properties": {
"field1": {
"type": "string"
},
"field2": {
"type": "number"
}
},
"required": ["field1"]
}
}
}
}';

SET @value= '
{
"id": "zero",
"arr_fields": [
{
"field1": "A",
"field2": 123
},
{
"field1": "B"
}
]
}';

SELECT JSON_SCHEMA_VALID(@schema, @value);

--echo # End of 11.4 tests
6 changes: 6 additions & 0 deletions mysql-test/main/func_json_notembedded.result
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ select json_array_append(@arr, '$[0]', 1);
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
select json_array_insert(@arr, '$[0]', 1);
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
select json_array_intersect(@arr, @arr);
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
select json_insert(@obj, '$.meta', 1);
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
select json_compact(@arr);
Expand All @@ -40,10 +42,14 @@ select json_merge_patch(@obj, @obj);
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
select json_merge_preserve(@obj, @arr);
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
select json_object_filter_keys(@obj, @arr);
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
select json_remove(@obj,'$.foo');
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
select json_replace(@obj,'$.foo',1);
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
select json_schema_valid(@obj, '{"type":"object"}');
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
select json_set(@arr,'$[1000]',1);
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
select ST_AsTEXT(ST_GeomFromGeoJSON(JSON_OBJECT("type", "Point", "coordinates", @arr),2)) as exp;
Expand Down
3 changes: 3 additions & 0 deletions mysql-test/main/func_json_notembedded.test
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ SET @old_debug= @@debug_dbug;
SET debug_dbug='+d,json_pause_execution';
select json_array_append(@arr, '$[0]', 1);
select json_array_insert(@arr, '$[0]', 1);
select json_array_intersect(@arr, @arr);
select json_insert(@obj, '$.meta', 1);
select json_compact(@arr);
select json_contains(@obj, '"d"', '$.c');
Expand All @@ -33,8 +34,10 @@ select json_loose(@arr);
select json_merge(@obj, @arr);
select json_merge_patch(@obj, @obj);
select json_merge_preserve(@obj, @arr);
select json_object_filter_keys(@obj, @arr);
select json_remove(@obj,'$.foo');
select json_replace(@obj,'$.foo',1);
select json_schema_valid(@obj, '{"type":"object"}');
select json_set(@arr,'$[1000]',1);
select ST_AsTEXT(ST_GeomFromGeoJSON(JSON_OBJECT("type", "Point", "coordinates", @arr),2)) as exp;
enable_abort_on_error;
Expand Down
Loading