Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
None
-
None
Description
Wrong SQL code is generated when aggregation is done on the field being a result of window expression evaluation.
Example can be demonstrated by adding following code to RelToSqlConverterTest.java:
@Test void testConvertWindowGroupByToSql() { String query = "SELECT * FROM (" + "SELECT rank() over (order by \"hire_date\") \"rank\" FROM \"employee\"" + ") GROUP BY \"rank\""; String expected ="SELECT * FROM (" + "SELECT rank() over (order by \"hire_date\") AS \"$0\" FROM \"employee\"" + ") GROUP BY \"$0\""; sql(query).ok(expected); }
Generated SQL code will look like:
SELECT RANK() OVER (ORDER BY hire_date) AS rank FROM foodmart.employee GROUP BY RANK() OVER (ORDER BY hire_date)
This is incorrect - window expressions are not allowed in GROUP BY clause by SQL standard and Calcite itself would produce following error message if this SQL code would be passed as input:
Windowed aggregate expression is illegal in GROUP BY clause
Attachments
Issue Links
- relates to
-
CALCITE-5502 RelToSql converter generates where clause with window expression
- Open
- links to