Skip to content

Commit 65244b1

Browse files
heary-caocloud-fan
authored andcommitted
[SPARK-23356][SQL][TEST] add new test cases for a + 1,a + b and Rand in SetOperationSuite
## What changes were proposed in this pull request? The purpose of this PR is supplement new test cases for a + 1,a + b and Rand in SetOperationSuite. It comes from the comment of closed PR:apache#20541, thanks. ## How was this patch tested? add new test cases Closes apache#23138 from heary-cao/UnionPushTestCases. Authored-by: caoxuewen <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
1 parent 6a064ba commit 65244b1

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/SetOperationSuite.scala

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package org.apache.spark.sql.catalyst.optimizer
2020
import org.apache.spark.sql.catalyst.analysis.EliminateSubqueryAliases
2121
import org.apache.spark.sql.catalyst.dsl.expressions._
2222
import org.apache.spark.sql.catalyst.dsl.plans._
23-
import org.apache.spark.sql.catalyst.expressions.{Alias, And, GreaterThan, GreaterThanOrEqual, If, Literal, ReplicateRows}
23+
import org.apache.spark.sql.catalyst.expressions.{And, GreaterThan, GreaterThanOrEqual, If, Literal, Rand, ReplicateRows}
2424
import org.apache.spark.sql.catalyst.plans.PlanTest
2525
import org.apache.spark.sql.catalyst.plans.logical._
2626
import org.apache.spark.sql.catalyst.rules._
@@ -196,4 +196,31 @@ class SetOperationSuite extends PlanTest {
196196
))
197197
comparePlans(expectedPlan, rewrittenPlan)
198198
}
199+
200+
test("SPARK-23356 union: expressions with literal in project list are pushed down") {
201+
val unionQuery = testUnion.select(('a + 1).as("aa"))
202+
val unionOptimized = Optimize.execute(unionQuery.analyze)
203+
val unionCorrectAnswer =
204+
Union(testRelation.select(('a + 1).as("aa")) ::
205+
testRelation2.select(('d + 1).as("aa")) ::
206+
testRelation3.select(('g + 1).as("aa")) :: Nil).analyze
207+
comparePlans(unionOptimized, unionCorrectAnswer)
208+
}
209+
210+
test("SPARK-23356 union: expressions in project list are pushed down") {
211+
val unionQuery = testUnion.select(('a + 'b).as("ab"))
212+
val unionOptimized = Optimize.execute(unionQuery.analyze)
213+
val unionCorrectAnswer =
214+
Union(testRelation.select(('a + 'b).as("ab")) ::
215+
testRelation2.select(('d + 'e).as("ab")) ::
216+
testRelation3.select(('g + 'h).as("ab")) :: Nil).analyze
217+
comparePlans(unionOptimized, unionCorrectAnswer)
218+
}
219+
220+
test("SPARK-23356 union: no pushdown for non-deterministic expression") {
221+
val unionQuery = testUnion.select('a, Rand(10).as("rnd"))
222+
val unionOptimized = Optimize.execute(unionQuery.analyze)
223+
val unionCorrectAnswer = unionQuery.analyze
224+
comparePlans(unionOptimized, unionCorrectAnswer)
225+
}
199226
}

0 commit comments

Comments
 (0)