cloud-fan commented on code in PR #51820:
URL: https://github.com/apache/spark/pull/51820#discussion_r2254411146


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala:
##########
@@ -792,27 +792,33 @@ class Analyzer(override val catalogManager: 
CatalogManager) extends RuleExecutor
       } else {
         colResolved.havingCondition
       }
-      // Try resolving the condition of the filter as though it is in the 
aggregate clause
-      val (extraAggExprs, Seq(resolvedHavingCond)) =
-        ResolveAggregateFunctions.resolveExprsWithAggregate(Seq(cond), 
aggForResolving)
-
-      // Push the aggregate expressions into the aggregate (if any).
-      val newChild = constructAggregate(h, selectedGroupByExprs, groupByExprs,
-        aggregate.aggregateExpressions ++ extraAggExprs, aggregate.child)
-
-      // Since the output exprId will be changed in the constructed aggregate, 
here we build an
-      // attrMap to resolve the condition again.
-      val attrMap = AttributeMap((aggForResolving.output ++ 
extraAggExprs.map(_.toAttribute))
-        .zip(newChild.output))
-      val newCond = resolvedHavingCond.transform {
-        case a: AttributeReference => attrMap.getOrElse(a, a)
-      }
-
-      if (extraAggExprs.isEmpty) {
-        Filter(newCond, newChild)
+      // `cond` might contain unresolved aggregate functions so defer its 
resolution to
+      // `ResolveAggregateFunctions` rule if needed.
+      if (!cond.resolved) {

Review Comment:
   it's not only to minimize diff, but the "early return" pattern is 
recommended in general, see 
https://medium.com/swlh/return-early-pattern-3d18a41bba8



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