mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-04-20 09:07:44 +03:00
The following functions are created: Create function JSON_VALID and test cases Create function JSON_DEPTH and test cases Create function JSON_LENGTH and test cases Create function JSON_EQUALS and test cases Create function JSON_NORMALIZE and test cases Create function JSON_TYPE and test cases Create function JSON_OBJECT and test cases Create function JSON_ARRAY and test cases Create function JSON_KEYS and test cases Create function JSON_EXISTS and test cases Create function JSON_QUOTE/JSON_UNQUOTE and test cases Create function JSON_COMPACT/DETAILED/LOOSE and test cases Create function JSON_MERGE and test cases Create function JSON_MERGE_PATCH and test cases Create function JSON_VALUE and test cases Create function JSON_QUERY and test cases Create function JSON_CONTAINS and test cases Create function JSON_ARRAY_APPEND and test cases Create function JSON_ARRAY_INSERT and test cases Create function JSON_INSERT/REPLACE/SET and test cases Create function JSON_REMOVE and test cases Create function JSON_CONTAINS_PATH and test cases Create function JSON_OVERLAPS and test cases Create function JSON_EXTRACT and test cases Create function JSON_SEARCH and test cases Note: Some functions output differs from MDB because session variables that affects functions output,e.g JSON_QUOTE/JSON_UNQUOTE This depends on MCOL-5212
106 lines
4.0 KiB
Plaintext
106 lines
4.0 KiB
Plaintext
DROP DATABASE IF EXISTS json_merge_db;
|
|
CREATE DATABASE json_merge_db;
|
|
USE json_merge_db;
|
|
# ----------------------------------------------------------------------
|
|
# Test of JSON_MERGE function.
|
|
# ----------------------------------------------------------------------
|
|
CREATE TABLE t1(l TEXT, r TEXT) ENGINE = columnstore;
|
|
INSERT INTO t1 VALUES('[1, 2, 3]','[4, 5, 6]');
|
|
# Not enough args
|
|
SELECT JSON_MERGE() FROM t1;
|
|
ERROR 42000: Incorrect parameter count in the call to native function 'JSON_MERGE'
|
|
SELECT JSON_MERGE(l) FROM t1;
|
|
ERROR 42000: Incorrect parameter count in the call to native function 'JSON_MERGE'
|
|
SELECT JSON_MERGE(NULL) FROM t1;
|
|
ERROR 42000: Incorrect parameter count in the call to native function 'JSON_MERGE'
|
|
# Null args
|
|
SELECT JSON_MERGE(NULL, r) FROM t1;
|
|
JSON_MERGE(NULL, r)
|
|
NULL
|
|
SELECT JSON_MERGE(l, NULL) FROM t1;
|
|
JSON_MERGE(l, NULL)
|
|
NULL
|
|
SELECT JSON_MERGE(NULL, l, r) FROM t1;
|
|
JSON_MERGE(NULL, l, r)
|
|
NULL
|
|
SELECT JSON_MERGE(l, NULL, r) FROM t1;
|
|
JSON_MERGE(l, NULL, r)
|
|
NULL
|
|
SELECT JSON_MERGE(l, r, NULL) FROM t1;
|
|
JSON_MERGE(l, r, NULL)
|
|
NULL
|
|
# Invalid JSON text
|
|
error ER_INVALID_JSON_TEXT_IN_PARAM
|
|
SELECT JSON_MERGE(l, '[4, 5, 6') FROM t1;
|
|
JSON_MERGE(l, '[4, 5, 6')
|
|
NULL
|
|
error ER_INVALID_JSON_TEXT_IN_PARAM
|
|
SELECT JSON_MERGE('[1, 2, 3', r) FROM t1;
|
|
JSON_MERGE('[1, 2, 3', r)
|
|
NULL
|
|
# Good JSON_MERGE() Expressions
|
|
TRUNCATE t1;
|
|
INSERT INTO t1 VALUES('1', '2' );
|
|
INSERT INTO t1 VALUES('1', '[2, 3]' );
|
|
INSERT INTO t1 VALUES('[1, 2]', '3' );
|
|
INSERT INTO t1 VALUES('1', '{ "a": 2 }' );
|
|
INSERT INTO t1 VALUES('{ "a": 2 }', '1' );
|
|
INSERT INTO t1 VALUES('[1, 2]', '[3, 4]' );
|
|
INSERT INTO t1 VALUES('{ "a": 2 }', '{ "b": 3}' );
|
|
INSERT INTO t1 VALUES('[1, 2]', '{ "a": 2 }' );
|
|
INSERT INTO t1 VALUES('{ "a": 2 }', '[1, 2]' );
|
|
INSERT INTO t1 VALUES('{"a": 1, "b": 2 }', '{"b": 3, "d": 4 }' );
|
|
INSERT INTO t1 VALUES('{"a": 1, "b": 2 }', '{"b": [3, 4], "d": 4 }' );
|
|
INSERT INTO t1 VALUES('{"a": 1, "b": [2, 3] }', '{"b": 4, "d": 4 }' );
|
|
INSERT INTO t1 VALUES('{"a": 1, "b": 2 }', '{"b": {"e": 7, "f": 8}, "d": 4 }' );
|
|
INSERT INTO t1 VALUES('{"b": {"e": 7, "f": 8}, "d": 4 }', '{"a": 1, "b": 2 }' );
|
|
INSERT INTO t1 VALUES('{"a": 1, "b": [2, 9] }', '{"b": [10, 11], "d": 4 }' );
|
|
INSERT INTO t1 VALUES('{"a": 1, "b": [2, 9] }', '{"b": {"e": 7, "f": 8}, "d": 4 }' );
|
|
INSERT INTO t1 VALUES('{"b": {"e": 7, "f": 8}, "d": 4 }', '{"a": 1, "b": [2, 9] }' );
|
|
INSERT INTO t1 VALUES('{"b": {"e": 7, "f": 8}, "d": 4 }', '{ "a": 1, "b": {"e": 20, "g": 21 } }' );
|
|
INSERT INTO t1 VALUES('{ "a" : "foo", "b" : [ true, { "c" : 123 } ] }', '[ 5, 6]');
|
|
INSERT INTO t1 VALUES('{ "a" : "foo", "b" : [ true, { "c" : 123 } ] }', '{ "b": [ false, 34 ] }');
|
|
INSERT INTO t1 VALUES('{ "a" : "foo", "b" : [ true, { "c" : 123 } ] }','{ "b": "bar" }');
|
|
INSERT INTO t1 VALUES('{ "a" : { "b" : 1 } }','{ "a" : { "c" : 1 } }');
|
|
SELECT JSON_MERGE(l, r) FROM t1;
|
|
JSON_MERGE(l, r)
|
|
[1, 2]
|
|
[1, 2, 3]
|
|
[1, 2, 3]
|
|
[1, {"a": 2}]
|
|
[{"a": 2}, 1]
|
|
[1, 2, 3, 4]
|
|
{"a": 2, "b": 3}
|
|
[1, 2, {"a": 2}]
|
|
[{"a": 2}, 1, 2]
|
|
{"a": 1, "b": [2, 3], "d": 4}
|
|
{"a": 1, "b": [2, 3, 4], "d": 4}
|
|
{"a": 1, "b": [2, 3, 4], "d": 4}
|
|
{"a": 1, "b": [2, {"e": 7, "f": 8}], "d": 4}
|
|
{"b": [{"e": 7, "f": 8}, 2], "d": 4, "a": 1}
|
|
{"a": 1, "b": [2, 9, 10, 11], "d": 4}
|
|
{"a": 1, "b": [2, 9, {"e": 7, "f": 8}], "d": 4}
|
|
{"b": [{"e": 7, "f": 8}, 2, 9], "d": 4, "a": 1}
|
|
{"b": {"e": [7, 20], "f": 8, "g": 21}, "d": 4, "a": 1}
|
|
[{"a": "foo", "b": [true, {"c": 123}]}, 5, 6]
|
|
{"a": "foo", "b": [true, {"c": 123}, false, 34]}
|
|
{"a": "foo", "b": [true, {"c": 123}, "bar"]}
|
|
{"a": {"b": 1, "c": 1}}
|
|
CREATE TABLE t2(l1 TEXT, l2 TEXT, l3 TEXT) ENGINE = columnstore;
|
|
INSERT INTO t2 VALUES('1', '2', '3' );
|
|
INSERT INTO t2 VALUES('[1, 2 ]', '3', '[4, 5]' );
|
|
INSERT INTO t2 VALUES
|
|
(
|
|
'{ "a": true, "b": { "c": 3, "d": 4 }, "e": [ 1, 2 ] }',
|
|
'{ "d": false, "b": { "g": 3, "d": 5 }, "f": [ 1, 2 ] }',
|
|
'{ "m": true, "b": { "h": 8, "d": 4 }, "e": [ 3, 4 ] }'
|
|
);
|
|
SELECT JSON_MERGE(l1, l2, l3) from t2;
|
|
JSON_MERGE(l1, l2, l3)
|
|
[1, 2, 3]
|
|
[1, 2, 3, 4, 5]
|
|
{"a": true, "b": {"c": 3, "d": [4, 5, 4], "g": 3, "h": 8}, "e": [1, 2, 3, 4], "d": false, "f": [1, 2], "m": true}
|
|
DROP TABLE t1;
|
|
DROP TABLE t2;
|
|
DROP DATABASE json_merge_db;
|