[
https://issues.apache.org/jira/browse/CALCITE-6442?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17856302#comment-17856302
]
Mihai Budiu commented on CALCITE-6442:
--------------------------------------
The git blame shows that [~julianhyde] has made these edits sometime in 2020 as
part of a commit tagged "Copy-edit SQL reference":
7a75cc6863982aee981c9c03198561f785a35442
I will submit a fix to the grammar.
> Validator rejects FILTER in OVER windows
> ----------------------------------------
>
> Key: CALCITE-6442
> URL: https://issues.apache.org/jira/browse/CALCITE-6442
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.37.0
> Reporter: Mihai Budiu
> Priority: Minor
>
> The Calcite grammar about windows says this:
> {code}
> windowedAggregateCall:
> agg '(' [ ALL | DISTINCT ] value [, value ]* ')'
> [ RESPECT NULLS | IGNORE NULLS ]
> [ WITHIN GROUP '(' ORDER BY orderItem [, orderItem ]* ')' ]
> [ FILTER '(' WHERE condition ')' ]
> OVER window
> {code}
> However, the validator rejects the following query:
> {code:sql}
> SELECT deptno,
> COUNT(DISTINCT deptno) FILTER (WHERE deptno > 10)
> OVER win AS agg
> FROM emp
> WINDOW win AS (PARTITION BY empno)
> {code}
> with the following error:
> {code}
> org.apache.calcite.sql.validate.SqlValidatorException: OVER must be applied
> to aggregate function
> at
> java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:67)
> at
> java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
> at
> java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:484)
> at
> org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:507)
> at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:601)
> at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:948)
> at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:933)
> at
> org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(SqlValidatorImpl.java:5676)
> at
> org.apache.calcite.sql.SqlOverOperator.validateCall(SqlOverOperator.java:77)
> at
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:6404)
> {code}
> The easy fix would be to remove this from the grammar.
> A harder fix would be to implement support for FILTERs in windows, but I
> don't know how hard that would be.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)