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

AggregateExpandDistinctAggregatesRule must cast top aggregates to original type

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    Description

      The query SELECT COUNT(comm), COUNT(DISTINCT comm) FROM emp produces the plan below:

      LogicalAggregate(group=[{}], EXPR$0=[$SUM0($1)], EXPR$1=[COUNT($0)])
        LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
          LogicalProject(COMM=[$6])
            LogicalTableScan(table=[[CATALOG, SALES, EMP]]) 
      

      In case SUM type is expanded by override RelDataTypeSystem#deriveSumType the AggregateExpandDistinctAggregatesRule fails with assertion below:

      Error:
      java.lang.AssertionError: type mismatch:
      aggCall type:
      BIGINT NOT NULL
      inferred type:
      DECIMAL(19, 0) NOT NULL
          at org.apache.calcite.util.Litmus$1.fail(Litmus.java:32)
          at org.apache.calcite.plan.RelOptUtil.eq(RelOptUtil.java:2211)
          at org.apache.calcite.rel.core.Aggregate.typeMatchesInferred(Aggregate.java:443)
          at org.apache.calcite.rel.core.Aggregate.<init>(Aggregate.java:170)
          at org.apache.calcite.rel.logical.LogicalAggregate.<init>(LogicalAggregate.java:72)
          at org.apache.calcite.rel.logical.LogicalAggregate.copy(LogicalAggregate.java:154)
          at org.apache.calcite.rel.logical.LogicalAggregate.copy(LogicalAggregate.java:48)
          at org.apache.calcite.rel.rules.AggregateExpandDistinctAggregatesRule.convertSingletonDistinct(AggregateExpandDistinctAggregatesRule.java:401)
          ... 
      

      Root cause:
      the type of SUM aggregate doesn't match original type of the COUNT.

      Attachments

        Issue Links

        Activity

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

          People

            tledkov-gridgain Taras Ledkov
            tledkov-gridgain Taras Ledkov
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1.5h
                1.5h

                Slack

                  Issue deployment