Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19201#discussion_r138401827
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/QueryPlanConstraints.scala
 ---
    @@ -106,91 +106,48 @@ trait QueryPlanConstraints { self: LogicalPlan =>
        * Infers an additional set of constraints from a given set of equality 
constraints.
        * For e.g., if an operator has constraints of the form (`a = 5`, `a = 
b`), this returns an
        * additional constraint of the form `b = 5`.
    -   *
    -   * [SPARK-17733] We explicitly prevent producing recursive constraints 
of the form `a = f(a, b)`
    -   * as they are often useless and can lead to a non-converging set of 
constraints.
        */
       private def inferAdditionalConstraints(constraints: Set[Expression]): 
Set[Expression] = {
    -    val constraintClasses = 
generateEquivalentConstraintClasses(constraints)
    -
    +    val aliasedConstraints = 
eliminateAliasedExpressionInConstraints(constraints)
         var inferredConstraints = Set.empty[Expression]
    -    constraints.foreach {
    +    aliasedConstraints.foreach {
           case eq @ EqualTo(l: Attribute, r: Attribute) =>
    -        val candidateConstraints = constraints - eq
    -        inferredConstraints ++= candidateConstraints.map(_ transform {
    -          case a: Attribute if a.semanticEquals(l) &&
    -            !isRecursiveDeduction(r, constraintClasses) => r
    -        })
    -        inferredConstraints ++= candidateConstraints.map(_ transform {
    -          case a: Attribute if a.semanticEquals(r) &&
    -            !isRecursiveDeduction(l, constraintClasses) => l
    -        })
    +        val candidateConstraints = aliasedConstraints - eq
    +        inferredConstraints ++= replaceConstraints(candidateConstraints, 
l, r)
    +        inferredConstraints ++= replaceConstraints(candidateConstraints, 
r, l)
           case _ => // No inference
         }
         inferredConstraints -- constraints
       }
     
       /**
    -   * Generate a sequence of expression sets from constraints, where each 
set stores an equivalence
    -   * class of expressions. For example, Set(`a = b`, `b = c`, `e = f`) 
will generate the following
    -   * expression sets: (Set(a, b, c), Set(e, f)). This will be used to 
search all expressions equal
    -   * to an selected attribute.
    +   * Replace the aliased expression in [[Alias]] with the alias name if 
both exist in constraints.
    +   * Thus non-converging inference can be prevented.
    +   * E.g. `a = f(a, b)`,  `a = f(b, c) && c = g(a, b)`.
    --- End diff --
    
    This example doesn't even have an alias...


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to