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

Nested window aggregate throws UnsupportedOperationException with the default ValidatorConfig

    XMLWordPrintableJSON

Details

    Description

      I was trying to run TPC-DS with the default ValidatorConfig. And the default value of validatorConfig.identifierExpansion is false. java.lang.UnsupportedOperationException were thrown when executing TPC-DS query12 and some other TPC-DS queries which used nested window aggregate, like `sum(sum(ws_ext_sales_price)) OVER (partition BY i_class)`.

      This bug can be easily reproduced using the following testcase

      // SqlToRelConverterTest
      @Test void testNestedWindowAggWithIdentifierExpansionDisabled(){
        String sql = "select sum(sum(sal)) over() from emp";
        sql(sql)
            .withFactory(f ->
                f.withValidator((opTab, catalogReader, typeFactory, config) -> {
                  if (config.conformance().allowGeometry()) {
                    opTab =
                        SqlOperatorTables.chain(opTab,
                            SqlOperatorTables.spatialInstance());
                  }
                  return SqlValidatorUtil.newValidator(opTab, catalogReader,
                      typeFactory, config.withIdentifierExpansion(false));
                }))
            .withTrim(false)
            .ok();
      } 

       

      The error stacktrace is as follows.

      java.lang.UnsupportedOperationException: class org.apache.calcite.sql.SqlBasicCall: SUM(SUM(`SAL`)) OVER ()
          at org.apache.calcite.util.Util.needToImplement(Util.java:1112)
          at org.apache.calcite.sql.validate.SqlValidatorImpl.getValidatedNodeType(SqlValidatorImpl.java:1908)
          at org.apache.calcite.sql2rel.SqlToRelConverter.convertOver(SqlToRelConverter.java:2333)
          at org.apache.calcite.sql2rel.SqlToRelConverter.access$2200(SqlToRelConverter.java:253)
          at org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.convertExpression(SqlToRelConverter.java:5701)
          at org.apache.calcite.sql2rel.SqlToRelConverter.createAggImpl(SqlToRelConverter.java:3664)
          at org.apache.calcite.sql2rel.SqlToRelConverter.convertAgg(SqlToRelConverter.java:3500)
          at org.apache.calcite.sql2rel.SqlToRelConverter.convertSelectList(SqlToRelConverter.java:4739)
          at org.apache.calcite.sql2rel.SqlToRelConverter.convertSelectImpl(SqlToRelConverter.java:809)
          at org.apache.calcite.sql2rel.SqlToRelConverter.convertSelect(SqlToRelConverter.java:735)
          at org.apache.calcite.sql2rel.SqlToRelConverter.convertQueryRecursive(SqlToRelConverter.java:3915)
          at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:628)
          at org.apache.calcite.sql.test.AbstractSqlTester.convertSqlToRel2(AbstractSqlTester.java:544)
          at org.apache.calcite.sql.test.AbstractSqlTester.assertSqlConvertsTo(AbstractSqlTester.java:485)
          at org.apache.calcite.sql.test.AbstractSqlTester.assertConvertsTo(AbstractSqlTester.java:463)
          at org.apache.calcite.test.SqlToRelFixture.convertsTo(SqlToRelFixture.java:106)
          at org.apache.calcite.test.SqlToRelFixture.ok(SqlToRelFixture.java:94) 
      at org.apache.calcite.test.SqlToRelConverterTest.testNestedWindowAggWithIdentifierExpansionDisabled(SqlToRelConverterTest.java:5373)

       

      The identifierExpansion config option is suppose to have nothing to do with nested window aggregate, so I think this is a bug, and was not tested out before due to the Caclite test framework `Fixture` sets this option to true as default for test cases.

      public static final SqlToRelFixture DEFAULT =
          new SqlToRelFixture("?", true, TESTER, SqlTestFactory.INSTANCE, false,
              false, null)
              .withFactory(f ->
                  f.withValidator((opTab, catalogReader, typeFactory, config) -> {
                    if (config.conformance().allowGeometry()) {
                      opTab =
                          SqlOperatorTables.chain(opTab,
                              SqlOperatorTables.spatialInstance());
                    }
                    return SqlValidatorUtil.newValidator(opTab, catalogReader,
                        typeFactory, config.withIdentifierExpansion(true));
                  }) 
      // ........

       

      Attachments

        Issue Links

          Activity

            People

              xiaoheng86 Heng Xiao
              xiaoheng86 Heng Xiao
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: