huaxingao commented on a change in pull request #32049:
URL: https://github.com/apache/spark/pull/32049#discussion_r648603609
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/PushDownUtils.scala
##########
@@ -70,6 +72,37 @@ object PushDownUtils extends PredicateHelper {
}
}
+ /**
+ * Pushes down aggregates to the data source reader
+ *
+ * @return pushed aggregation.
+ */
+ def pushAggregates(
+ scanBuilder: ScanBuilder,
+ aggregates: Seq[AggregateExpression],
+ groupBy: Seq[Expression]): Aggregation = {
+
+ def columnAsString(e: Expression): Option[FieldReference] = e match {
+ case AttributeReference(name, _, _, _) => Some(FieldReference(Seq(name)))
+ case _ => None
+ }
+
+ scanBuilder match {
+ case r: SupportsPushDownAggregates =>
+ val translatedAggregates = aggregates.map(DataSourceStrategy
+ .translateAggregate(_, PushableColumn(false)))
+ val translatedGroupBys = groupBy.map(columnAsString)
+
+ if (translatedAggregates.exists(_.isEmpty) ||
translatedGroupBys.exists(_.isEmpty)) {
+ Aggregation.empty
+ } else {
+ r.pushAggregation(Aggregation(translatedAggregates.flatten,
translatedGroupBys.flatten))
+ r.pushedAggregation
Review comment:
Yes, changed.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]