Skip to content

Commit 65e7406

Browse files
committed
remove limit
1 parent 7b4e4d6 commit 65e7406

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,15 +1458,7 @@ object PushPredicateThroughJoin extends Rule[LogicalPlan] with PredicateHelper {
14581458
*/
14591459
object EliminateLimits extends Rule[LogicalPlan] {
14601460
private def canEliminate(limitExpr: Expression, child: LogicalPlan): Boolean = {
1461-
// We skip such case that Sort is after Limit since
1462-
// SparkStrategies will convert them to TakeOrderedAndProjectExec
1463-
val skipEliminate = child match {
1464-
case Sort(_, true, _) => true
1465-
case Project(_, Sort(_, true, _)) => true
1466-
case _ => false
1467-
}
1468-
!skipEliminate && limitExpr.foldable &&
1469-
child.maxRows.exists { _ <= limitExpr.eval().toString.toLong }
1461+
limitExpr.foldable && child.maxRows.exists { _ <= limitExpr.eval().toString.toLong }
14701462
}
14711463

14721464
def apply(plan: LogicalPlan): LogicalPlan = plan transformDown {

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/CombiningLimitsSuite.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ class CombiningLimitsSuite extends PlanTest {
109109
comparePlans(optimized3, query3)
110110

111111
// test sort after limit
112-
val query4 = testRelation.select(Symbol("a")).orderBy(Symbol("a").asc).limit(1).analyze
112+
val query4 = testRelation.select().groupBy()(count(1))
113+
.orderBy(Symbol("a").asc).limit(1).analyze
113114
val optimized4 = Optimize.execute(query4)
114-
comparePlans(optimized4, optimized4)
115+
val expected4 = testRelation.select().groupBy()(count(1))
116+
.orderBy(Symbol("a").asc).analyze
117+
comparePlans(optimized4, expected4)
115118
}
116119
}

0 commit comments

Comments
 (0)