1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-04-21 19:45:56 +03:00
Ziy1-Tan cdd41f05f3 MCOL-785 Implement DISTRIBUTED JSON functions
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
2022-08-30 22:22:23 +08:00

154 lines
2.9 KiB
Plaintext

--source ../include/disable_before_10.9.inc
--source ../include/have_columnstore.inc
--disable_warnings
DROP DATABASE IF EXISTS json_range_expr_db;
--enable_warnings
CREATE DATABASE json_range_expr_db;
USE json_range_expr_db;
--echo # Range expression is supported in MariaDB 10.9 binaries
CREATE TABLE t2(j TEXT, p TEXT) ENGINE = columnstore;
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
}';
INSERT INTO
t2
VALUES
(@json, '$.A[-2][-1]'),
(@json, '$.A[last-1][last]');
SELECT
j,
p,
JSON_EXISTS(j, p) AS result
FROM
t2;
--echo # Test case 2
CREATE TABLE t3(j TEXT, p TEXT) ENGINE = columnstore;
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
]';
INSERT INTO
t3
VALUES
(@json, '$[3][3][-2 to last]');
SELECT
j,
p,
JSON_EXISTS(j, p) AS result
FROM
t3;
-- echo # Test case 3
CREATE TABLE t4(j TEXT, p TEXT) ENGINE = columnstore;
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
]';
INSERT INTO
t4
VALUES
(@json, '$[2][2][1 to 2]'),
(@json, '$[2][2][4 to 6]'),
(@json, '$[2][2][1 to 4]');
SELECT
j,
p,
JSON_EXISTS(j, p) AS result
FROM
t4;
--echo
--echo # JSON_EXTRACT
--echo
CREATE TABLE t5(j LONGTEXT, p LONGTEXT) ENGINE = COLUMNSTORE;
INSERT INTO
t5
VALUES
('[1, "val2", [3.1, -4]]', '$'),
('1', '$'),
('[10, 20, [30, 40]]', '$[2][*]'),
('[10, 20, [{"a":3}, 30, 40]]', '$[2][*]'),
(json_object('foo', 'foobar'), '$');
SELECT
j,
p,
JSON_EXTRACT(j, p) AS result
FROM
t5;
--echo
--echo # JSON_EXTRACT
--echo
CREATE TABLE t6(j TEXT, f TEXT, v TEXT, e TEXT, p TEXT) ENGINE = COLUMNSTORE;
SET
@j = '["abc", [{"k": "10"}, "def"], {"x":"abc"}, {"y":"bcd"}]';
INSERT INTO
t6
VALUES
(@j, 'all', 'abc', NULL, '$'),
(@j, 'all', '10', NULL, '$'),
(@j, 'all', '10', NULL, '$[*]'),
(@j, 'all', '10', NULL, '$[*][0].k'),
(@j, 'all', '10', NULL, '$**.k');
SELECT
j AS json,
f AS return_arg,
v AS search_str,
e AS escape_char,
p AS path,
JSON_SEARCH(j, f, v, NULL, p) AS result
FROM
t6;
DROP TABLE t6;
DROP TABLE t5;
DROP TABLE t4;
DROP TABLE t3;
DROP TABLE t2;
DROP DATABASE json_range_expr_db;