You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Stefan Kandic (Jira)" <ji...@apache.org> on 2026/06/09 14:19:00 UTC

[jira] [Created] (SPARK-57346) [Analyzer++] HAVING/ORDER BY aggregates over GROUPING SETS give wrong results

Stefan Kandic created SPARK-57346:
-------------------------------------

             Summary: [Analyzer++] HAVING/ORDER BY aggregates over GROUPING SETS give wrong results
                 Key: SPARK-57346
                 URL: https://issues.apache.org/jira/browse/SPARK-57346
             Project: Spark
          Issue Type: Bug
          Components: SQL
    Affects Versions: 4.2.0
            Reporter: Stefan Kandic


SUM(b) in HAVING/ORDER BY above a GROUPING SETS/CUBE/ROLLUP aggregate resolves grouping column b to the Expand-output copy (NULL for rolled-up groups) instead of the original column. HAVING filters out rolled-up rows; ORDER BY sorts them as NULL.

ORDER BY repro: 
SELECT a, b, SUM(b) FROM VALUES (1,10),(1,20),(2,30) AS t(a,b)
GROUP BY CUBE(a, b) ORDER BY SUM(b);                          
                                                                                             
HAVING repro:                                                                              
SELECT a, SUM(b) FROM VALUES (1,10),(1,20),(2,30) AS t(a,b)                                
GROUP BY ROLLUP(a, b) HAVING SUM(b) > 25;



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org