peter-toth commented on a change in pull request #27252: [SPARK-29231][SQL]
Constraints should be inferred from cast equality constraint
URL: https://github.com/apache/spark/pull/27252#discussion_r378111623
##########
File path:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/InferFiltersFromConstraintsSuite.scala
##########
@@ -263,4 +264,45 @@ class InferFiltersFromConstraintsSuite extends PlanTest {
val y = testRelation.subquery('y)
testConstraintsAfterJoin(x, y, x.where(IsNotNull('a)), y, RightOuter)
}
+
+ test("Constraints should be inferred from cast equality constraint(filter
higher data type)") {
+ val testRelation1 = LocalRelation('a.int)
+ val testRelation2 = LocalRelation('b.long)
+ val originalLeft = testRelation1.subquery('left)
+ val originalRight = testRelation2.where('b === 1L).subquery('right)
+
+ val left = testRelation1.where(IsNotNull('a) && 'a.cast(LongType) ===
1L).subquery('left)
+ val right = testRelation2.where(IsNotNull('b) && 'b ===
1L).subquery('right)
+
+ Seq(Some("left.a".attr.cast(LongType) === "right.b".attr),
+ Some("right.b".attr === "left.a".attr.cast(LongType))).foreach {
condition =>
+ testConstraintsAfterJoin(originalLeft, originalRight, left, right,
Inner, condition)
+ }
+ }
+
+ test("Constraints shouldn't be inferred from cast equality constraint(filter
lower data type)") {
+ val testRelation1 = LocalRelation('a.int)
+ val testRelation2 = LocalRelation('b.long)
+ val originalLeft = testRelation1.where('a === 1).subquery('left)
+ val originalRight = testRelation2.subquery('right)
+
+ val left = testRelation1.where(IsNotNull('a) && 'a === 1).subquery('left)
+ val right = testRelation2.where(IsNotNull('b)).subquery('right)
+
+ Seq(Some("left.a".attr.cast(LongType) === "right.b".attr),
Review comment:
I might be wrong, but I find these test cases a bit confusing because `left`
and `right` have equality filters. Eg. here `'a === 1` in `left` so actually it
would be correct to infer `1.cast(LongType) === 'b` for `right`. This PR
doesn't do that obviously (https://github.com/apache/spark/pull/27518 will
address that) but probably using inequalities (`'a < 1`) would be easier to
follow.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]