Github user marmbrus commented on a diff in the pull request:
https://github.com/apache/spark/pull/7191#discussion_r35707207
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
---
@@ -554,27 +554,33 @@ object PushPredicateThroughProject extends
Rule[LogicalPlan] with PredicateHelpe
// Split the condition into small conditions by `And`, so that we
can push down part of this
// condition without nondeterministic expressions.
val andConditions = splitConjunctivePredicates(condition)
-
- val (deterministic, nondeterministic) =
andConditions.partition(_.collect {
- case a: Attribute if aliasMap.contains(a) => aliasMap(a)
- }.forall(_.deterministic))
+ val nondeterministicConditions =
andConditions.filter(hasNondeterministic(_, aliasMap))
// If there is no nondeterministic conditions, push down the whole
condition.
- if (nondeterministic.isEmpty) {
+ if (nondeterministicConditions.isEmpty) {
project.copy(child = Filter(replaceAlias(condition, aliasMap),
grandChild))
} else {
// If they are all nondeterministic conditions, leave it
un-changed.
- if (deterministic.isEmpty) {
+ if (nondeterministicConditions.length == andConditions.length) {
filter
} else {
+ val deterministicConditions =
andConditions.filterNot(hasNondeterministic(_, aliasMap))
// Push down the small conditions without nondeterministic
expressions.
- val pushedCondition = deterministic.map(replaceAlias(_,
aliasMap)).reduce(And)
- Filter(nondeterministic.reduce(And),
+ val pushedCondition =
deterministicConditions.map(replaceAlias(_, aliasMap)).reduce(And)
+ Filter(nondeterministicConditions.reduce(And),
project.copy(child = Filter(pushedCondition, grandChild)))
}
}
}
+ private def hasNondeterministic(
+ condition: Expression,
+ sourceAliases: AttributeMap[Expression]) = {
+ condition.collect {
--- End diff --
I don't think we have to do this anymore. `deterministic` traverses the
whole tree now.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]