Github user HyukjinKwon commented on a diff in the pull request: https://github.com/apache/spark/pull/20360#discussion_r163228866 --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/python/ExtractPythonUDFs.scala --- @@ -45,7 +45,8 @@ object ExtractPythonUDFFromAggregate extends Rule[LogicalPlan] { private def hasPythonUdfOverAggregate(expr: Expression, agg: Aggregate): Boolean = { expr.find { - e => PythonUDF.isScalarPythonUDF(e) && e.find(belongAggregate(_, agg)).isDefined + e => PythonUDF.isScalarPythonUDF(e) && + (e.references.isEmpty || e.find(belongAggregate(_, agg)).isDefined) --- End diff -- I think `references` is more correct - If we use `children` and then we could have an expression, for example, a literal, we would not try this extraction, ending up with leaving `HashAggregateExec` still binding to the Python UDF because I think its `children` is non-empty but it doesn't belong to the aggregate expression in this case whereas `references` remains empty.
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org