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

Aggregate functions in OVER clause

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.15.0
    • None
    • None

    Description

      When window functions use aggregate functions in PARTITION BY or ORDER BY sub-clause of the OVER clause, Calcite gives a NullPointerException.

      Currently the scene of window functions on top of nested aggregations is already in consideration, however, that one as follow is not:

      select
        sum(sal),
        rank() over (order by sum(sal))
      from emp
      group by deptno
      

      An NPE from SqlToRelConverter:

      java.lang.NullPointerException
      	at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:212)
      	at org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.convertExpression(SqlToRelConverter.java:4470)
      	at org.apache.calcite.sql2rel.SqlToRelConverter.convertOver(SqlToRelConverter.java:1839)
      	at org.apache.calcite.sql2rel.SqlToRelConverter.access$1500(SqlToRelConverter.java:213)
      	at org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.convertExpression(SqlToRelConverter.java:4462)
      	at org.apache.calcite.sql2rel.SqlToRelConverter.createAggImpl(SqlToRelConverter.java:2857)
      	at org.apache.calcite.sql2rel.SqlToRelConverter.convertAgg(SqlToRelConverter.java:2675)
      	at org.apache.calcite.sql2rel.SqlToRelConverter.convertSelectImpl(SqlToRelConverter.java:660)
      	at org.apache.calcite.sql2rel.SqlToRelConverter.convertSelect(SqlToRelConverter.java:622)
      	at org.apache.calcite.sql2rel.SqlToRelConverter.convertQueryRecursive(SqlToRelConverter.java:3085)
      	at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:558)
      	at org.apache.calcite.test.SqlToRelTestBase$TesterImpl.convertSqlToRel(SqlToRelTestBase.java:574)
      	at org.apache.calcite.test.RelOptTestBase.checkPlanning(RelOptTestBase.java:137)
      	at org.apache.calcite.test.RelOptTestBase.checkPlanning(RelOptTestBase.java:120)
      	at org.apache.calcite.test.RelOptTestBase.checkPlanning(RelOptTestBase.java:95)
      	at org.apache.calcite.test.RelOptTestBase.checkPlanning(RelOptTestBase.java:84)
      	at org.apache.calcite.test.RelOptRulesTest.testWindowAggregatesWithOrderByAgg(RelOptRulesTest.java:2722)
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            julianhyde Julian Hyde
            Liao Liao Xintao
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment