Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/20345#discussion_r180327289
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/planning/patterns.scala
---
@@ -172,17 +174,20 @@ object ExtractFiltersAndInnerJoins extends
PredicateHelper {
case Filter(filterCondition, j @ Join(left, right, _: InnerLike,
joinCondition)) =>
val (plans, conditions) = flattenJoin(j)
(plans, conditions ++ splitConjunctivePredicates(filterCondition))
-
+ case p @ Project(_, j @ Join(_, _, _: InnerLike, _))
+ // Keep flattening joins when the project has attributes only
+ if p.projectList.forall(_.isInstanceOf[Attribute]) =>
+ flattenJoin(j)
case _ => (Seq((plan, parentJoinType)), Seq.empty)
}
- def unapply(plan: LogicalPlan): Option[(Seq[(LogicalPlan, InnerLike)],
Seq[Expression])]
- = plan match {
- case f @ Filter(filterCondition, j @ Join(_, _, joinType: InnerLike,
_)) =>
- Some(flattenJoin(f))
- case j @ Join(_, _, joinType, _) =>
- Some(flattenJoin(j))
- case _ => None
+ def unapply(plan: LogicalPlan): Option[(Seq[(LogicalPlan, InnerLike)],
Seq[Expression])] = {
+ val (plans, conditions) = flattenJoin(plan)
+ if (plans.size > 1) {
--- End diff --
how about `plans.size > 2 && conditions.nonEmpty`? then we can remove the
`if` condition
[here](https://github.com/apache/spark/pull/20345/files#diff-17d31b198ff391188311550fcabd1198R120)
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]