Skip to content

Commit

Permalink
SPARK-24012 add UT for array
Browse files Browse the repository at this point in the history
  • Loading branch information
liutang123 committed Apr 24, 2018
1 parent 670824f commit 8cb240f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
6 changes: 6 additions & 0 deletions sql/core/src/test/resources/sql-tests/inputs/union.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ SELECT map(1, 2), 'str'
UNION ALL
SELECT map(1, 2, 3, NULL), 1;

-- SPARK-24012 Union of array and other compatible columns.
SELECT array(1, 2), 'str'
UNION ALL
SELECT array(1, 2, 3, NULL), 1;


-- Clean-up
DROP VIEW IF EXISTS t1;
DROP VIEW IF EXISTS t2;
Expand Down
27 changes: 19 additions & 8 deletions sql/core/src/test/resources/sql-tests/results/union.sql.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Automatically generated by SQLQueryTestSuite
-- Number of queries: 15
-- Number of queries: 16


-- !query 0
Expand Down Expand Up @@ -116,40 +116,51 @@ struct<map(1, 2):map<int,int>,str:string>


-- !query 10
DROP VIEW IF EXISTS t1
SELECT array(1, 2), 'str'
UNION ALL
SELECT array(1, 2, 3, NULL), 1
-- !query 10 schema
struct<>
struct<array(1, 2):array<int>,str:string>
-- !query 10 output

[1,2,3,null] 1
[1,2] str


-- !query 11
DROP VIEW IF EXISTS t2
DROP VIEW IF EXISTS t1
-- !query 11 schema
struct<>
-- !query 11 output



-- !query 12
DROP VIEW IF EXISTS p1
DROP VIEW IF EXISTS t2
-- !query 12 schema
struct<>
-- !query 12 output



-- !query 13
DROP VIEW IF EXISTS p2
DROP VIEW IF EXISTS p1
-- !query 13 schema
struct<>
-- !query 13 output



-- !query 14
DROP VIEW IF EXISTS p3
DROP VIEW IF EXISTS p2
-- !query 14 schema
struct<>
-- !query 14 output



-- !query 15
DROP VIEW IF EXISTS p3
-- !query 15 schema
struct<>
-- !query 15 output

12 changes: 9 additions & 3 deletions sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -903,9 +903,15 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext {
|SELECT map(1, 2), 'str'
|UNION ALL
|SELECT map(1, 2, 3, NULL), 1""".stripMargin),
Row.fromSeq(Seq(Map(1 -> 2), "str"))::
Row.fromSeq(Seq(Map(1 -> 2, 3 -> null), "1"))::
Nil
Row(Map(1 -> 2), "str") :: Row(Map(1 -> 2, 3 -> null), "1") :: Nil
)
checkAnswer(
sql(
"""
|SELECT array(1), 'str'
|UNION ALL
|SELECT array(1, 2, 3, NULL), 1""".stripMargin),
Row(Array(1), "str") :: Row(Array(1, 2, 3, null), "1") :: Nil
)
}

Expand Down

0 comments on commit 8cb240f

Please sign in to comment.