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

AggregateMergeRule throws 'type mismatch' AssertionError

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 1.37.0
    • 1.38.0
    • None

    Description

      Hey all!
      The following Test in JdbcAdapterTests:

        @Test
        void testSumOfSumWithGroupBy() {
          CalciteAssert.model(JdbcTest.SCOTT_MODEL)
              .query("SELECT\n" +
                     "    SUM(DEPTNO)\n" +
                     "FROM\n" +
                     "    (\n" +
                     "        SELECT\n" +
                     "            SUM(DEPTNO) AS DEPTNO\n" +
                     "        FROM\n" +
                     "            \"SCOTT\".\"DEPT\"\n" +
                     "        GROUP BY\n" +
                     "            DNAME\n" +
                     "    )")
              .enable(CalciteAssert.DB == CalciteAssert.DatabaseInstance.HSQLDB)
              .runs();
        }
      

      fails with:

      java.lang.AssertionError: type mismatch:
      aggCall type:
      TINYINT NOT NULL
      inferred type:
      TINYINT
      	at org.apache.calcite.util.Litmus.lambda$static$0(Litmus.java:31)
      	at org.apache.calcite.plan.RelOptUtil.eq(RelOptUtil.java:2204)
      	at org.apache.calcite.rel.core.Aggregate.typeMatchesInferred(Aggregate.java:450)
      	at org.apache.calcite.rel.core.Aggregate.<init>(Aggregate.java:177)
      

      Its possible to workaround this issue by adding a COALESCE block
      (see

        @Test
        void testSumOfSumWithGroupBy() {
          CalciteAssert.model(JdbcTest.SCOTT_MODEL)
              .query("SELECT\n" +
                     "    SUM(DEPTNO)\n" +
                     "FROM\n" +
                     "    (\n" +
                     "        SELECT\n" +
                     "            COALESCE(SUM(DEPTNO),0) AS DEPTNO\n" +
                     "        FROM\n" +
                     "            \"SCOTT\".\"DEPT\"\n" +
                     "        GROUP BY\n" +
                     "            DNAME\n" +
                     "    )")
              .enable(CalciteAssert.DB == CalciteAssert.DatabaseInstance.HSQLDB)
              .runs();
        }
      

      )

      however I think the statement should also work without the workaround.

      Since "TINYINT NOT NULL" is a subset of "TINYINT" the equality check could be made more tolerant?

      BR,
      Corvin

      Attachments

        Issue Links

          Activity

            People

              julianhyde Julian Hyde
              corvinkuebler Corvin Kuebler
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: