You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/07/06 23:56:12 UTC
(superset) 01/01: test(sql): prove Oracle GROUP BY is no longer rewritten to ordinals (#35414)
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a commit to branch test/issue-35414-oracle-groupby
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 3cafe1c5eead65c2a139694b71a3ed355808c019
Author: Claude Code <no...@anthropic.com>
AuthorDate: Mon Jul 6 16:51:17 2026 -0700
test(sql): prove Oracle GROUP BY is no longer rewritten to ordinals (#35414)
Co-Authored-By: Claude Fable 5 <no...@anthropic.com>
---
tests/unit_tests/sql/parse_tests.py | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/tests/unit_tests/sql/parse_tests.py b/tests/unit_tests/sql/parse_tests.py
index 5bb8a9e8ab5..c7187a50e50 100644
--- a/tests/unit_tests/sql/parse_tests.py
+++ b/tests/unit_tests/sql/parse_tests.py
@@ -439,6 +439,40 @@ WHERE
)
+def test_format_oracle_group_by_keeps_explicit_expressions() -> None:
+ """
+ Test that formatting Oracle SQL doesn't rewrite ``GROUP BY`` to ordinals.
+
+ Oracle doesn't support positional grouping (``GROUP BY 1, 2``) and fails
+ with ``ORA-00979: not a GROUP BY expression``. sqlglot < 27.21.0 rewrote
+ ``GROUP BY`` expressions that matched aliased projections into ordinals
+ when generating Oracle SQL, breaking chart queries.
+
+ Regression test for https://github.com/apache/superset/issues/35414,
+ fixed by upgrading sqlglot.
+ """
+ sql = (
+ "SELECT TRUNC(CAST(order_date AS DATE), 'MONTH') AS __timestamp, "
+ 'region AS region, SUM(sales) AS "SUM(sales)" '
+ "FROM orders "
+ "GROUP BY TRUNC(CAST(order_date AS DATE), 'MONTH'), region "
+ 'ORDER BY "SUM(sales)" DESC'
+ )
+ formatted = SQLStatement(sql, engine="oracle").format()
+
+ # pretty-formatting puts each `GROUP BY` item on its own line
+ group_by_clause = formatted.split("GROUP BY")[1].split("ORDER BY")[0]
+ group_by_items = [
+ line.strip().rstrip(",") for line in group_by_clause.strip().splitlines()
+ ]
+ assert group_by_items == [
+ "TRUNC(CAST(order_date AS DATE), 'MONTH')",
+ "region",
+ ]
+ # no item should have been replaced by a positional reference
+ assert not any(item.isdigit() for item in group_by_items)
+
+
def test_split_no_dialect() -> None:
"""
Test the statement split when the engine has no corresponding dialect.