Skip to content

Commit ca4480e

Browse files
committed
Avoid generating too many constraints
1 parent 719d812 commit ca4480e

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,13 @@ abstract class UnaryNode extends LogicalPlan {
177177
case a @ Alias(e, _) =>
178178
// For every alias in `projectList`, replace the reference in constraints by its attribute.
179179
allConstraints ++= allConstraints.map {
180-
case binaryExpression @ EqualNullSafe(_: BinaryExpression, _) =>
181-
binaryExpression
182-
case ternaryExpression @ EqualNullSafe(_: TernaryExpression, _) =>
183-
ternaryExpression
184-
case quaternaryExpression @ EqualNullSafe(_: QuaternaryExpression, _) =>
185-
quaternaryExpression
186-
case septenaryExpression @ EqualNullSafe(_: SeptenaryExpression, _) =>
187-
septenaryExpression
188-
case userDefinedExpression @ EqualNullSafe(_: UserDefinedExpression, _) =>
189-
userDefinedExpression
190-
case other =>
191-
other transform {
192-
case expr: Expression if expr.semanticEquals(e) =>
193-
a.toAttribute
180+
case e @ EqualNullSafe(l, _: AttributeReference)
181+
if !l.isInstanceOf[AttributeReference] => e
182+
case e @ EqualNullSafe(_: AttributeReference, r)
183+
if !r.isInstanceOf[AttributeReference] => e
184+
case other => other transform {
185+
case expr: Expression if expr.semanticEquals(e) =>
186+
a.toAttribute
194187
}
195188
}
196189
allConstraints += EqualNullSafe(e, a.toAttribute)

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/plans/ConstraintPropagationSuite.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,4 +422,12 @@ class ConstraintPropagationSuite extends SparkFunSuite with PlanTest {
422422
assert(aliasedRelation.analyze.constraints.isEmpty)
423423
}
424424
}
425+
426+
test("SPARK-29606 Avoid generating too many constraints") {
427+
val aliasedRelation = LocalRelation('a.int, 'b.int, 'c.int)
428+
.select('a, 'b, 'c, ('a + 'b + 'c).as("abc"))
429+
.select('a.as("a1"), 'b.as("b1"), 'c.as("c1"), 'abc.as("abc1"))
430+
assert(aliasedRelation.analyze.isInstanceOf[Project])
431+
assert(aliasedRelation.analyze.asInstanceOf[Project].validConstraints.size === 5)
432+
}
425433
}

0 commit comments

Comments
 (0)