Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove toSet (ExpressionSet should support all these operations)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I transformed child.constraints to Set[Expression] as we need to apply ++= operator on it.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should really return aliasedConstraints -- child.constraints. Perhaps rename aliasedConstraints to allConstraints and then return allConstraints -- child.constraints?

}

override protected def validConstraints: Set[Expression] = child.constraints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,16 @@ class ConstraintPropagationSuite extends SparkFunSuite {
ExpressionSet(Seq(resolveColumn(aliasedRelation.analyze, "x") > 10,
IsNotNull(resolveColumn(aliasedRelation.analyze, "x")),
resolveColumn(aliasedRelation.analyze, "b") <=> resolveColumn(aliasedRelation.analyze, "y"),
resolveColumn(aliasedRelation.analyze, "z") <=> resolveColumn(aliasedRelation.analyze, "x"),
resolveColumn(aliasedRelation.analyze, "z") > 10,
IsNotNull(resolveColumn(aliasedRelation.analyze, "z")))))

val multiAlias = tr.where('a === 'c + 10).select('a.as('x), 'c.as('y))
verifyConstraints(multiAlias.analyze.constraints,
ExpressionSet(Seq(IsNotNull(resolveColumn(multiAlias.analyze, "x")),
IsNotNull(resolveColumn(multiAlias.analyze, "y")),
resolveColumn(multiAlias.analyze, "x") === resolveColumn(multiAlias.analyze, "y") + 10))
)
}

test("propagating constraints in union") {
Expand Down