You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Jiajun Xie (Jira)" <ji...@apache.org> on 2023/02/12 09:31:00 UTC

[jira] [Assigned] (CALCITE-5523) RelToSql converter generates GROUP BY clause with window expression

     [ https://issues.apache.org/jira/browse/CALCITE-5523?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jiajun Xie reassigned CALCITE-5523:
-----------------------------------

    Assignee: Jiajun Xie

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