Skip to content

Commit

Permalink
[SPARK-33302][SQL] Failed to push down filters through Expand
Browse files Browse the repository at this point in the history
  • Loading branch information
AngersZhuuuu committed Nov 6, 2020
1 parent 68c032c commit c3ec848
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,7 @@ object PushPredicateThroughNonJoin extends Rule[LogicalPlan] with PredicateHelpe
case _: Sort => true
case _: BatchEvalPython => true
case _: ArrowEvalPython => true
case _: Expand => true
case _ => false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.apache.spark.sql.catalyst.plans._
import org.apache.spark.sql.catalyst.plans.logical._
import org.apache.spark.sql.catalyst.rules._
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types.{BooleanType, IntegerType, TimestampType}
import org.apache.spark.sql.types.{BooleanType, IntegerType, StringType, TimestampType}
import org.apache.spark.unsafe.types.CalendarInterval

class FilterPushdownSuite extends PlanTest {
Expand Down Expand Up @@ -1208,6 +1208,36 @@ class FilterPushdownSuite extends PlanTest {
checkAnalysis = false)
}


test("push down predicate through expand") {
val input = LocalRelation('a.int, 'b.string, 'c.double)
val query =
Aggregate(
Seq('a, 'b),
Seq(sum('c).as("sum")),
Filter('a > 1,
Expand(
Seq(
Seq('a, 'b, 'c, Literal.create(null, StringType), 1),
Seq('a, 'b, 'c, 'a, 2)),
Seq('a, 'b, 'c),
input))).analyze
val optimized = Optimize.execute(query)

val expected =
Aggregate(
Seq('a, 'b),
Seq(sum('c).as("sum")),
Expand(
Seq(
Seq('a, 'b, 'c, Literal.create(null, StringType), 1),
Seq('a, 'b, 'c, 'a, 2)),
Seq('a, 'b, 'c),
Filter('a > 1, input))).analyze

comparePlans(optimized, expected)
}

test("SPARK-28345: PythonUDF predicate should be able to pushdown to join") {
val pythonUDFJoinCond = {
val pythonUDF = PythonUDF("pythonUDF", null,
Expand Down

0 comments on commit c3ec848

Please sign in to comment.