Skip to content
Permalink
Browse files

[MINOR][SQL] add new unit test to LimitPushdown

## What changes were proposed in this pull request?

This PR is repaired as follows
1、update y -> x in "left outer join" test case ,maybe is mistake.
2、add a new test case:"left outer join and left sides are limited"
3、add a new test case:"left outer join and right sides are limited"
4、add a new test case: "right outer join and right sides are limited"
5、add a new test case: "right outer join and left sides are limited"
6、Remove annotations without code implementation

## How was this patch tested?

add new unit test case.

Author: caoxuewen <cao.xuewen@zte.com.cn>

Closes #20381 from heary-cao/LimitPushdownSuite.

(cherry picked from commit 6f0ba84)
Signed-off-by: gatorsmile <gatorsmile@gmail.com>
  • Loading branch information...
heary-cao authored and gatorsmile committed Jan 24, 2018
1 parent 500c944 commit a857ad56621f644a26b9d27079b76ab21f3726ae
@@ -352,7 +352,6 @@ object LimitPushDown extends Rule[LogicalPlan] {
// on both sides if it is applied multiple times. Therefore:
// - If one side is already limited, stack another limit on top if the new limit is smaller.
// The redundant limit will be collapsed by the CombineLimits rule.
// - If neither side is limited, limit the side that is estimated to be bigger.
case LocalLimit(exp, join @ Join(left, right, joinType, _)) =>
val newJoin = joinType match {
case RightOuter => join.copy(right = maybePushLocalLimit(exp, right))
@@ -93,7 +93,21 @@ class LimitPushdownSuite extends PlanTest {
test("left outer join") {
val originalQuery = x.join(y, LeftOuter).limit(1)
val optimized = Optimize.execute(originalQuery.analyze)
val correctAnswer = Limit(1, LocalLimit(1, y).join(y, LeftOuter)).analyze
val correctAnswer = Limit(1, LocalLimit(1, x).join(y, LeftOuter)).analyze
comparePlans(optimized, correctAnswer)
}

test("left outer join and left sides are limited") {
val originalQuery = x.limit(2).join(y, LeftOuter).limit(1)
val optimized = Optimize.execute(originalQuery.analyze)
val correctAnswer = Limit(1, LocalLimit(1, x).join(y, LeftOuter)).analyze
comparePlans(optimized, correctAnswer)
}

test("left outer join and right sides are limited") {
val originalQuery = x.join(y.limit(2), LeftOuter).limit(1)
val optimized = Optimize.execute(originalQuery.analyze)
val correctAnswer = Limit(1, LocalLimit(1, x).join(Limit(2, y), LeftOuter)).analyze
comparePlans(optimized, correctAnswer)
}

@@ -104,6 +118,20 @@ class LimitPushdownSuite extends PlanTest {
comparePlans(optimized, correctAnswer)
}

test("right outer join and right sides are limited") {
val originalQuery = x.join(y.limit(2), RightOuter).limit(1)
val optimized = Optimize.execute(originalQuery.analyze)
val correctAnswer = Limit(1, x.join(LocalLimit(1, y), RightOuter)).analyze
comparePlans(optimized, correctAnswer)
}

test("right outer join and left sides are limited") {
val originalQuery = x.limit(2).join(y, RightOuter).limit(1)
val optimized = Optimize.execute(originalQuery.analyze)
val correctAnswer = Limit(1, Limit(2, x).join(LocalLimit(1, y), RightOuter)).analyze
comparePlans(optimized, correctAnswer)
}

test("larger limits are not pushed on top of smaller ones in right outer join") {
val originalQuery = x.join(y.limit(5), RightOuter).limit(10)
val optimized = Optimize.execute(originalQuery.analyze)

0 comments on commit a857ad5

Please sign in to comment.
You can’t perform that action at this time.