beliefer commented on a change in pull request #26656: [SPARK-27986][SQL]
Support ANSI SQL filter clause for aggregate expression
URL: https://github.com/apache/spark/pull/26656#discussion_r353525269
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/AggregationIterator.scala
##########
@@ -157,19 +157,52 @@ abstract class AggregationIterator(
inputAttributes: Seq[Attribute]): (InternalRow, InternalRow) => Unit = {
val joinedRow = new JoinedRow
if (expressions.nonEmpty) {
- val mergeExpressions = functions.zip(expressions).flatMap {
- case (ae: DeclarativeAggregate, expression) =>
- expression.mode match {
- case Partial | Complete => ae.updateExpressions
- case PartialMerge | Final => ae.mergeExpressions
+ val mergeExpressions = functions.zip(expressions.map(ae => (ae.mode,
ae.filter))).flatMap {
+ case (ae: DeclarativeAggregate, (mode, filter)) =>
+ mode match {
+ case Partial | Complete =>
+ if (filter.isDefined) {
+ ae.updateExpressions.zip(ae.aggBufferAttributes).map {
+ case (newVal, attr) => If(filter.get, newVal, attr)
+ }
+ } else {
+ ae.updateExpressions
+ }
+ case PartialMerge =>
Review comment:
@cloud-fan `PartialMerge` mode need to evaluate the filter when the
aggregate funciton containing DISTINCT. Yes, the input here is the agg buffers,
so I added the referred attributes on
https://github.com/apache/spark/blob/4d1413f4c8e05e9bf47e60c955a7031b9aac7e83/sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/AggUtils.scala#L154
and
https://github.com/apache/spark/blob/4d1413f4c8e05e9bf47e60c955a7031b9aac7e83/sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/AggUtils.scala#L176
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]