Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-6442

Validator rejects FILTER in OVER windows

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.37.0
    • 1.38.0
    • core
    • None

    Description

      The Calcite grammar about windows says this:

      windowedAggregateCall:
            agg '(' [ ALL | DISTINCT ] value [, value ]* ')'
            [ RESPECT NULLS | IGNORE NULLS ]
            [ WITHIN GROUP '(' ORDER BY orderItem [, orderItem ]* ')' ]
            [ FILTER '(' WHERE condition ')' ]
            OVER window
      

      However, the validator rejects the following query:

      SELECT deptno,
             COUNT(DISTINCT deptno) FILTER (WHERE deptno > 10)
      OVER win AS agg
      FROM emp
      WINDOW win AS (PARTITION BY empno)
      

      with the following error:

      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)
      

      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.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              mbudiu Mihai Budiu
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: