forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-44834][PYTHON][SQL][TESTS] Add SQL query tests for Python UDTFs
### What changes were proposed in this pull request? This PR adds a new sql query test suite for running Python UDTFs in SQL. You can trigger the test using ``` SPARK_GENERATE_GOLDEN_FILES=1 build/sbt "sql/testOnly *SQLQueryTestSuite -- -z udtf/udtf.sql" ``` ### Why are the changes needed? To add more test cases for Python UDTFs. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Added new golden file tests. Closes apache#42517 from allisonwang-db/spark-44834-udtf-sql-test. Authored-by: allisonwang-db <allison.wang@databricks.com> Signed-off-by: Takuya UESHIN <ueshin@databricks.com>
- Loading branch information
1 parent
047b224
commit be04ac1
Showing
6 changed files
with
269 additions
and
0 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
sql/core/src/test/resources/sql-tests/analyzer-results/udtf/udtf.sql.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
-- Automatically generated by SQLQueryTestSuite | ||
-- !query | ||
CREATE OR REPLACE TEMPORARY VIEW t1 AS VALUES (0, 1), (1, 2) t(c1, c2) | ||
-- !query analysis | ||
CreateViewCommand `t1`, VALUES (0, 1), (1, 2) t(c1, c2), false, true, LocalTempView, true | ||
+- SubqueryAlias t | ||
+- LocalRelation [c1#x, c2#x] | ||
|
||
|
||
-- !query | ||
SELECT * FROM udtf(1, 2) | ||
-- !query analysis | ||
Project [x#x, y#x] | ||
+- Generate TestUDTF(1, 2)#x, false, [x#x, y#x] | ||
+- OneRowRelation | ||
|
||
|
||
-- !query | ||
SELECT * FROM udtf(-1, 0) | ||
-- !query analysis | ||
Project [x#x, y#x] | ||
+- Generate TestUDTF(-1, 0)#x, false, [x#x, y#x] | ||
+- OneRowRelation | ||
|
||
|
||
-- !query | ||
SELECT * FROM udtf(0, -1) | ||
-- !query analysis | ||
Project [x#x, y#x] | ||
+- Generate TestUDTF(0, -1)#x, false, [x#x, y#x] | ||
+- OneRowRelation | ||
|
||
|
||
-- !query | ||
SELECT * FROM udtf(0, 0) | ||
-- !query analysis | ||
Project [x#x, y#x] | ||
+- Generate TestUDTF(0, 0)#x, false, [x#x, y#x] | ||
+- OneRowRelation | ||
|
||
|
||
-- !query | ||
SELECT a, b FROM udtf(1, 2) t(a, b) | ||
-- !query analysis | ||
Project [a#x, b#x] | ||
+- SubqueryAlias t | ||
+- Project [x#x AS a#x, y#x AS b#x] | ||
+- Generate TestUDTF(1, 2)#x, false, [x#x, y#x] | ||
+- OneRowRelation | ||
|
||
|
||
-- !query | ||
SELECT * FROM t1, LATERAL udtf(c1, c2) | ||
-- !query analysis | ||
Project [c1#x, c2#x, x#x, y#x] | ||
+- LateralJoin lateral-subquery#x [c1#x && c2#x], Inner | ||
: +- Generate TestUDTF(outer(c1#x), outer(c2#x))#x, false, [x#x, y#x] | ||
: +- OneRowRelation | ||
+- SubqueryAlias t1 | ||
+- View (`t1`, [c1#x,c2#x]) | ||
+- Project [cast(c1#x as int) AS c1#x, cast(c2#x as int) AS c2#x] | ||
+- SubqueryAlias t | ||
+- LocalRelation [c1#x, c2#x] | ||
|
||
|
||
-- !query | ||
SELECT * FROM t1 LEFT JOIN LATERAL udtf(c1, c2) | ||
-- !query analysis | ||
Project [c1#x, c2#x, x#x, y#x] | ||
+- LateralJoin lateral-subquery#x [c1#x && c2#x], LeftOuter | ||
: +- Generate TestUDTF(outer(c1#x), outer(c2#x))#x, false, [x#x, y#x] | ||
: +- OneRowRelation | ||
+- SubqueryAlias t1 | ||
+- View (`t1`, [c1#x,c2#x]) | ||
+- Project [cast(c1#x as int) AS c1#x, cast(c2#x as int) AS c2#x] | ||
+- SubqueryAlias t | ||
+- LocalRelation [c1#x, c2#x] | ||
|
||
|
||
-- !query | ||
SELECT * FROM udtf(1, 2) t(c1, c2), LATERAL udtf(c1, c2) | ||
-- !query analysis | ||
Project [c1#x, c2#x, x#x, y#x] | ||
+- LateralJoin lateral-subquery#x [c1#x && c2#x], Inner | ||
: +- Generate TestUDTF(outer(c1#x), outer(c2#x))#x, false, [x#x, y#x] | ||
: +- OneRowRelation | ||
+- SubqueryAlias t | ||
+- Project [x#x AS c1#x, y#x AS c2#x] | ||
+- Generate TestUDTF(1, 2)#x, false, [x#x, y#x] | ||
+- OneRowRelation | ||
|
||
|
||
-- !query | ||
SELECT * FROM udtf(cast(rand(0) AS int) + 1, 1) | ||
-- !query analysis | ||
[Analyzer test output redacted due to nondeterminism] |
18 changes: 18 additions & 0 deletions
18
sql/core/src/test/resources/sql-tests/inputs/udtf/udtf.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
CREATE OR REPLACE TEMPORARY VIEW t1 AS VALUES (0, 1), (1, 2) t(c1, c2); | ||
|
||
-- test basic udtf | ||
SELECT * FROM udtf(1, 2); | ||
SELECT * FROM udtf(-1, 0); | ||
SELECT * FROM udtf(0, -1); | ||
SELECT * FROM udtf(0, 0); | ||
|
||
-- test column alias | ||
SELECT a, b FROM udtf(1, 2) t(a, b); | ||
|
||
-- test lateral join | ||
SELECT * FROM t1, LATERAL udtf(c1, c2); | ||
SELECT * FROM t1 LEFT JOIN LATERAL udtf(c1, c2); | ||
SELECT * FROM udtf(1, 2) t(c1, c2), LATERAL udtf(c1, c2); | ||
|
||
-- test non-deterministic input | ||
SELECT * FROM udtf(cast(rand(0) AS int) + 1, 1); |
85 changes: 85 additions & 0 deletions
85
sql/core/src/test/resources/sql-tests/results/udtf/udtf.sql.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
-- Automatically generated by SQLQueryTestSuite | ||
-- !query | ||
CREATE OR REPLACE TEMPORARY VIEW t1 AS VALUES (0, 1), (1, 2) t(c1, c2) | ||
-- !query schema | ||
struct<> | ||
-- !query output | ||
|
||
|
||
|
||
-- !query | ||
SELECT * FROM udtf(1, 2) | ||
-- !query schema | ||
struct<x:int,y:int> | ||
-- !query output | ||
1 -1 | ||
2 1 | ||
|
||
|
||
-- !query | ||
SELECT * FROM udtf(-1, 0) | ||
-- !query schema | ||
struct<x:int,y:int> | ||
-- !query output | ||
|
||
|
||
|
||
-- !query | ||
SELECT * FROM udtf(0, -1) | ||
-- !query schema | ||
struct<x:int,y:int> | ||
-- !query output | ||
|
||
|
||
|
||
-- !query | ||
SELECT * FROM udtf(0, 0) | ||
-- !query schema | ||
struct<x:int,y:int> | ||
-- !query output | ||
0 0 | ||
|
||
|
||
-- !query | ||
SELECT a, b FROM udtf(1, 2) t(a, b) | ||
-- !query schema | ||
struct<a:int,b:int> | ||
-- !query output | ||
1 -1 | ||
2 1 | ||
|
||
|
||
-- !query | ||
SELECT * FROM t1, LATERAL udtf(c1, c2) | ||
-- !query schema | ||
struct<c1:int,c2:int,x:int,y:int> | ||
-- !query output | ||
1 2 1 -1 | ||
1 2 2 1 | ||
|
||
|
||
-- !query | ||
SELECT * FROM t1 LEFT JOIN LATERAL udtf(c1, c2) | ||
-- !query schema | ||
struct<c1:int,c2:int,x:int,y:int> | ||
-- !query output | ||
1 2 1 -1 | ||
1 2 2 1 | ||
|
||
|
||
-- !query | ||
SELECT * FROM udtf(1, 2) t(c1, c2), LATERAL udtf(c1, c2) | ||
-- !query schema | ||
struct<c1:int,c2:int,x:int,y:int> | ||
-- !query output | ||
2 1 1 -1 | ||
2 1 2 1 | ||
|
||
|
||
-- !query | ||
SELECT * FROM udtf(cast(rand(0) AS int) + 1, 1) | ||
-- !query schema | ||
struct<x:int,y:int> | ||
-- !query output | ||
1 0 | ||
1 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters