[ https://issues.apache.org/jira/browse/CALCITE-5523?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
ASF GitHub Bot updated CALCITE-5523: ------------------------------------ Labels: pull-request-available (was: ) > RelToSql converter generates GROUP BY clause with window expression > ------------------------------------------------------------------- > > Key: CALCITE-5523 > URL: https://issues.apache.org/jira/browse/CALCITE-5523 > Project: Calcite > Issue Type: Bug > Components: jdbc-adapter > Reporter: Leonid Chistov > Assignee: Jiajun Xie > Priority: Major > Labels: pull-request-available > > 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: > {code: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); > } > {code} > Generated SQL code will look like: > {code:java} > SELECT RANK() OVER (ORDER BY hire_date) AS rank > FROM foodmart.employee > GROUP BY RANK() OVER (ORDER BY hire_date){code} > 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: > {code:java} > Windowed aggregate expression is illegal in GROUP BY clause {code} -- This message was sent by Atlassian Jira (v8.20.10#820010)