Skip to content

Commit

Permalink
add e2e tests for jsonb_agg and jsonb_build_array/object
Browse files Browse the repository at this point in the history
Signed-off-by: Runji Wang <wangrunji0408@163.com>
  • Loading branch information
wangrunji0408 committed Nov 3, 2023
1 parent 621300b commit be0679f
Showing 2 changed files with 125 additions and 8 deletions.
111 changes: 103 additions & 8 deletions e2e_test/batch/aggregate/jsonb_agg.slt.part
Original file line number Diff line number Diff line change
@@ -2,27 +2,27 @@ statement ok
SET RW_IMPLICIT_FLUSH TO true;

statement ok
create table t(v1 boolean, v2 int, v3 varchar, v4 jsonb);
create table t(v1 boolean, v2 int, v3 varchar, v4 jsonb, v5 timestamp, v6 interval);

statement ok
insert into t values
(null, null, null, null),
(false, 1, 'ccc', 'null'),
(true, 2, 'bbb', 'false'),
(true, 3, 'aaa', '{}');
(null, null, null, null, null, null),
(false, 1, 'ccc', 'null', '2019-01-01 01:00:00', '1 day'),
(true, 2, 'bbb', 'false', '2020-01-01 02:00:00', '2 days'),
(true, 3, 'aaa', '{}', '2021-01-01 03:00:00', '3 days');

query T
select jsonb_agg(v1) from t;
----
[null, false, true, true]

query T
select jsonb_agg(v2) from t;
select jsonb_agg(v2::int2) from t;
----
[null, 1, 2, 3]

query T
select jsonb_agg(v2::int2) from t;
select jsonb_agg(v2::int4) from t;
----
[null, 1, 2, 3]

@@ -41,16 +41,51 @@ select jsonb_agg(v2::float8) from t;
----
[null, 1.0, 2.0, 3.0]

query T
select jsonb_agg(v2::decimal) from t;
----
[null, 1, 2, 3]

query T
select jsonb_agg(v3) from t;
----
[null, "ccc", "bbb", "aaa"]

query T
select jsonb_agg(v3::bytea) from t;
----
[null, "\\x636363", "\\x626262", "\\x616161"]

query T
select jsonb_agg(v4) from t;
----
[null, null, false, {}]

query T
select jsonb_agg(v5::date) from t;
----
[null, "2019-01-01", "2020-01-01", "2021-01-01"]

query T
select jsonb_agg(v5::time) from t;
----
[null, "01:00:00", "02:00:00", "03:00:00"]

query T
select jsonb_agg(v5::timestamp) from t;
----
[null, "2019-01-01T01:00:00", "2020-01-01T02:00:00", "2021-01-01T03:00:00"]

query T
select jsonb_agg(v5::timestamptz) from t;
----
[null, "2019-01-01T01:00:00+00:00", "2020-01-01T02:00:00+00:00", "2021-01-01T03:00:00+00:00"]

query T
select jsonb_agg(v6) from t;
----
[null, "1 day", "2 days", "3 days"]

# query T
# select jsonb_agg(distinct v1) from t;
# ----
@@ -75,14 +110,74 @@ select jsonb_object_agg(v3, v1) filter (where v3 is not null) from t;
{"aaa": true, "bbb": true, "ccc": false}

query T
select jsonb_object_agg(v3, v2) filter (where v3 is not null) from t;
select jsonb_object_agg(v3, v2::int2) filter (where v3 is not null) from t;
----
{"aaa": 3, "bbb": 2, "ccc": 1}

query T
select jsonb_object_agg(v3, v2::int4) filter (where v3 is not null) from t;
----
{"aaa": 3, "bbb": 2, "ccc": 1}

query T
select jsonb_object_agg(v3, v2::int8) filter (where v3 is not null) from t;
----
{"aaa": 3, "bbb": 2, "ccc": 1}

query T
select jsonb_object_agg(v3, v2::float4) filter (where v3 is not null) from t;
----
{"aaa": 3.0, "bbb": 2.0, "ccc": 1.0}

query T
select jsonb_object_agg(v3, v2::float8) filter (where v3 is not null) from t;
----
{"aaa": 3.0, "bbb": 2.0, "ccc": 1.0}

query T
select jsonb_object_agg(v3, v2::decimal) filter (where v3 is not null) from t;
----
{"aaa": 3, "bbb": 2, "ccc": 1}

query T
select jsonb_object_agg(v3, v3) filter (where v3 is not null) from t;
----
{"aaa": "aaa", "bbb": "bbb", "ccc": "ccc"}

query T
select jsonb_object_agg(v3, v3::bytea) filter (where v3 is not null) from t;
----
{"aaa": "\\x616161", "bbb": "\\x626262", "ccc": "\\x636363"}

query T
select jsonb_object_agg(v3, v4) filter (where v3 is not null) from t;
----
{"aaa": {}, "bbb": false, "ccc": null}

query T
select jsonb_object_agg(v3, v5::date) filter (where v3 is not null) from t;
----
{"aaa": "2021-01-01", "bbb": "2020-01-01", "ccc": "2019-01-01"}

query T
select jsonb_object_agg(v3, v5::time) filter (where v3 is not null) from t;
----
{"aaa": "03:00:00", "bbb": "02:00:00", "ccc": "01:00:00"}

query T
select jsonb_object_agg(v3, v5::timestamp) filter (where v3 is not null) from t;
----
{"aaa": "2021-01-01T03:00:00", "bbb": "2020-01-01T02:00:00", "ccc": "2019-01-01T01:00:00"}

query T
select jsonb_object_agg(v3, v5::timestamptz) filter (where v3 is not null) from t;
----
{"aaa": "2021-01-01T03:00:00+00:00", "bbb": "2020-01-01T02:00:00+00:00", "ccc": "2019-01-01T01:00:00+00:00"}

query T
select jsonb_object_agg(v3, v6) filter (where v3 is not null) from t;
----
{"aaa": "3 days", "bbb": "2 days", "ccc": "1 day"}

statement ok
drop table t;
22 changes: 22 additions & 0 deletions e2e_test/batch/basic/to_jsonb.slt.part
Original file line number Diff line number Diff line change
@@ -255,5 +255,27 @@ SELECT to_jsonb(row(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14,
{"f1": true, "f10": "22:12:40", "f11": "2023-09-01T22:11:27", "f12": null, "f13": "-00:01:00", "f14": null, "f15": [252, 137, 110, 574], "f16": ["t5073iSwvs"], "f17": "\\x80", "f18": null, "f2": 7096, "f3": -1627323193, "f4": 191.0, "f5": 483.0, "f6": 85.0, "f7": -2147483648.0, "f8": "2023-09-01", "f9": "sLgs9Am1iP"}
{"f1": false, "f10": "22:12:37", "f11": "2023-09-01T22:11:40", "f12": "2023-09-01T22:12:37+00:00", "f13": "00:00:28", "f14": null, "f15": [355], "f16": ["xan6o2VHID", "MTSy3lzImo", "UZqnEMW60w"], "f17": "\\xaabbccddeeff", "f18": "value3", "f2": 972, "f3": -235825836, "f4": 842.0, "f5": 27.0, "f6": 675.0, "f7": 0.0, "f8": "2023-08-25", "f9": "uwAFEeex9Y"}

query T
SELECT jsonb_build_array(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18) from alltypes;
----
[true, 786, 1409922817, 925.0, 536.0, 782.0, 487.0, "2023-09-01", "IwfwuseZmg", "22:12:54", "2023-09-01T22:12:42", "2023-09-01T22:12:42+00:00", "-00:01:18", null, [354, 627], ["yRMgX7pFXW", "r7PAN6KB2b", "NQJbRQoVib"], null, {"key1": "value1"}]
[true, 82, 216, 732.0, 337.0, 772.0, 378.0, "2023-09-01", "6nNf6LL2C1", "22:12:25", "2023-09-01T21:12:54", "2023-09-01T21:12:54+00:00", "24:00:00", null, [0], ["3NE5ewEx4T"], "\\xdeadbeef", {"key2": "value2"}]
[false, 761, 966, 153.0, 1023789440.0, 752.0, 630.0, "2023-09-01", "ySrgeBXDuc", "22:11:17", "2023-09-01T22:11:50", null, "-00:01:31", null, [77, 718, 401, 874], ["k6N5rUX8p1", "sFRQ1u2ihF"], "\\x0123456789abcdef", null]
[false, 255, 1, 9.223372036854776e18, 0.0, 775.0, -2147483648.0, "2023-09-01", "2498VN2txc", "22:11:54", "2023-09-01T22:12:54", "2023-09-01T21:12:54+00:00", "-00:01:24", null, [246, 120, 154], ["Rau1Iezv50", "uWtqX1jIP0", "N356wachUq", "tDVFlmtDNk"], "\\x00ff00", {"key3": ["value3", "value55"]}]
[true, 933, 915, 433.0, 734.0, 438.0, 998512901.0, "2023-09-01", "Qgfzps4qkX", "22:12:54", "2023-09-01T22:12:02", "2023-09-01T22:12:02+00:00", "01:00:00", null, [329, 577, 255, 70], ["1HQloIk7oW", "ixxNgP8vaq", "9CSOsftyRA", "jiqocRdrUC"], null, {"key4": {"inner_key": "value4"}}]
[true, 7096, -1627323193, 191.0, 483.0, 85.0, -2147483648.0, "2023-09-01", "sLgs9Am1iP", "22:12:40", "2023-09-01T22:11:27", null, "-00:01:00", null, [252, 137, 110, 574], ["t5073iSwvs"], "\\x80", null]
[false, 972, -235825836, 842.0, 27.0, 675.0, 0.0, "2023-08-25", "uwAFEeex9Y", "22:12:37", "2023-09-01T22:11:40", "2023-09-01T22:12:37+00:00", "00:00:28", null, [355], ["xan6o2VHID", "MTSy3lzImo", "UZqnEMW60w"], "\\xaabbccddeeff", "value3"]

query T
SELECT jsonb_build_object('f1', c1, 'f2', c2, 'f3', c3, 'f4', c4, 'f5', c5, 'f6', c6, 'f7', c7, 'f8', c8, 'f9', c9, 'f10', c10, 'f11', c11, 'f12', c12, 'f13', c13, 'f14', c14, 'f15', c15, 'f16', c16, 'f17', c17, 'f18', c18) from alltypes;
----
{"f1": true, "f10": "22:12:54", "f11": "2023-09-01T22:12:42", "f12": "2023-09-01T22:12:42+00:00", "f13": "-00:01:18", "f14": null, "f15": [354, 627], "f16": ["yRMgX7pFXW", "r7PAN6KB2b", "NQJbRQoVib"], "f17": null, "f18": {"key1": "value1"}, "f2": 786, "f3": 1409922817, "f4": 925.0, "f5": 536.0, "f6": 782.0, "f7": 487.0, "f8": "2023-09-01", "f9": "IwfwuseZmg"}
{"f1": true, "f10": "22:12:25", "f11": "2023-09-01T21:12:54", "f12": "2023-09-01T21:12:54+00:00", "f13": "24:00:00", "f14": null, "f15": [0], "f16": ["3NE5ewEx4T"], "f17": "\\xdeadbeef", "f18": {"key2": "value2"}, "f2": 82, "f3": 216, "f4": 732.0, "f5": 337.0, "f6": 772.0, "f7": 378.0, "f8": "2023-09-01", "f9": "6nNf6LL2C1"}
{"f1": false, "f10": "22:11:17", "f11": "2023-09-01T22:11:50", "f12": null, "f13": "-00:01:31", "f14": null, "f15": [77, 718, 401, 874], "f16": ["k6N5rUX8p1", "sFRQ1u2ihF"], "f17": "\\x0123456789abcdef", "f18": null, "f2": 761, "f3": 966, "f4": 153.0, "f5": 1023789440.0, "f6": 752.0, "f7": 630.0, "f8": "2023-09-01", "f9": "ySrgeBXDuc"}
{"f1": false, "f10": "22:11:54", "f11": "2023-09-01T22:12:54", "f12": "2023-09-01T21:12:54+00:00", "f13": "-00:01:24", "f14": null, "f15": [246, 120, 154], "f16": ["Rau1Iezv50", "uWtqX1jIP0", "N356wachUq", "tDVFlmtDNk"], "f17": "\\x00ff00", "f18": {"key3": ["value3", "value55"]}, "f2": 255, "f3": 1, "f4": 9.223372036854776e18, "f5": 0.0, "f6": 775.0, "f7": -2147483648.0, "f8": "2023-09-01", "f9": "2498VN2txc"}
{"f1": true, "f10": "22:12:54", "f11": "2023-09-01T22:12:02", "f12": "2023-09-01T22:12:02+00:00", "f13": "01:00:00", "f14": null, "f15": [329, 577, 255, 70], "f16": ["1HQloIk7oW", "ixxNgP8vaq", "9CSOsftyRA", "jiqocRdrUC"], "f17": null, "f18": {"key4": {"inner_key": "value4"}}, "f2": 933, "f3": 915, "f4": 433.0, "f5": 734.0, "f6": 438.0, "f7": 998512901.0, "f8": "2023-09-01", "f9": "Qgfzps4qkX"}
{"f1": true, "f10": "22:12:40", "f11": "2023-09-01T22:11:27", "f12": null, "f13": "-00:01:00", "f14": null, "f15": [252, 137, 110, 574], "f16": ["t5073iSwvs"], "f17": "\\x80", "f18": null, "f2": 7096, "f3": -1627323193, "f4": 191.0, "f5": 483.0, "f6": 85.0, "f7": -2147483648.0, "f8": "2023-09-01", "f9": "sLgs9Am1iP"}
{"f1": false, "f10": "22:12:37", "f11": "2023-09-01T22:11:40", "f12": "2023-09-01T22:12:37+00:00", "f13": "00:00:28", "f14": null, "f15": [355], "f16": ["xan6o2VHID", "MTSy3lzImo", "UZqnEMW60w"], "f17": "\\xaabbccddeeff", "f18": "value3", "f2": 972, "f3": -235825836, "f4": 842.0, "f5": 27.0, "f6": 675.0, "f7": 0.0, "f8": "2023-08-25", "f9": "uwAFEeex9Y"}

statement ok
DROP TABLE alltypes;

0 comments on commit be0679f

Please sign in to comment.