viirya commented on a change in pull request #25215: [SPARK-28445][SQL][Python] 
Fix error when PythonUDF is used in both group by and aggregate expression
URL: https://github.com/apache/spark/pull/25215#discussion_r308231137
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/python/ExtractPythonUDFs.scala
 ##########
 @@ -81,6 +81,64 @@ object ExtractPythonUDFFromAggregate extends 
Rule[LogicalPlan] {
   }
 }
 
+/**
+ * Extracts PythonUDFs in logical aggregate, which are used in grouping keys, 
evaluate them
+ * before aggregate.
+ * This must be executed after `ExtractPythonUDFFromAggregate` rule and before 
`ExtractPythonUDFs`.
+ */
+object ExtractGroupingPythonUDFFromAggregate extends Rule[LogicalPlan] {
 
 Review comment:
   ExtractPythonUDFFromAggregate pulls out Python UDFs which have aggregate 
expression or grouping key as input, like udf(sum(c)), and Python UDFs which 
have no input. Those UDFs pulled out are evaluated after aggregate.
   
   
   This rule, ExtractGroupingPythonUDFFromAggregate, pulls out Python UDFs 
which are used in grouping keys, like `SELECT count(*) FROM table GROUP BY 
udf(id)`.  This kind of Python UDF is evaluated before aggregate.
   

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

Reply via email to