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

Optimizing ARRAY_REPEAT expression causes an assertion failure

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 1.36.0
    • 1.37.0
    • core
    • None

    Description

      The following RelOptRulesTest causes an assertion failure:

        @Test void testArrayRepeat() {
          sql("SELECT array_repeat(123, null)")
              .withFactory(
                  t -> t.withOperatorTable(
                      opTab -> SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(
                          SqlLibrary.STANDARD, SqlLibrary.SPARK)))
              .withRule(CoreRules.PROJECT_REDUCE_EXPRESSIONS).checkUnchanged();
        }
      

      The assertion failure 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(123, 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)
      

      This suggests that the type inferred for ARRAY_REPEAT is incorrect.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: