@@ -35,6 +35,29 @@ def test_unnest(self):
35
35
"SELECT student, score, t.unnest FROM tests CROSS JOIN LATERAL UNNEST(scores) AS t" ,
36
36
"SELECT student, score, t.unnest FROM tests CROSS JOIN LATERAL UNNEST(scores) AS t(unnest)" ,
37
37
)
38
+ self .validate_identity (
39
+ "SELECT student, score, unnest.unnest FROM tests CROSS JOIN LATERAL UNNEST(scores)" ,
40
+ "SELECT student, score, unnest.unnest FROM tests CROSS JOIN LATERAL UNNEST(scores) AS unnest(unnest)" ,
41
+ )
42
+ self .validate_all (
43
+ r"""SELECT * FROM UNNEST(array['John','Jane','Jim','Jamie'], array[24,25,26,27]) AS t(name, age)""" ,
44
+ write = {
45
+ "postgres" : "SELECT * FROM UNNEST(ARRAY['John', 'Jane', 'Jim', 'Jamie'], ARRAY[24, 25, 26, 27]) AS t(name, age)" ,
46
+ "spark" : "SELECT * FROM EXPLODE(ARRAY('John', 'Jane', 'Jim', 'Jamie'), ARRAY(24, 25, 26, 27)) AS "
47
+ "t(name, age)" ,
48
+ },
49
+ )
50
+ # Use UNNEST to convert into multiple columns
51
+ # see: https://docs.starrocks.io/docs/sql-reference/sql-functions/array-functions/unnest/
52
+ self .validate_all (
53
+ r"""SELECT id, t.type, t.scores FROM example_table, unnest(split(type, ";"), scores) AS t(type,scores)""" ,
54
+ write = {
55
+ "postgres" : "SELECT id, t.type, t.scores FROM example_table, UNNEST(SPLIT(type, ';'), scores) AS "
56
+ "t(type, scores)" ,
57
+ "spark" : "SELECT id, t.type, t.scores FROM example_table LATERAL VIEW EXPLODE(SPLIT(type, CONCAT"
58
+ r"""('\\Q', ';'))) t AS type LATERAL VIEW EXPLODE(scores) t AS scores""" ,
59
+ },
60
+ )
38
61
39
62
lateral_explode_sqls = [
40
63
"SELECT id, t.col FROM tbl, UNNEST(scores) AS t(col)" ,
0 commit comments