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

    https://github.com/apache/spark/pull/12539#discussion_r60765014
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
 ---
    @@ -1517,10 +1517,34 @@ object RewritePredicateSubquery extends 
Rule[LogicalPlan] with PredicateHelper {
        */
       private def pullOutCorrelatedPredicates(
           in: InSubQuery,
    -      query: LogicalPlan): (LogicalPlan, Seq[Expression]) = {
    +      query: LogicalPlan): (LogicalPlan, LogicalPlan, Seq[Expression]) = {
         val (resolved, joinCondition) = pullOutCorrelatedPredicates(in.query, 
query)
    -    val conditions = joinCondition ++ 
in.expressions.zip(resolved.output).map(EqualTo.tupled)
    -    (resolved, conditions)
    +    // Check whether there is some attributes have same exprId but come 
from different side
    +    val outerAttributes = 
AttributeSet(in.expressions.flatMap(_.references))
    +    if (outerAttributes.intersect(resolved.outputSet).nonEmpty) {
    +      val aliases = mutable.Map[Attribute, Alias]()
    +      val exprs = in.expressions.map { expr =>
    +        expr transformUp {
    +          case a: AttributeReference if resolved.outputSet.contains(a) =>
    +            val alias = Alias(a, a.toString)()
    +            val attr = alias.toAttribute
    +            aliases += attr -> alias
    +            attr
    +        }
    +      }
    +      val newP = Project(query.output ++ aliases.values, query)
    +      val projection = resolved.output.map {
    +        case a if outerAttributes.contains(a) => Alias(a, a.toString)()
    +        case a => a
    +      }
    +      val subquery = Project(projection, resolved)
    --- End diff --
    
    We added a new column here, that will change the result, we have to remove 
it after the join.


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