Github user nsyca commented on a diff in the pull request: https://github.com/apache/spark/pull/17520#discussion_r109519728 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala --- @@ -766,6 +771,31 @@ object PushDownPredicate extends Rule[LogicalPlan] with PredicateHelper { project.copy(child = Filter(replaceAlias(condition, aliasMap), grandChild)) + // Similar to the above Filter over Project + // LeftSemi/LeftAnti over Project + case join @ Join(project @ Project(projectList, grandChild), rightOp, + LeftSemiOrAnti(joinType), joinCond) + if !tooSimplePlan(grandChild) && + projectList.forall(_.deterministic) && + !ScalarSubquery.hasScalarSubquery(projectList) && + canPushThroughCondition(grandChild, joinCond, rightOp) => + if (joinCond.isEmpty) { + // No join condition, just push down the Join below Project + Project(projectList, Join(grandChild, rightOp, joinType, joinCond)) + } else { + // 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(projectList.collect { + case a: Alias => (a.toAttribute, a.child) + }) + val newJoinCond = if (aliasMap.nonEmpty) { + Option(replaceAlias(joinCond.get, aliasMap)) + } else { + joinCond + } + Project(projectList, Join(grandChild, rightOp, joinType, newJoinCond)) + } + --- End diff -- [To reviewers] Should we separate this into a new rule?
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org