Skip to content

Commit c5b3a3d

Browse files
rootroot
authored andcommitted
fix some code style
1 parent 8a6dd8d commit c5b3a3d

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import org.apache.spark.sql.catalyst.plans.logical.{Aggregate, Expand, LogicalPl
2323
import org.apache.spark.sql.catalyst.rules.Rule
2424
import org.apache.spark.sql.types.IntegerType
2525

26-
/*
26+
/**
2727
* This rule rewrites an aggregate query with distinct aggregations into an expanded double
2828
* aggregation in which the regular aggregation expressions and every distinct clause is aggregated
2929
* in a separate group. The results are then combined in a second aggregate.
@@ -125,6 +125,8 @@ object RewriteDistinctAggregates extends Rule[LogicalPlan] {
125125
// we must expand at least one of the children (here we take the first child),
126126
// or If we don't, we will get the wrong result, for example:
127127
// count(distinct 1) will be explained to count(1) after the rewrite function.
128+
// Generally, the distinct aggregateFunction should not run
129+
// foldable TypeCheck for the first child.
128130
e.aggregateFunction.children.take(1).toSet
129131
}
130132
}
@@ -144,8 +146,9 @@ object RewriteDistinctAggregates extends Rule[LogicalPlan] {
144146

145147
// Functions used to modify aggregate functions and their inputs.
146148
def evalWithinGroup(id: Literal, e: Expression) = If(EqualTo(gid, id), e, nullify(e))
147-
def patchAggregateFunctionChildren(af: AggregateFunction)(
148-
attrs: Expression => Option[Expression]): AggregateFunction = {
149+
def patchAggregateFunctionChildren(
150+
af: AggregateFunction)(
151+
attrs: Expression => Option[Expression]): AggregateFunction = {
149152
val newChildren = af.children.map(c => attrs(c).getOrElse(c))
150153
af.withNewChildren(newChildren).asInstanceOf[AggregateFunction]
151154
}
@@ -251,8 +254,8 @@ object RewriteDistinctAggregates extends Rule[LogicalPlan] {
251254

252255
// Construct the second aggregate
253256
val transformations: Map[Expression, Expression] =
254-
(distinctAggOperatorMap.flatMap(_._2) ++
255-
regularAggOperatorMap.map(e => (e._1, e._3))).toMap
257+
(distinctAggOperatorMap.flatMap(_._2) ++
258+
regularAggOperatorMap.map(e => (e._1, e._3))).toMap
256259

257260
val patchedAggExpressions = a.aggregateExpressions.map { e =>
258261
e.transformDown {
@@ -275,9 +278,9 @@ object RewriteDistinctAggregates extends Rule[LogicalPlan] {
275278
private def nullify(e: Expression) = Literal.create(null, e.dataType)
276279

277280
private def expressionAttributePair(e: Expression) =
278-
// We are creating a new reference here instead of reusing the attribute in case of a
279-
// NamedExpression. This is done to prevent collisions between distinct and regular aggregate
280-
// children, in this case attribute reuse causes the input of the regular aggregate to bound to
281-
// the (nulled out) input of the distinct aggregate.
281+
// We are creating a new reference here instead of reusing the attribute in case of a
282+
// NamedExpression. This is done to prevent collisions between distinct and regular aggregate
283+
// children, in this case attribute reuse causes the input of the regular aggregate to bound to
284+
// the (nulled out) input of the distinct aggregate.
282285
e -> AttributeReference(e.sql, e.dataType, nullable = true)()
283286
}

0 commit comments

Comments
 (0)