[ 
https://issues.apache.org/jira/browse/CALCITE-5523?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17766056#comment-17766056
 ] 

Leonid Chistov commented on CALCITE-5523:
-----------------------------------------

[~jiajunbernoulli] 

That is quite interesting since documentation that I was able to find 
[https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/Analytic-Functions.html#GUID-527832F7-63C0-4445-8C16-307FA5084056]
 seems to say that it should not be supported.

But I don't have access to Oracle, so I cannot check.

And also in your example it is a HAVING clause, not GROUP BY clause.

> 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)

Reply via email to