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

    https://github.com/apache/spark/pull/15597#discussion_r84655429
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala
 ---
    @@ -293,15 +293,19 @@ abstract class UnaryNode extends LogicalPlan {
        * expressions with the corresponding alias
        */
       protected def getAliasedConstraints(projectList: Seq[NamedExpression]): 
Set[Expression] = {
    -    projectList.flatMap {
    +    var aliasedConstraints = child.constraints.toSet
    +    projectList.foreach {
           case a @ Alias(e, _) =>
    -        child.constraints.map(_ transform {
    +        // For every alias in `projectList`, replace the reference in 
constraints by its attribute.
    +        aliasedConstraints ++= aliasedConstraints.map(_ transform {
               case expr: Expression if expr.semanticEquals(e) =>
                 a.toAttribute
    -        }).union(Set(EqualNullSafe(e, a.toAttribute)))
    -      case _ =>
    -        Set.empty[Expression]
    -    }.toSet
    +        })
    +        aliasedConstraints += EqualNullSafe(e, a.toAttribute)
    +      case _ => // Don't change.
    +    }
    +
    +    aliasedConstraints
    --- End diff --
    
    This should really return `aliasedConstraints -- child.constraints`. 
Perhaps rename `aliasedConstraints` to `allConstraints` and then return 
`allConstraints -- child.constraints`?


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

Reply via email to