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

AggregateExpandDistinctAggregatesRule should make SUM nullable if there is no GROUP BY

    XMLWordPrintableJSON

Details

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

    Description

      AggregateExpandDistinctAggregatesRule should make SUM nullable if there is no GROUP BY. The following test gives aggCall type mismatch error:

      @Test public void testDistinctCountWithoutGroupBy() {
           final HepProgram program = HepProgram.builder()
              .addRuleInstance(AggregateExpandDistinctAggregatesRule.INSTANCE)
              .addRuleInstance(AggregateProjectMergeRule.INSTANCE)
              .build();
          checkPlanning(program,
              "select max(deptno), count(distinct ename) from sales.emp");
        }
      

      exception:

      java.lang.AssertionError: type mismatch:
      aggCall type:
      INTEGER
      inferred type:
      INTEGER NOT NULL
      
      	at org.apache.calcite.util.Litmus$1.fail(Litmus.java:31)
      	at org.apache.calcite.plan.RelOptUtil.eq(RelOptUtil.java:1838)
      	at org.apache.calcite.rel.core.Aggregate.typeMatchesInferred(Aggregate.java:428)
      	at org.apache.calcite.rel.core.Aggregate.<init>(Aggregate.java:161)
      	at org.apache.calcite.rel.logical.LogicalAggregate.<init>(LogicalAggregate.java:65)
      	at org.apache.calcite.rel.logical.LogicalAggregate.create_(LogicalAggregate.java:110)
      	at org.apache.calcite.rel.logical.LogicalAggregate.create(LogicalAggregate.java:100)
      	at org.apache.calcite.rel.core.RelFactories$AggregateFactoryImpl.createAggregate(RelFactories.java:213)
      	at org.apache.calcite.tools.RelBuilder.aggregate(RelBuilder.java:1268)
      	at org.apache.calcite.tools.RelBuilder.aggregate(RelBuilder.java:1840)
      	at org.apache.calcite.rel.rules.AggregateExpandDistinctAggregatesRule.rewriteUsingGroupingSets(AggregateExpandDistinctAggregatesRule.java:413)
      	at org.apache.calcite.rel.rules.AggregateExpandDistinctAggregatesRule.onMatch(AggregateExpandDistinctAggregatesRule.java:172)
      	at org.apache.calcite.plan.AbstractRelOptPlanner.fireRule(AbstractRelOptPlanner.java:317)
      	at org.apache.calcite.plan.hep.HepPlanner.applyRule(HepPlanner.java:508)
      	at org.apache.calcite.plan.hep.HepPlanner.applyRules(HepPlanner.java:387)
      	at org.apache.calcite.plan.hep.HepPlanner.executeInstruction(HepPlanner.java:252)
      	at org.apache.calcite.plan.hep.HepInstruction$RuleInstance.execute(HepInstruction.java:127)
      	at org.apache.calcite.plan.hep.HepPlanner.executeProgram(HepPlanner.java:211)
      	at org.apache.calcite.plan.hep.HepPlanner.findBestExp(HepPlanner.java:198)
      	at org.apache.calcite.test.RelOptTestBase.checkPlanning(RelOptTestBase.java:165)
      	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.testDistinctCountWithoutGroupBy(RelOptRulesTest.java:761)
      

      Attachments

        Activity

          People

            julianhyde Julian Hyde
            godfreyhe godfrey he
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: