Github user JoshRosen commented on a diff in the pull request:
https://github.com/apache/spark/pull/15289#discussion_r81040912
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
---
@@ -710,7 +710,7 @@ object PushDownPredicate extends Rule[LogicalPlan] with
PredicateHelper {
val (pushDown, rest) = candidates.partition { cond =>
val replaced = replaceAlias(cond, aliasMap)
- replaced.references.subsetOf(aggregate.child.outputSet)
+ cond.references.nonEmpty &&
replaced.references.subsetOf(aggregate.child.outputSet)
--- End diff --
If you use `replaced.references` here then this will break the "aggregate:
push down filters with literal" test case. Here's that test:
```scala
test("aggregate: push down filters with literal") {
val originalQuery = testRelation
.select('a, 'b)
.groupBy('a)('a, count('b) as 'c, "s" as 'd)
.where('c === 2L && 'd === "s")
val optimized = Optimize.execute(originalQuery.analyze)
val correctAnswer = testRelation
.where("s" === "s")
.select('a, 'b)
.groupBy('a)('a, count('b) as 'c, "s" as 'd)
.where('c === 2L)
.analyze
comparePlans(optimized, correctAnswer)
}
```
If you use `replaced.references` then the `'d` in the filter is replaced
with `"s"` and the resulting expression no longer contains any references and
thus isn't pushed.
---
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]