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

CoreRules.PROJECT_REDUCE_EXPRESSIONS crashes on expression with ARRAY_REPEAT

    XMLWordPrintableJSON

Details

    Description

      The following test in RelOptRulesTest causes a crash:

        @Test void testArrayRepeat() {
          final String sql = "select array_repeat(1, null)";
          sql(sql)
              .withFactory(
                  t -> t.withOperatorTable(
                      opTab -> SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(
                          SqlLibrary.STANDARD, SqlLibrary.SPARK)))
              .withRule(CoreRules.PROJECT_REDUCE_EXPRESSIONS)
              .check();
        }
      

      The crash is:

      java.lang.AssertionError: Cannot add expression of different type to set:
      set type is RecordType(INTEGER NOT NULL ARRAY NOT NULL EXPR$0) NOT NULL
      expression type is RecordType(INTEGER NOT NULL ARRAY EXPR$0) NOT NULL
      set is rel#4:LogicalProject.(input=HepRelVertex#3,exprs=[ARRAY_REPEAT(1, null:DECIMAL(19, 9))])
      expression is LogicalProject(EXPR$0=[null:INTEGER NOT NULL ARRAY])
        LogicalValues(tuples=[[{ 0 }]])
      Type mismatch:
      rowtype of original rel: RecordType(INTEGER NOT NULL ARRAY NOT NULL EXPR$0) NOT NULL
      rowtype of new rel: RecordType(INTEGER NOT NULL ARRAY EXPR$0) NOT NULL
      Difference:
      EXPR$0: INTEGER NOT NULL ARRAY NOT NULL -> INTEGER NOT NULL ARRAY
      
      	at org.apache.calcite.plan.RelOptUtil.verifyTypeEquivalence(RelOptUtil.java:419)
      	at org.apache.calcite.plan.hep.HepRuleCall.transformTo(HepRuleCall.java:60)
      	at org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:273)
      	at org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:288)
      	at org.apache.calcite.rel.rules.ReduceExpressionsRule$ProjectReduceExpressionsRule.onMatch(ReduceExpressionsRule.java:317)
      	at org.apache.calcite.plan.AbstractRelOptPlanner.fireRule(AbstractRelOptPlanner.java:337)
      

      Attachments

        Issue Links

          Activity

            People

              mbudiu Mihai Budiu
              mbudiu Mihai Budiu
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: