maropu commented on a change in pull request #28996:
URL: https://github.com/apache/spark/pull/28996#discussion_r449933207
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/DataFrameSetOperationsSuite.scala
##########
@@ -506,4 +506,23 @@ class DataFrameSetOperationsSuite extends QueryTest with
SharedSparkSession {
check(lit(2).cast("int"), $"c" === 2, Seq(Row(1, 1, 2, 0), Row(1, 1, 2,
1)))
check(lit(2).cast("int"), $"c" =!= 2, Seq())
}
+
+ test("SPARK-29358: Make unionByName optionally fill missing columns with
nulls") {
+ withSQLConf(SQLConf.ALLOW_MISSING_COLUMNS_IN_UNION_BY_NAME.key -> "true") {
+ var df1 = Seq(1, 2, 3).toDF("a")
+ var df2 = Seq(3, 1, 2).toDF("b")
+ val df3 = Seq(2, 3, 1).toDF("c")
+ val unionDf = df1.unionByName(df2.unionByName(df3))
+ checkAnswer(unionDf,
+ Row(1, null, null) :: Row(2, null, null) :: Row(3, null, null) :: //
df1
+ Row(null, 3, null) :: Row(null, 1, null) :: Row(null, 2, null) :: //
df2
+ Row(null, null, 2) :: Row(null, null, 3) :: Row(null, null, 1) ::
Nil // df3
+ )
+
+ df1 = Seq((1, 2)).toDF("a", "c")
+ df2 = Seq((3, 4, 5)).toDF("a", "b", "c")
+ checkAnswer(df1.unionByName(df2),
Review comment:
Could you add tests for both cases?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]