|
17 | 17 |
|
18 | 18 | package org.apache.spark.sql.catalyst.optimizer |
19 | 19 |
|
20 | | -import org.apache.spark.sql.catalyst.analysis.{Analyzer, EmptyFunctionRegistry} |
21 | | -import org.apache.spark.sql.catalyst.catalog.{InMemoryCatalog, SessionCatalog} |
22 | 20 | import org.apache.spark.sql.catalyst.dsl.expressions._ |
23 | 21 | import org.apache.spark.sql.catalyst.dsl.plans._ |
24 | 22 | import org.apache.spark.sql.catalyst.expressions._ |
25 | 23 | import org.apache.spark.sql.catalyst.plans._ |
26 | 24 | import org.apache.spark.sql.catalyst.plans.logical._ |
27 | 25 | import org.apache.spark.sql.catalyst.rules._ |
28 | | -import org.apache.spark.sql.internal.SQLConf |
29 | | -import org.apache.spark.sql.internal.SQLConf.{CASE_SENSITIVE, ORDER_BY_ORDINAL} |
30 | 26 |
|
31 | 27 | class RemoveRedundantSortsSuite extends PlanTest { |
32 | 28 |
|
@@ -72,6 +68,14 @@ class RemoveRedundantSortsSuite extends PlanTest { |
72 | 68 | comparePlans(optimized, correctAnswer) |
73 | 69 | } |
74 | 70 |
|
| 71 | + test("different sorts are not simplified if limit is in between") { |
| 72 | + val orderedPlan = testRelation.select('a, 'b).orderBy('b.desc).limit(Literal(10)) |
| 73 | + .orderBy('a.asc) |
| 74 | + val optimized = Optimize.execute(orderedPlan.analyze) |
| 75 | + val correctAnswer = orderedPlan.analyze |
| 76 | + comparePlans(optimized, correctAnswer) |
| 77 | + } |
| 78 | + |
75 | 79 | test("range is already sorted") { |
76 | 80 | val inputPlan = Range(1L, 1000L, 1, 10) |
77 | 81 | val orderedPlan = inputPlan.orderBy('id.asc) |
@@ -124,5 +128,11 @@ class RemoveRedundantSortsSuite extends PlanTest { |
124 | 128 | val correctAnswerWithBoth = |
125 | 129 | testRelation.select('b).where('b > Literal(0)).orderBy('b.desc).analyze |
126 | 130 | comparePlans(optimizedWithBoth, correctAnswerWithBoth) |
| 131 | + |
| 132 | + val orderedThrice = orderedTwiceWithBoth.select(('b + 1).as('c)).orderBy('c.asc) |
| 133 | + val optimizedThrice = Optimize.execute(orderedThrice.analyze) |
| 134 | + val correctAnswerThrice = testRelation.select('b).where('b > Literal(0)) |
| 135 | + .select(('b + 1).as('c)).orderBy('c.asc).analyze |
| 136 | + comparePlans(optimizedThrice, correctAnswerThrice) |
127 | 137 | } |
128 | 138 | } |
0 commit comments