Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/12822#discussion_r61713337
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
 ---
    @@ -1533,3 +1535,74 @@ object RewritePredicateSubquery extends 
Rule[LogicalPlan] with PredicateHelper {
           }
       }
     }
    +
    +/**
    + * This rule rewrites correlated [[ScalarSubquery]] expressions into LEFT 
OUTER joins.
    + */
    +object RewriteCorrelatedScalarSubquery extends Rule[LogicalPlan] {
    +  /**
    +   * Extract all correlated scalar subqueries from an expression. The 
subqueries are collected using
    +   * the given collector. The expression is rewritten and returned.
    +   */
    +  private def extractCorrelatedScalarSubqueries[E <: Expression](
    +      expression: E,
    +      subqueries: ArrayBuffer[ScalarSubquery]): E = {
    +    val newExpression = expression transform {
    +      case s: ScalarSubquery if s.children.nonEmpty =>
    +        subqueries += s
    +        s.query.output.head
    +    }
    +    newExpression.asInstanceOf[E]
    +  }
    +
    +  /**
    +   * Construct a new child plan by left joining the given subqueries to a 
base plan.
    +   */
    +  private def constructLeftJoins(
    +      child: LogicalPlan,
    +      subqueries: ArrayBuffer[ScalarSubquery]): LogicalPlan = {
    +    subqueries.foldLeft(child) {
    +      case (currentChild, ScalarSubquery(query, conditions, _)) =>
    +        Project(
    +          currentChild.output :+ query.output.head,
    --- End diff --
    
    I see, thanks


---
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]

Reply via email to