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] [Commented] (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:comment-tabpanel&focusedCommentId=17687547#comment-17687547 ]
Jiajun Xie commented on CALCITE-5523:
-------------------------------------
In my opinion, it is similar as CALCITE-4491.
I have simple way to fix it.
{code:java}
if (!dialect.supportsNestedAggregations()
&& agg.getInput() instanceof Project
&& ((Project) agg.getInput()).containsOver()) {
return true;
} {code}
But I think `[hasNestedWindowedAgg|https://github.com/gooddata/calcite/blob/a1569b0dd67f4eda781d4b44956c475a91102c97/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java#L1811]` should cover it, I'm trying.
> 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
> 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)