[ https://issues.apache.org/jira/browse/CALCITE-5523?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17766053#comment-17766053 ]
Jiajun Xie commented on CALCITE-5523: ------------------------------------- [~lchistov1987] , Oracle support it. {code:java} // Oracle does support nested aggregations final String expectedOracle = "SELECT COUNT(DISTINCT RANK() OVER (ORDER BY \"SAL\")) \"c\"\n" + "FROM \"scott\".\"EMP\"\n" + "HAVING COUNT(DISTINCT RANK() OVER (ORDER BY \"SAL\")) >= 10"; relFn(relFn).withOracle().ok(expectedOracle); {code} So I use `supportsNestedAggregations()` . > 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)