Skip to content
Prev Previous commit
Next Next commit
Address comment
  • Loading branch information
wangyum committed Feb 12, 2020
commit 47eadf4bbd35aa853175d28527278194c4f7225d
Original file line number Diff line number Diff line change
Expand Up @@ -283,17 +283,23 @@ class InferFiltersFromConstraintsSuite extends PlanTest {
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.where('b < 10).subquery('right)
val originalLeft = testRelation1.where('a === 1).subquery('left)
val originalRight = testRelation2.subquery('right)

val left = testRelation1.where(
IsNotNull('a) && 'a > 1 && 'a.cast(LongType) < Literal(10).cast(LongType)).subquery('left)
val right = testRelation2.where(
IsNotNull('b) && 'b < Literal(10).cast(LongType)).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),
Copy link
Contributor

Choose a reason for hiding this comment

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

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 (#27518 will address that) but probably using inequalities ('a < 1) would be easier to follow.

Some("right.b".attr === "left.a".attr.cast(LongType))).foreach { condition =>
testConstraintsAfterJoin(originalLeft, originalRight, left, right, Inner, condition)
}

testConstraintsAfterJoin(
originalLeft,
originalRight,
left,
testRelation2.where(IsNotNull('b) && 'b.attr.cast(IntegerType) === 1).subquery('right),
Inner,
Some("left.a".attr === "right.b".attr.cast(IntegerType)))
}
}