anchovYu commented on code in PR #39040:
URL: https://github.com/apache/spark/pull/39040#discussion_r1053617144


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveLateralColumnAlias.scala:
##########
@@ -244,6 +303,61 @@ object ResolveLateralColumnAliasReference extends 
Rule[LogicalPlan] {
               child = Project(innerProjectList.toSeq, child)
             )
           }
+
+        case agg @ Aggregate(groupingExpressions, aggregateExpressions, _) if 
agg.resolved
+            && 
aggregateExpressions.exists(_.containsPattern(LATERAL_COLUMN_ALIAS_REFERENCE)) 
=>
+
+          // Check if current Aggregate is eligible to lift up with Project: 
the aggregate
+          // expression only contains: 1) aggregate functions, 2) grouping 
expressions, 3) lateral
+          // column alias reference or 4) literals.
+          // This check is to prevent unnecessary transformation on invalid 
plan, to guarantee it
+          // throws the same exception. For example, cases like non-aggregate 
expressions not
+          // in group by, once transformed, will throw a different exception: 
missing input.
+          def eligibleToLiftUp(exp: Expression): Boolean = {
+            exp match {
+              case e: AggregateExpression if 
AggregateExpression.isAggregate(e) => true

Review Comment:
   oops, thanks.



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