Skip to content

Commit

Permalink
Don't push predicate through project with nondeterministic field(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
liancheng committed Feb 24, 2016
1 parent 5d80fac commit 863c5ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,9 @@ object SimplifyFilters extends Rule[LogicalPlan] {
*/
object PushPredicateThroughProject extends Rule[LogicalPlan] with PredicateHelper {
def apply(plan: LogicalPlan): LogicalPlan = plan transform {
case filter @ Filter(condition, project @ Project(fields, grandChild)) =>
case filter @ Filter(condition, project @ Project(fields, grandChild))
if fields.forall(_.deterministic) =>

// Create a map of Aliases to their values from the child projection.
// e.g., 'SELECT a + b AS c, d ...' produces Map(c -> a + b).
val aliasMap = AttributeMap(fields.collect {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class FilterPushdownSuite extends PlanTest {
comparePlans(optimized, correctAnswer)
}

test("nondeterministic: can't push down filter through project") {
test("nondeterministic: can't push down filter with nondeterministic condition through project") {
val originalQuery = testRelation
.select(Rand(10).as('rand), 'a)
.where('rand > 5 || 'a > 5)
Expand All @@ -156,6 +156,17 @@ class FilterPushdownSuite extends PlanTest {
comparePlans(optimized, originalQuery)
}

test("nondeterministic: can't push down filter through project with nondeterministic field") {
val originalQuery = testRelation
.select(Rand(10).as('rand), 'a)
.where('a > 5)
.analyze

val optimized = Optimize.execute(originalQuery)

comparePlans(optimized, originalQuery)
}

test("nondeterministic: push down part of filter through project") {
val originalQuery = testRelation
.select(Rand(10).as('rand), 'a)
Expand Down

0 comments on commit 863c5ec

Please sign in to comment.