Skip to content

Commit b4adef7

Browse files
committed
Update comments
1 parent 4526135 commit b4adef7

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,14 @@ object RewriteDistinctAggregates extends Rule[LogicalPlan] {
214214
}
215215

216216
def rewrite(aOrig: Aggregate): Aggregate = {
217-
// make children of distinct aggregations the same if they are different
218-
// only because of superficial reasons, e.g.:
219-
// "1 + col1" vs "col1 + 1", both become "1 + col1"
217+
// Make children of distinct aggregations the same if they are only
218+
// different due to superficial reasons, e.g.:
219+
// "1 + col1" vs "col1 + 1", both should become "1 + col1"
220220
// or
221-
// "col1" vs "Col1", both become "col1"
221+
// "col1" vs "Col1", both should become "col1"
222+
// This could potentially reduce the number of distinct
223+
// aggregate groups, and therefore reduce the number of
224+
// projections in Expand (or eliminate the need for Expand)
222225
val a = reduceDistinctAggregateGroups(aOrig)
223226

224227
val aggExpressions = collectAggregateExprs(a)
@@ -408,6 +411,10 @@ object RewriteDistinctAggregates extends Rule[LogicalPlan] {
408411
}
409412
Aggregate(groupByAttrs, patchedAggExpressions, firstAggregate)
410413
} else {
414+
// It's possible we avoided rewriting the plan to use Expand only because
415+
// reduceDistinctAggregateGroups reduced the number of distinct aggregate groups
416+
// from > 1 to 1. To prevent SparkStrategies from complaining during sanity check,
417+
// we use the potentially patched Aggregate returned by reduceDistinctAggregateGroups.
411418
a
412419
}
413420
}

0 commit comments

Comments
 (0)