Github user jiangxb1987 commented on a diff in the pull request:
    --- Diff: 
    @@ -74,14 +74,26 @@ abstract class QueryPlan[PlanType <: 
QueryPlan[PlanType]] extends TreeNode[PlanT
        * additional constraint of the form `b = 5`
       private def inferAdditionalConstraints(constraints: Set[Expression]): 
Set[Expression] = {
    +    // Collect alias from expressions to avoid producing non-converging 
set of constraints
    +    // for recursive functions.
    +    //
    +    // Don't apply transform on constraints if the attribute used to 
replace is an alias,
    +    // because then both `QueryPlan.inferAdditionalConstraints` and
    +    // `UnaryNode.getAliasedConstraints` applies and may produce a 
non-converging set of
    +    // constraints.
    +    // For more details, refer to
    +    val aliasSet = AttributeSet((expressions ++ 
children.flatMap(_.expressions)).collect {
    +      case a: Alias => a.toAttribute
    +    })
         var inferredConstraints = Set.empty[Expression]
         constraints.foreach {
           case eq @ EqualTo(l: Attribute, r: Attribute) =>
             inferredConstraints ++= (constraints - eq).map(_ transform {
    -          case a: Attribute if a.semanticEquals(l) => r
    +          case a: Attribute if a.semanticEquals(l) && 
!aliasSet.contains(r) => r
    --- End diff --
    Thank you a lot for your advice! Perhaps We should generate the following 
two sets:
    1. Set of `Alias` which have references to other expressions, for instance, 
`Alias(f(b, c), "a")`, or `Alias(a, "a1")`;
    2. Generate sets of equivalence classes out of `EqualTo` operators in 
constraints, e.g., when we have `a = b` and `c = b`, then the sets would be 
((a, b, c)).
    Here, for any expressions to be used to infer new constraints, we should 
check that either it's not in our `AliasSet`, or its reference doesn't contain 
any expressions in the corresponding equivalence classes set.
    I'll update this check rule ASAP. Thank you for helping!

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 or file a JIRA ticket
with INFRA.

To unsubscribe, e-mail:
For additional commands, e-mail:

Reply via email to