Skip to content

Commit c630a63

Browse files
committed
fix
1 parent 11c266b commit c630a63

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,9 @@ object LimitPushDown extends Rule[LogicalPlan] {
649649
LocalLimit(exp, project.copy(child = pushLocalLimitThroughJoin(exp, join)))
650650
// Push down limit 1 through Aggregate if it is group only.
651651
case Limit(le @ IntegerLiteral(1), a: Aggregate) if a.groupOnly =>
652-
Limit(le, a.copy(child = LocalLimit(le, a.child)))
652+
Limit(le, Project(a.output, LocalLimit(le, a.child)))
653653
case Limit(le @ IntegerLiteral(1), p @ Project(_, a: Aggregate)) if a.groupOnly =>
654-
Limit(le, p.copy(child = a.copy(child = LocalLimit(le, a.child))))
654+
Limit(le, p.copy(child = Project(a.output, LocalLimit(le, a.child))))
655655
}
656656
}
657657

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,15 @@ class LimitPushdownSuite extends PlanTest {
244244
// Push down when it is group only and limit 1.
245245
comparePlans(
246246
Optimize.execute(x.groupBy("x.a".attr)("x.a".attr).limit(1).analyze),
247-
LocalLimit(1, x).groupBy("x.a".attr)("x.a".attr).limit(1).analyze)
247+
LocalLimit(1, x).select("x.a".attr).limit(1).analyze)
248248

249249
comparePlans(
250250
Optimize.execute(x.groupBy("x.a".attr)("x.a".attr).select("x.a".attr).limit(1).analyze),
251-
LocalLimit(1, x).groupBy("x.a".attr)("x.a".attr).select("x.a".attr).limit(1).analyze)
251+
LocalLimit(1, x).select("x.a".attr).select("x.a".attr).limit(1).analyze)
252252

253253
comparePlans(
254254
Optimize.execute(x.union(y).groupBy("x.a".attr)("x.a".attr).limit(1).analyze),
255-
LocalLimit(1, LocalLimit(1, x).union(LocalLimit(1, y)))
256-
.groupBy("x.a".attr)("x.a".attr).limit(1).analyze)
255+
LocalLimit(1, LocalLimit(1, x).union(LocalLimit(1, y))).select("x.a".attr).limit(1).analyze)
257256

258257
// No push down
259258
comparePlans(

0 commit comments

Comments
 (0)