cloud-fan commented on a change in pull request #35130:
URL: https://github.com/apache/spark/pull/35130#discussion_r785764681
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2ScanRelationPushDown.scala
##########
@@ -210,16 +250,33 @@ object V2ScanRelationPushDown extends Rule[LogicalPlan]
with PredicateHelper {
}
}
+ private def collectAggregates(resultExpressions: Seq[NamedExpression],
+ aggExprToOutputOrdinal: mutable.HashMap[Expression, Int]):
Seq[AggregateExpression] = {
+ var ordinal = 0
+ resultExpressions.flatMap { expr =>
+ expr.collect {
+ // Do not push down duplicated aggregate expressions. For example,
+ // `SELECT max(a) + 1, max(a) + 2 FROM ...`, we should only push down
one
+ // `max(a)` to the data source.
+ case agg: AggregateExpression
+ if !aggExprToOutputOrdinal.contains(agg.canonicalized) =>
+ aggExprToOutputOrdinal(agg.canonicalized) = ordinal
+ ordinal += 1
+ agg
+ }
+ }
+ }
+
private def supportPartialAggPushDown(agg: Aggregation): Boolean = {
// We don't know the agg buffer of `GeneralAggregateFunc`, so can't do
partial agg push down.
agg.aggregateExpressions().forall(!_.isInstanceOf[GeneralAggregateFunc])
}
- private def addCastIfNeeded(aggAttribute: AttributeReference, aggDataType:
DataType) =
- if (aggAttribute.dataType == aggDataType) {
- aggAttribute
+ private def addCastIfNeeded(expression: Expression, aggDataType: DataType) =
Review comment:
```suggestion
private def addCastIfNeeded(expression: Expression, expectedDataType:
DataType) =
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]