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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/resolver/OperatorResolutionContext.scala:
##########
@@ -130,19 +131,22 @@ class OperatorResolutionContextStack {
       new OperatorResolutionContext(
         unresolvedPlan = Some(unresolvedPlan),
         isResolvingTreeUnderHaving = isResolvingTreeUnderHaving,
-        parameterNamesToValues = current.parameterNamesToValues
+        parameterNamesToValues = current.parameterNamesToValues,
+        isSubqueryRoot = isSubqueryRoot
       )
     )
   }
 
   /**
    * Pops the top resolution context from the stack. Before popping, 
propagates the
    * `hasGroupingAnalytics` from the child context to the parent context if it 
was set.
+   * The flag is NOT propagated across subquery boundaries (isSubqueryRoot), 
because grouping
+   * analytics inside a subquery are unrelated to operators in the outer query.
    */
   def pop(): Unit = {
     val childContext = current
     stack.pop()
-    if (childContext.hasGroupingAnalytics) {
+    if (childContext.hasGroupingAnalytics && !childContext.isSubqueryRoot) {

Review Comment:
   This boundary still misses derived-table query blocks. `SubqueryAlias` 
resolves its child with an ordinary context, so a query such as `SELECT a FROM 
(SELECT a FROM VALUES (1) t(a) GROUP BY CUBE(a)) s GROUP BY a HAVING a > 0` 
propagates this flag and rejects the unrelated outer HAVING in pure single-pass 
mode; outer ORDER BY has the same problem. Please isolate grouping-analytics 
state at derived-table boundaries as well, and add both HAVING and ORDER BY 
regressions.



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