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

fix(type): fix parsing array literal and printing struct value #13229

Merged
merged 22 commits into from
Nov 15, 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
5 changes: 2 additions & 3 deletions e2e_test/batch/basic/array.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,13 @@ select pg_typeof((v1::integer[][])[2][1]), (v1::integer[][])[2][1] from (values
integer 2

# Test multiple castings of the same input.
query TTI
query TI
select
(arr::varchar[][])[1][2] as double_varchar,
(arr::varchar[][][])[1][2][3] as triple_varchar,
(arr::integer[][][])[1][2][3] as triple_integer
from (values ('{{{1, 2, 3}, {44, 55, 66}}}')) as t(arr);
----
{44, 55, 66} 66 66
66 66

# Test cast from array to string
query T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ INSERT INTO t.t VALUES (ROW(ROW(ROW(42))));
query I
SELECT (t.t.t).t FROM t.t;
----
((42))
("(42)")

query I
SELECT (t.t.t).t.t FROM t.t;
Expand Down
12 changes: 6 additions & 6 deletions e2e_test/batch/order/test_order_struct.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ select * from t order by 1;
----
(1,2)
(1,3)
(1,NULL)
(1,)
(2,1)
(2,2)
(NULL,NULL)
(,)

statement ok
drop table t;
Expand All @@ -29,10 +29,10 @@ insert into t values (('abc',('bcd',2)),1), (('abc',('bcd',2)),2), (('a',('bcbcd
query TTII
select * from t order by 1 DESC, 2 ASC;
----
(b,(a,2)) 2
(abc,(bcd,2)) 1
(abc,(bcd,2)) 2
(a,(bcbcd,2)) 2
(b,"(a,2)") 2
(abc,"(bcd,2)") 1
(abc,"(bcd,2)") 2
(a,"(bcbcd,2)") 2

statement ok
drop table t;
10 changes: 2 additions & 8 deletions e2e_test/batch/types/jsonb.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,8 @@ b "bar"
query T
select jsonb_each('{"a":"foo", "b":"bar"}'::jsonb);
----
(a,"foo")
(b,"bar")

# FIXME: the output format is inconsistent with pg
# https://github.com/risingwavelabs/risingwave/issues/4769
#
# (a,"""foo""")
# (b,"""bar""")
(a,"""foo""")
(b,"""bar""")

statement error cannot deconstruct
select * from jsonb_each('null'::jsonb)
Expand Down
12 changes: 6 additions & 6 deletions e2e_test/batch/types/struct/nested_structs.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ INSERT INTO a VALUES (ROW(ROW(3), 4))
query I
SELECT * FROM a
----
((3),4)
("(3)",4)

query I
SELECT ((c).i).a FROM a
Expand All @@ -26,7 +26,7 @@ INSERT INTO a VALUES (NULL)
query I rowsort
SELECT * FROM a
----
((3),4)
("(3)",4)
NULL

query I rowsort
Expand All @@ -48,10 +48,10 @@ INSERT INTO a VALUES (ROW(NULL, 1))
query I rowsort
SELECT * FROM a
----
((1),NULL)
((3),4)
((NULL),1)
(NULL,1)
("()",1)
("(1)",)
("(3)",4)
(,1)
NULL

# nested struct mismatch on insertion
Expand Down
44 changes: 35 additions & 9 deletions e2e_test/batch/types/struct/struct.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ select (v2).* from st;
query II rowsort
select * from st;
----
1 (1,(1,2))
1 (1,(1,3))
1 (1,"(1,2)")
1 (1,"(1,3)")

query I
select (v2).v2.v1 from st;
Expand All @@ -43,22 +43,22 @@ select (v2).v2 from st;
query II
select * from st where v2 = (1,(1,3));
----
1 (1,(1,3))
1 (1,"(1,3)")

query II
select * from st where v2 != (1,(1,3));
----
1 (1,(1,2))
1 (1,"(1,2)")

query II
select * from st where (v2).v2 < (1,3);
----
1 (1,(1,2))
1 (1,"(1,2)")

query II
select * from st where (v2).v2 > (1,2);
----
1 (1,(1,3))
1 (1,"(1,3)")

query I
select max((v2).v2) from st;
Expand All @@ -82,15 +82,15 @@ insert into st values(1,(1,(1,null)));
query II
select * from st;
----
1 (1,(1,NULL))
1 (1,"(1,)")

statement ok
drop table st;

query T
select Row('foo', 'bar', null);
----
(foo,bar,NULL)
(foo,bar,)

query T
select Row();
Expand All @@ -100,7 +100,7 @@ select Row();
query T
select Row(null);
----
(NULL)
()

statement ok
create table t (v1 int);
Expand Down Expand Up @@ -136,3 +136,29 @@ select * from t where Row(1,v1*2) > Row(1,2);

statement ok
drop table t;

# row to text
query TTTT
select Row('a'), Row(''), Row('"'), Row(' a '), Row('a b');
----
(a) ("") ("""") (" a ") ("a b")

query TTT
select Row('{}'), Row('[]'), Row('()'), Row(',');
----
({}) ([]) ("()") (",")

query TTT
select Row(NULL), Row(NULL, NULL), Row('null');
----
() (,) (null)

query TTT
select Row(Array[] :: varchar[]), Row(Array[1] :: varchar[]), Row(Array[1,2] :: varchar[]);
----
({}) ({1}) ("{1,2}")

query T
select Row(Array['"'] :: varchar[]);
----
("{""\\""""}")
2 changes: 1 addition & 1 deletion e2e_test/batch/types/struct/struct_case.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ NULL
query I
SELECT CASE WHEN 1=0 THEN NULL ELSE ROW(NULL) END
----
(NULL)
()

# now with a table
query II
Expand Down
18 changes: 9 additions & 9 deletions e2e_test/batch/types/struct/struct_cast.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ SELECT ROW(1,2)::STRUCT<i BIGINT, j VARCHAR>;
query I
SELECT (NULL, 'hello')::STRUCT<i BIGINT, j VARCHAR>;
----
(NULL,hello)
(,hello)

query I
SELECT (NULL, NULL)::STRUCT<i BIGINT, j VARCHAR>;
----
(NULL,NULL)
(,)

query I
SELECT NULL::STRUCT<i BIGINT, j VARCHAR>;
Expand All @@ -29,7 +29,7 @@ NULL
query I
SELECT (NULL, NULL)::STRUCT<i BIGINT, j VARCHAR>;
----
(NULL,NULL)
(,)

query I
SELECT ((NULL, NULL)::STRUCT<i BIGINT, j VARCHAR>).i;
Expand All @@ -45,22 +45,22 @@ NULL
query I
SELECT (1, (2, 3))::STRUCT<i BIGINT, j STRUCT<a BIGINT, b VARCHAR>>;
----
(1,(2,3))
(1,"(2,3)")

query I
SELECT (1, (NULL, 3))::STRUCT<i BIGINT, j STRUCT<a BIGINT, b VARCHAR>>;
----
(1,(NULL,3))
(1,"(,3)")

query I
SELECT (1, (2, NULL))::STRUCT<i BIGINT, j STRUCT<a BIGINT, b VARCHAR>>;
----
(1,(2,NULL))
(1,"(2,)")

query I
SELECT (1, NULL)::STRUCT<i BIGINT, j STRUCT<a BIGINT, b VARCHAR>>;
----
(1,NULL)
(1,)

# cast and extract
query I
Expand All @@ -83,9 +83,9 @@ INSERT INTO structs VALUES ((1,2)), ((null, 2)), ((1, null)), (NULL)
query I rowsort
SELECT s FROM structs;
----
(,2)
(1,)
(1,2)
(1,NULL)
(NULL,2)
NULL

statement ok
Expand Down
50 changes: 25 additions & 25 deletions e2e_test/batch/types/struct/struct_cross_product.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,45 @@ insert into t values (1, ROW(ROW(3, 7), ARRAY[1, 2, 3])), (2, NULL), (3, ROW(NUL
query IIII
SELECT * FROM t AS v, t AS w ORDER BY v.v1, w.v1;
----
1 ((3,7),{1,2,3}) 1 ((3,7),{1,2,3})
1 ((3,7),{1,2,3}) 2 NULL
1 ((3,7),{1,2,3}) 3 (NULL,{4,5,NULL})
2 NULL 1 ((3,7),{1,2,3})
1 ("(3,7)","{1,2,3}") 1 ("(3,7)","{1,2,3}")
1 ("(3,7)","{1,2,3}") 2 NULL
1 ("(3,7)","{1,2,3}") 3 (,"{4,5,NULL}")
2 NULL 1 ("(3,7)","{1,2,3}")
2 NULL 2 NULL
2 NULL 3 (NULL,{4,5,NULL})
3 (NULL,{4,5,NULL}) 1 ((3,7),{1,2,3})
3 (NULL,{4,5,NULL}) 2 NULL
3 (NULL,{4,5,NULL}) 3 (NULL,{4,5,NULL})
2 NULL 3 (,"{4,5,NULL}")
3 (,"{4,5,NULL}") 1 ("(3,7)","{1,2,3}")
3 (,"{4,5,NULL}") 2 NULL
3 (,"{4,5,NULL}") 3 (,"{4,5,NULL}")

query IIII
SELECT * FROM t v, t w WHERE v.v1 >= w.v1 ORDER BY v.v1, w.v1;
----
1 ((3,7),{1,2,3}) 1 ((3,7),{1,2,3})
2 NULL 1 ((3,7),{1,2,3})
1 ("(3,7)","{1,2,3}") 1 ("(3,7)","{1,2,3}")
2 NULL 1 ("(3,7)","{1,2,3}")
2 NULL 2 NULL
3 (NULL,{4,5,NULL}) 1 ((3,7),{1,2,3})
3 (NULL,{4,5,NULL}) 2 NULL
3 (NULL,{4,5,NULL}) 3 (NULL,{4,5,NULL})
3 (,"{4,5,NULL}") 1 ("(3,7)","{1,2,3}")
3 (,"{4,5,NULL}") 2 NULL
3 (,"{4,5,NULL}") 3 (,"{4,5,NULL}")

query IIII
SELECT * FROM t v, t w WHERE v.v1 <> w.v1 ORDER BY v.v1, w.v1;
----
1 ((3,7),{1,2,3}) 2 NULL
1 ((3,7),{1,2,3}) 3 (NULL,{4,5,NULL})
2 NULL 1 ((3,7),{1,2,3})
2 NULL 3 (NULL,{4,5,NULL})
3 (NULL,{4,5,NULL}) 1 ((3,7),{1,2,3})
3 (NULL,{4,5,NULL}) 2 NULL
1 ("(3,7)","{1,2,3}") 2 NULL
1 ("(3,7)","{1,2,3}") 3 (,"{4,5,NULL}")
2 NULL 1 ("(3,7)","{1,2,3}")
2 NULL 3 (,"{4,5,NULL}")
3 (,"{4,5,NULL}") 1 ("(3,7)","{1,2,3}")
3 (,"{4,5,NULL}") 2 NULL

query IIII
SELECT * FROM t v, t w WHERE v.v1 <> w.v1 OR v.v1 > w.v1 ORDER BY v.v1, w.v1;
----
1 ((3,7),{1,2,3}) 2 NULL
1 ((3,7),{1,2,3}) 3 (NULL,{4,5,NULL})
2 NULL 1 ((3,7),{1,2,3})
2 NULL 3 (NULL,{4,5,NULL})
3 (NULL,{4,5,NULL}) 1 ((3,7),{1,2,3})
3 (NULL,{4,5,NULL}) 2 NULL
1 ("(3,7)","{1,2,3}") 2 NULL
1 ("(3,7)","{1,2,3}") 3 (,"{4,5,NULL}")
2 NULL 1 ("(3,7)","{1,2,3}")
2 NULL 3 (,"{4,5,NULL}")
3 (,"{4,5,NULL}") 1 ("(3,7)","{1,2,3}")
3 (,"{4,5,NULL}") 2 NULL

statement ok
drop table t;
4 changes: 2 additions & 2 deletions e2e_test/ddl/alter_rename_relation.slt
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ SELECT * from v3
query IIII rowsort
SELECT * from v4
----
1 (1,(1,2)) 1 (1,(1,2))
2 (2,(2,4)) 2 (2,(2,4))
1 (1,"(1,2)") 1 (1,"(1,2)")
2 (2,"(2,4)") 2 (2,"(2,4)")

statement ok
CREATE MATERIALIZED VIEW mv4 AS SELECT * FROM src;
Expand Down
4 changes: 2 additions & 2 deletions e2e_test/sink/kafka/avro.slt
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ select
time_micros_field,
time_millis_field from from_kafka order by string_field;
----
t Rising \x6130 3.5 4.25 22 23 NULL {{NULL,3},NULL,{7,NULL,2}} 2006-01-02 22:04:05+00:00 NULL NULL 12:34:56.123456 NULL
f Wave \x5a4446 1.5 NULL 11 12 (NULL,foo) NULL NULL 2006-01-02 22:04:05+00:00 2021-04-01 NULL 23:45:16.654
t Rising \x6130 3.5 4.25 22 23 NULL {{NULL,3},NULL,{7,NULL,2}} 2006-01-02 22:04:05+00:00 NULL NULL 12:34:56.123456 NULL
f Wave \x5a4446 1.5 NULL 11 12 (,foo) NULL NULL 2006-01-02 22:04:05+00:00 2021-04-01 NULL 23:45:16.654

statement error SchemaFetchError
create sink sink_err from into_kafka with (
Expand Down
2 changes: 1 addition & 1 deletion e2e_test/sink/kafka/protobuf.slt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ select
timestamp_field,
oneof_int32 from from_kafka order by string_field;
----
t Rising \x6130 3.5 4.25 22 23 24 0 26 27 (1,) {4,0,4} (1136239445,0) 42
t Rising \x6130 3.5 4.25 22 23 24 0 26 27 (1,"") {4,0,4} (1136239445,0) 42
f Wave \x5a4446 1.5 0 11 12 13 14 15 16 (4,foo) {} (0,0) 0

statement error failed to read file
Expand Down
6 changes: 3 additions & 3 deletions e2e_test/source/basic/kafka.slt
Original file line number Diff line number Diff line change
Expand Up @@ -629,17 +629,17 @@ select id, sequence_id, name, score, avg_score, is_lasted, entrance_date, birthd
query ITITT
select id, code, timestamp, xfas, contacts, sex from s10;
----
100 abc 1473305798 {"(0,200,10.0.0.1)","(1,400,10.0.0.2)"} ({1xxx,2xxx},{1xxx,2xxx}) MALE
100 abc 1473305798 {"(0,200,10.0.0.1)","(1,400,10.0.0.2)"} ("{1xxx,2xxx}","{1xxx,2xxx}") MALE

query ITITT
select id, code, timestamp, xfas, contacts, sex from s11;
----
0 abc 1473305798 {"(0,200,127.0.0.1)","(1,400,127.0.0.2)"} ({1xxx,2xxx},{1xxx,2xxx}) MALE
0 abc 1473305798 {"(0,200,127.0.0.1)","(1,400,127.0.0.2)"} ("{1xxx,2xxx}","{1xxx,2xxx}") MALE

query ITITT
select id, code, timestamp, xfas, contacts, jsonb from s12;
----
100 abc 1473305798 {"(0,200,10.0.0.1)","(1,400,10.0.0.2)"} ({1xxx,2xxx},{1xxx,2xxx}) {"blockNumber": 16938734}
100 abc 1473305798 {"(0,200,10.0.0.1)","(1,400,10.0.0.2)"} ("{1xxx,2xxx}","{1xxx,2xxx}") {"blockNumber": 16938734}

query ITIT
select * from s13 order by id;
Expand Down
Loading