Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mgaido91 committed Apr 23, 2018
1 parent 1d6ca1e commit e7391f3
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -748,11 +748,18 @@ object RemoveRedundantSorts extends Rule[LogicalPlan] {
}

def recursiveRemoveSort(plan: LogicalPlan): LogicalPlan = plan match {
case Project(fields, child) => Project(fields, recursiveRemoveSort(child))
case Filter(condition, child) => Filter(condition, recursiveRemoveSort(child))
case Sort(_, _, child) => recursiveRemoveSort(child)
case other if canEliminateSort(other) =>
other.withNewChildren(other.children.map(recursiveRemoveSort))
case _ => plan
}

def canEliminateSort(plan: LogicalPlan): Boolean = plan match {
case p: Project => p.projectList.forall(_.deterministic)
case f: Filter => f.condition.deterministic
case _: ResolvedHint => true
case _ => false
}
}

/**
Expand Down

0 comments on commit e7391f3

Please sign in to comment.