Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,9 @@ object LimitPushDown extends Rule[LogicalPlan] {
LocalLimit(exp, project.copy(child = pushLocalLimitThroughJoin(exp, join)))
// Push down limit 1 through Aggregate and turn Aggregate into Project if it is group only.
case Limit(le @ IntegerLiteral(1), a: Aggregate) if a.groupOnly =>
Limit(le, Project(a.output, LocalLimit(le, a.child)))
Limit(le, Project(a.aggregateExpressions, LocalLimit(le, a.child)))
case Limit(le @ IntegerLiteral(1), p @ Project(_, a: Aggregate)) if a.groupOnly =>
Limit(le, p.copy(child = Project(a.output, LocalLimit(le, a.child))))
Limit(le, p.copy(child = Project(a.aggregateExpressions, LocalLimit(le, a.child))))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ class LimitPushdownSuite extends PlanTest {
Optimize.execute(x.union(y).groupBy("x.a".attr)("x.a".attr).limit(1).analyze),
LocalLimit(1, LocalLimit(1, x).union(LocalLimit(1, y))).select("x.a".attr).limit(1).analyze)

comparePlans(
Optimize.execute(
x.groupBy("x.a".attr)("x.a".attr)
.select("x.a".attr.as("a1"), "x.a".attr.as("a2")).limit(1).analyze),
LocalLimit(1, x).select("x.a".attr)
.select("x.a".attr.as("a1"), "x.a".attr.as("a2")).limit(1).analyze)

// No push down
comparePlans(
Optimize.execute(x.groupBy("x.a".attr)("x.a".attr).limit(2).analyze),
Expand Down