martuafernando opened a new issue, #37044:
URL: https://github.com/apache/superset/issues/37044
### Bug description
When using Apache Superset 6.0.0 with the Oracle dialect, aggregate queries
that use positional references in the GROUP BY clause (e.g. GROUP BY 1) are
compiled into SQL that is invalid in Oracle, resulting in the following error:
Log
```
2026-01-12 14:15:49,756:DEBUG:superset.stats_logger:[stats_logger] (incr)
_get_data_response
2026-01-12 14:15:49,778:WARNING:superset.models.helpers:Query SELECT
anon_1."REGION", anon_1."count"
FROM (SELECT "REGION" AS "REGION", COUNT(*) AS "count"
FROM (SELECT
'North' AS region,
1 AS id
FROM dual
UNION ALL
SELECT
'North' AS region,
2 AS id
FROM dual
UNION ALL
SELECT
'South' AS region,
3 AS id
FROM dual
UNION ALL
SELECT
'South' AS region,
4 AS id
FROM dual
UNION ALL
SELECT
'East' AS region,
5 AS id
FROM dual) virtual_table GROUP BY "REGION" ORDER BY COUNT(*) DESC) anon_1
WHERE ROWNUM <= 1000 on schema failed
Traceback (most recent call last):
File "D:\dev\superset-test\superset\models\helpers.py", line 1182, in query
df = self.database.get_df(
^^^^^^^^^^^^^^^^^^^^^
File "D:\dev\superset-test\superset\models\core.py", line 768, in get_df
cursor, rows, description = self._execute_sql_with_mutation_and_logging(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\dev\superset-test\superset\models\core.py", line 721, in
_execute_sql_with_mutation_and_logging
self.db_engine_spec.execute(cursor, sql_, self)
File "D:\dev\superset-test\superset\db_engine_specs\base.py", line 1890,
in execute
raise cls.get_dbapi_mapped_exception(ex) from ex
File "D:\dev\superset-test\superset\db_engine_specs\base.py", line 1886,
in execute
cursor.execute(query)
cx_Oracle.DatabaseError: ORA-00979: not a GROUP BY expression
Help: https://docs.oracle.com/error-help/db/ora-00979/
```
This appears to be caused by SQLGlot preserving or emitting positional GROUP
BY expressions instead of rewriting them to the actual column expressions,
which is not reliable in Oracle and leads to ORA-00979: not a GROUP BY
expression.
Original Query
```sql
SELECT anon_1."REGION", anon_1."count"
FROM (SELECT "REGION" AS "REGION", COUNT(*) AS "count"
FROM (SELECT
'North' AS region,
1 AS id
FROM dual
UNION ALL
SELECT
'North' AS region,
2 AS id
FROM dual
UNION ALL
SELECT
'South' AS region,
3 AS id
FROM dual
UNION ALL
SELECT
'South' AS region,
4 AS id
FROM dual
UNION ALL
SELECT
'East' AS region,
5 AS id
FROM dual) virtual_table GROUP BY "REGION" ORDER BY COUNT(*) DESC) anon_1
WHERE ROWNUM <= 1000;
```
Formatted Query
```
SELECT
anon_1."REGION",
anon_1."count"
FROM (
SELECT
"REGION" AS "REGION",
COUNT(*) AS "count"
FROM (
SELECT
'North' AS region,
1 AS id
FROM dual
UNION ALL
SELECT
'North' AS region,
2 AS id
FROM dual
UNION ALL
SELECT
'South' AS region,
3 AS id
FROM dual
UNION ALL
SELECT
'South' AS region,
4 AS id
FROM dual
UNION ALL
SELECT
'East' AS region,
5 AS id
FROM dual
) virtual_table
GROUP BY
1
ORDER BY
COUNT(*) DESC
) anon_1
WHERE
ROWNUM <= 1000
```
### Screenshots/recordings
<img width="1919" height="1067" alt="Image"
src="https://github.com/user-attachments/assets/b439e61c-a51e-4c08-8248-834c0b7c4590"
/>
### Superset version
master / latest-dev
### Python version
3.11
### Node version
18 or greater
### Browser
Chrome
### Additional context
_No response_
### Checklist
- [x] I have searched Superset docs and Slack and didn't find a solution to
my problem.
- [x] I have searched the GitHub issue tracker and didn't find a similar bug
report.
- [x] I have checked Superset's logs for errors and if I found a relevant
Python stacktrace, I included it here as text in the "additional context"
section.
--
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]