cloud-fan commented on a change in pull request #35130:
URL: https://github.com/apache/spark/pull/35130#discussion_r780294560



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2ScanRelationPushDown.scala
##########
@@ -212,7 +224,10 @@ object V2ScanRelationPushDown extends Rule[LogicalPlan] 
with PredicateHelper {
 
   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])
+    agg.aggregateExpressions().forall { aggregateFunc =>
+      !aggregateFunc.isInstanceOf[GeneralAggregateFunc] ||
+        aggregateFunc.asInstanceOf[GeneralAggregateFunc].name() == "AVG"

Review comment:
       If `AVG` can be partially pushed, I'd like to create a dedicated class 
for it, instead of using `GeneralAggregateFunc`.

##########
File path: sql/core/src/main/scala/org/apache/spark/sql/jdbc/JdbcDialects.scala
##########
@@ -223,7 +225,11 @@ abstract class JdbcDialect extends Serializable with 
Logging{
       case f: GeneralAggregateFunc if f.name() == "AVG" =>
         assert(f.inputs().length == 1)
         val distinct = if (f.isDistinct) "DISTINCT " else ""
-        Some(s"AVG($distinct${f.inputs().head})")
+        if (supportCompletePushDown) {
+          Some(s"AVG($distinct${f.inputs().head})")
+        } else {
+          Some(s"Sum($distinct${f.inputs().head}), 
Count($distinct${f.inputs().head})")

Review comment:
       why do we need it? It's Spark's responsibility to rewrite avg to 
sum/count, not the data source.




-- 
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]

Reply via email to