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



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -2163,22 +2235,29 @@ class Analyzer(
                   alias.toAttribute
               }
           }
-
-          // Push the aggregate expressions into the aggregate (if any).
-          if (aggregateExpressions.nonEmpty) {
-            Project(agg.output,
-              Filter(transformedAggregateFilter,
-                agg.copy(aggregateExpressions = agg.aggregateExpressions ++ 
aggregateExpressions)))
-          } else {
-            filter
-          }
+          (aggregateExpressions, Some(transformedAggregateFilter))
         } else {
-          filter
+          (aggregateExpressions, None)
         }
       } catch {
         // Attempting to resolve in the aggregate can result in ambiguity.  
When this happens,
         // just return the original plan.
-        case ae: AnalysisException => filter
+        case ae: AnalysisException => (aggregateExpressions, None)
+      }
+    }
+
+    def resolveHaving(filter: Filter, agg: Aggregate): LogicalPlan = {
+      // Try resolving the condition of the filter as though it is in the 
aggregate clause
+      val (aggregateExpressions, resolvedHavingCond) =
+        resolveFilterCondInAggregate(filter.condition, agg)
+
+      // Push the aggregate expressions into the aggregate (if any).
+      if (aggregateExpressions.nonEmpty) {

Review comment:
       you seem to assume that, if `aggregateExpressions.nonEmpty`, then 
`resolvedHavingCond` must be `Some`. Let's make the 
`resolveFilterCondInAggregate` more clear with this assumption.




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

Reply via email to