1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +03:00

func json_arrayagg test adjustments

This commit is contained in:
mariadb-AndreyPiskunov
2022-11-02 16:06:05 +02:00
parent c2ae123020
commit 8b4be1b7f9
2 changed files with 37 additions and 30 deletions

View File

@ -8,7 +8,9 @@ USE json_arrayagg_db;
CREATE TABLE t1 (a INT, b INT)ENGINE=COLUMNSTORE;
INSERT INTO t1 VALUES (1, 1),(2, 1), (1, 1),(2, 1), (3, 2),(2, 2),(2, 2),(2, 2);
SELECT JSON_VALID(JSON_ARRAYAGG(a)) FROM t1;
sorted_result;
SELECT JSON_ARRAYAGG(a), JSON_ARRAYAGG(b) FROM t1;
sorted_result;
SELECT JSON_ARRAYAGG(a), JSON_ARRAYAGG(b) FROM t1 GROUP BY b;
DROP TABLE t1;
@ -18,6 +20,7 @@ DROP TABLE t1;
CREATE TABLE t1 (a FLOAT, b DOUBLE, c DECIMAL(10, 2))ENGINE=COLUMNSTORE;
INSERT INTO t1 VALUES (1.0, 2.0, 3.0),(1.0, 3.0, 9.0),(1.0, 4.0, 16.0),(1.0, 5.0, 25.0);
SELECT JSON_VALID(JSON_ARRAYAGG(a)) FROM t1;
sorted_result;
SELECT JSON_ARRAYAGG(a), JSON_ARRAYAGG(b), JSON_ARRAYAGG(c) FROM t1;
DROP TABLE t1;
@ -31,6 +34,7 @@ sorted_result;
SELECT JSON_ARRAYAGG(a), JSON_ARRAYAGG(b) FROM t1;
sorted_result;
SELECT JSON_ARRAYAGG(a), JSON_ARRAYAGG(b) FROM t1 GROUP BY b;
sorted_result;
SELECT JSON_ARRAYAGG(TRUE), JSON_ARRAYAGG(FALSE) FROM t1;
DROP TABLE t1;
@ -42,6 +46,7 @@ INSERT INTO t1 VALUES
('"double_quoted_value"'), ("'single_quoted_value'"),
('"double_quoted_value"'), ("'single_quoted_value'");
SELECT JSON_VALID(JSON_ARRAYAGG(a)) FROM t1;
sorted_result;
SELECT JSON_ARRAYAGG(a) FROM t1;
DROP TABLE t1;
@ -53,32 +58,44 @@ INSERT INTO t1 VALUES
(1, "Hello"),(1, "World"), (2, "This"),(2, "Will"), (2, "Work"),(2, "!"), (3, NULL),
(1, "Hello"),(1, "World"), (2, "This"),(2, "Will"), (2, "Work"),(2, "!"), (3, NULL);
SELECT JSON_VALID(JSON_ARRAYAGG(b)) FROM t1;
sorted_result;
SELECT JSON_ARRAYAGG(a), JSON_ARRAYAGG(b) FROM t1;
sorted_result;
SELECT JSON_ARRAYAGG(a), JSON_ARRAYAGG(b) FROM t1 GROUP BY a;
-- echo #
-- echo # DISTINCT and LIMIT
-- echo #
sorted_result;
SELECT JSON_ARRAYAGG(b LIMIT 1) FROM t1;
sorted_result;
SELECT JSON_ARRAYAGG(b LIMIT 2) FROM t1;
sorted_result;
SELECT JSON_ARRAYAGG(b LIMIT 1) FROM t1 GROUP BY b;
sorted_result;
SELECT JSON_ARRAYAGG(b LIMIT 2) FROM t1 GROUP BY a;
sorted_result;
SELECT JSON_ARRAYAGG(DISTINCT a) FROM t1;
sorted_result;
SELECT JSON_ARRAYAGG(DISTINCT b) FROM t1;
sorted_result;
SELECT JSON_ARRAYAGG(DISTINCT a LIMIT 2) FROM t1;
sorted_result;
SELECT JSON_ARRAYAGG(DISTINCT b LIMIT 2) FROM t1;
-- echo #
-- echo # JSON aggregation
-- echo #
SELECT JSON_VALID(JSON_ARRAYAGG(JSON_ARRAY(a, b))) FROM t1;
sorted_result;
SELECT JSON_ARRAYAGG(JSON_ARRAY(a, b)) FROM t1;
sorted_result;
SELECT JSON_ARRAYAGG(JSON_ARRAY(a, b)) FROM t1 GROUP BY a;
SELECT JSON_VALID(JSON_ARRAYAGG(JSON_OBJECT('a', a, 'b', b))) FROM t1;
sorted_result;
SELECT JSON_ARRAYAGG(JSON_OBJECT('a', a, 'b', b)) FROM t1;
sorted_result;
SELECT JSON_ARRAYAGG(JSON_OBJECT('a', a, 'b', b)) FROM t1 GROUP BY a;
-- echo #
@ -94,18 +111,13 @@ SELECT JSON_ARRAYAGG(JSON_ARRAYAGG(a, b)) FROM t1;
SELECT JSON_ARRAYAGG(JSON_ARRAYAGG(a)) FROM t1;
-- echo #
-- echo # MDEV-16620 JSON_OBJECTAGG
-- echo #
DROP TABLE t1;
--echo #
--echo # End of 10.4 tests
--echo #
-- echo #
-- echo # MDEV-16620 JSON_ARRAYAGG
-- echo #
CREATE TABLE t1 (a INT)ENGINE=COLUMNSTORE;
@ -113,8 +125,6 @@ SELECT JSON_ARRAYAGG(a) FROM t1;
DROP TABLE t1;
-- echo #
-- echo # MDEV-21915 Server crashes in copy_fields,Item_func_group_concat::add
-- echo while using json_arrayagg() as a window function
-- echo #
--error ER_NOT_SUPPORTED_YET
@ -123,31 +133,36 @@ select json_arrayagg(a) over () from (select 1 a) t;
--error ER_NOT_SUPPORTED_YET
select json_objectagg(a, b) over () from (select 1 a, 2 b) t;
sorted_result;
SELECT JSON_ARRAYAGG(NULL) FROM (SELECT 1 AS t) AS A;
sorted_result;
SELECT JSON_ARRAYAGG("null") FROM (SELECT 1 AS t) AS A;
create view v as (select json_arrayagg(json_object("type", "permPeriod", "id", "asd")) as JSON_DATA);
select * from v;
drop view v;
sorted_result;
select json_arrayagg(a order by a asc) from (select 1 a union select 2 a) t;
sorted_result;
select json_object('x', json_arrayagg(json_object('a', 1)));
--echo #
--echo # MDEV-22011: DISTINCT with JSON_ARRAYAGG gives wrong results
--echo #
CREATE TABLE t1(a INT, b INT)ENGINE=COLUMNSTORE;
INSERT INTO t1 VALUES (1,1), (2,2), (3,3);
INSERT INTO t1 VALUES (1,1), (2,2), (3,3);
sorted_result;
SELECT JSON_ARRAYAGG(a) FROM t1;
sorted_result;
SELECT JSON_ARRAYAGG(DISTINCT a) FROM t1;
INSERT INTO t1 VALUES (NULL,NULL), (NULL,NULL);
sorted_result;
SELECT JSON_ARRAYAGG(a) FROM t1;
sorted_result;
SELECT JSON_ARRAYAGG(DISTINCT a) FROM t1;
DROP TABLE t1;
@ -155,29 +170,32 @@ CREATE TABLE t1(a VARCHAR(10), b INT)ENGINE=COLUMNSTORE;
INSERT INTO t1 VALUES (1,1), (2,2), (3,3);
INSERT INTO t1 VALUES (1,1), (2,2), (3,3);
sorted_result;
SELECT JSON_ARRAYAGG(a) FROM t1;
sorted_result;
SELECT JSON_ARRAYAGG(DISTINCT a) FROM t1;
INSERT INTO t1 VALUES (NULL,NULL), (NULL,NULL);
sorted_result;
SELECT JSON_ARRAYAGG(a) FROM t1;
sorted_result;
SELECT JSON_ARRAYAGG(DISTINCT a) FROM t1;
DROP TABLE t1;
--echo #
--echo # MDEV-22840: JSON_ARRAYAGG gives wrong results with NULL values and ORDER by clause
--echo #
CREATE TABLE t1(a VARCHAR(255))ENGINE=COLUMNSTORE;
INSERT INTO t1 VALUES ('red'),('blue');
sorted_result;
SELECT JSON_ARRAYAGG(a) FROM t1;
SELECT JSON_ARRAYAGG(a ORDER BY a DESC) FROM t1;
SELECT JSON_ARRAYAGG(a ORDER BY a ASC) FROM t1;
INSERT INTO t1 VALUES (NULL);
sorted_result;
SELECT JSON_ARRAYAGG(a) FROM t1;
SELECT JSON_ARRAYAGG(a ORDER BY a DESC) FROM t1;
SELECT JSON_ARRAYAGG(a ORDER BY a ASC) FROM t1;
@ -187,6 +205,7 @@ set group_concat_max_len=64;
create table t1 (a varchar(254))ENGINE=COLUMNSTORE;
insert into t1 values (concat('x64-', repeat('a', 60)));
insert into t1 values (concat('x64-', repeat('b', 60))); insert into t1 values (concat('x64-', repeat('c', 60)));
sorted_result;
select json_arrayagg(a) from t1;
drop table t1;
SET group_concat_max_len= default;
@ -207,7 +226,6 @@ DROP TABLE t1;
DROP TABLE t2;
--echo #
--echo # MDEV-27018 IF and COALESCE lose "json" property
--echo #
SELECT json_object('a', if(1, json_object('b', 'c'), json_object('e', 'f')));
@ -215,14 +233,14 @@ SELECT json_object('a', coalesce(json_object('b', 'c')));
--echo #
--echo # MDEV-26054 Server crashes in Item_func_json_arrayagg::get_str_from_field
--echo #
CREATE TABLE t (a VARCHAR(8))ENGINE=COLUMNSTORE;
CREATE VIEW v AS SELECT * FROM t;
INSERT INTO t VALUES ('foo'),('bar');
sorted_result;
SELECT JSON_ARRAYAGG(a) AS f FROM v;
DROP VIEW v;
DROP TABLE t;
DROP DATABASE IF EXISTS json_arrayagg_db;
DROP DATABASE IF EXISTS json_arrayagg_db;