Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests with JSON_ARRAYAGG and JSON_OBJECTAGG aggregates #7186

Merged
merged 1 commit into from
Sep 7, 2023
Merged
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
82 changes: 82 additions & 0 deletions src/test/regress/expected/pg16.out
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,88 @@ SET citus.shard_replication_factor TO 1;
-- DEFAULT cannot be used in COPY TO
COPY (select 1 as test) TO stdout WITH (default '\D');
ERROR: COPY DEFAULT only available using COPY FROM
-- Tests for SQL/JSON: JSON_ARRAYAGG and JSON_OBJECTAGG aggregates
-- Relevant PG commit:
-- https://github.com/postgres/postgres/commit/7081ac4
SET citus.next_shard_id TO 952000;
CREATE TABLE agg_test(a int, b serial);
SELECT create_distributed_table('agg_test', 'a');
create_distributed_table
---------------------------------------------------------------------

(1 row)

INSERT INTO agg_test SELECT i FROM generate_series(1, 5) i;
-- JSON_ARRAYAGG with distribution key
SELECT JSON_ARRAYAGG(a ORDER BY a),
JSON_ARRAYAGG(a ORDER BY a RETURNING jsonb)
FROM agg_test;
json_arrayagg | json_arrayagg
---------------------------------------------------------------------
[1, 2, 3, 4, 5] | [1, 2, 3, 4, 5]
(1 row)

-- JSON_ARRAYAGG with other column
SELECT JSON_ARRAYAGG(b ORDER BY b),
JSON_ARRAYAGG(b ORDER BY b RETURNING jsonb)
FROM agg_test;
json_arrayagg | json_arrayagg
---------------------------------------------------------------------
[1, 2, 3, 4, 5] | [1, 2, 3, 4, 5]
(1 row)

-- JSON_ARRAYAGG with router query
SET citus.log_remote_commands TO on;
SELECT JSON_ARRAYAGG(a ORDER BY a),
JSON_ARRAYAGG(a ORDER BY a RETURNING jsonb)
FROM agg_test WHERE a = 2;
NOTICE: issuing SELECT JSON_ARRAYAGG(a ORDER BY a RETURNING json) AS "json_arrayagg", JSON_ARRAYAGG(a ORDER BY a RETURNING jsonb) AS "json_arrayagg" FROM pg16.agg_test_952000 agg_test WHERE (a OPERATOR(pg_catalog.=) 2)
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
json_arrayagg | json_arrayagg
---------------------------------------------------------------------
[2] | [2]
(1 row)

RESET citus.log_remote_commands;
-- JSON_OBJECTAGG with distribution key
SELECT
JSON_OBJECTAGG(a: a),
JSON_ARRAYAGG(a ORDER BY a), -- for order
JSON_OBJECTAGG(a: a RETURNING jsonb)
FROM
agg_test;
json_objectagg | json_arrayagg | json_objectagg
---------------------------------------------------------------------
{ "1" : 1, "2" : 2, "3" : 3, "4" : 4, "5" : 5 } | [1, 2, 3, 4, 5] | {"1": 1, "2": 2, "3": 3, "4": 4, "5": 5}
(1 row)

-- JSON_OBJECTAGG with other column
SELECT
JSON_OBJECTAGG(b: b),
JSON_ARRAYAGG(b ORDER BY b), -- for order
JSON_OBJECTAGG(b: b RETURNING jsonb)
FROM
agg_test;
json_objectagg | json_arrayagg | json_objectagg
---------------------------------------------------------------------
{ "1" : 1, "2" : 2, "3" : 3, "4" : 4, "5" : 5 } | [1, 2, 3, 4, 5] | {"1": 1, "2": 2, "3": 3, "4": 4, "5": 5}
(1 row)

-- JSON_OBJECTAGG with router query
SET citus.log_remote_commands TO on;
SELECT
JSON_OBJECTAGG(a: a),
JSON_OBJECTAGG(a: a RETURNING jsonb)
FROM
agg_test WHERE a = 3;
NOTICE: issuing SELECT JSON_OBJECTAGG(a : a RETURNING json) AS "json_objectagg", JSON_OBJECTAGG(a : a RETURNING jsonb) AS "json_objectagg" FROM pg16.agg_test_952000 agg_test WHERE (a OPERATOR(pg_catalog.=) 3)
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
json_objectagg | json_objectagg
---------------------------------------------------------------------
{ "3" : 3 } | {"3": 3}
(1 row)

RESET citus.log_remote_commands;
-- Tests for SQL/JSON: support the IS JSON predicate
-- Relevant PG commit:
-- https://github.com/postgres/postgres/commit/6ee30209
Expand Down
51 changes: 51 additions & 0 deletions src/test/regress/sql/pg16.sql
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,57 @@ SET citus.shard_replication_factor TO 1;
-- DEFAULT cannot be used in COPY TO
COPY (select 1 as test) TO stdout WITH (default '\D');

-- Tests for SQL/JSON: JSON_ARRAYAGG and JSON_OBJECTAGG aggregates
-- Relevant PG commit:
-- https://github.com/postgres/postgres/commit/7081ac4
SET citus.next_shard_id TO 952000;

CREATE TABLE agg_test(a int, b serial);
SELECT create_distributed_table('agg_test', 'a');
INSERT INTO agg_test SELECT i FROM generate_series(1, 5) i;

-- JSON_ARRAYAGG with distribution key
SELECT JSON_ARRAYAGG(a ORDER BY a),
JSON_ARRAYAGG(a ORDER BY a RETURNING jsonb)
FROM agg_test;

-- JSON_ARRAYAGG with other column
SELECT JSON_ARRAYAGG(b ORDER BY b),
JSON_ARRAYAGG(b ORDER BY b RETURNING jsonb)
FROM agg_test;

-- JSON_ARRAYAGG with router query
SET citus.log_remote_commands TO on;
SELECT JSON_ARRAYAGG(a ORDER BY a),
JSON_ARRAYAGG(a ORDER BY a RETURNING jsonb)
FROM agg_test WHERE a = 2;
RESET citus.log_remote_commands;

-- JSON_OBJECTAGG with distribution key
SELECT
JSON_OBJECTAGG(a: a),
JSON_ARRAYAGG(a ORDER BY a), -- for order
JSON_OBJECTAGG(a: a RETURNING jsonb)
FROM
agg_test;

-- JSON_OBJECTAGG with other column
SELECT
JSON_OBJECTAGG(b: b),
JSON_ARRAYAGG(b ORDER BY b), -- for order
JSON_OBJECTAGG(b: b RETURNING jsonb)
FROM
agg_test;

-- JSON_OBJECTAGG with router query
SET citus.log_remote_commands TO on;
SELECT
JSON_OBJECTAGG(a: a),
JSON_OBJECTAGG(a: a RETURNING jsonb)
FROM
agg_test WHERE a = 3;
RESET citus.log_remote_commands;

-- Tests for SQL/JSON: support the IS JSON predicate
-- Relevant PG commit:
-- https://github.com/postgres/postgres/commit/6ee30209
Expand Down