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

Type assertion error when reducing partially constant expression

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Not A Problem
    • Affects Version/s: None
    • Fix Version/s: 1.19.0
    • Component/s: core

      Description

      Probably a follow up of CALCITE-2041

      The following query failed at planning time with an assertion error:

      SELECT
        EXTRACT(SECOND FROM CAST(CASE WHEN TRUE THEN {ts '2018-01-01 01:23:45'} ELSE NULL END AS TIMESTAMP)) =
        EXTRACT(SECOND FROM d)
      FROM (VALUES({ts '2018-01-01 01:23:45'})) tbl(d
      

      Stacktrace is:

      java.lang.AssertionError: Cannot add expression of different type to set:
      set type is RecordType(BOOLEAN EXPR$0) NOT NULL
      expression type is RecordType(BOOLEAN NOT NULL EXPR$0) NOT NULL
      set is rel#4:LogicalProject(input=HepRelVertex#3,EXPR$0==(EXTRACT(FLAG(SECOND), CAST(CASE(true, 2018-01-01 01:23:45, null)):TIMESTAMP(0)), EXTRACT(FLAG(SECOND), $0)))
      expression is LogicalProject#6
      	at org.apache.calcite.plan.RelOptUtil.verifyTypeEquivalence(RelOptUtil.java:413)
      	at org.apache.calcite.plan.hep.HepRuleCall.transformTo(HepRuleCall.java:57)
      	at org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:234)
      	at org.apache.calcite.rel.rules.ReduceExpressionsRule$ProjectReduceExpressionsRule.onMatch(ReduceExpressionsRule.java:290)
      	at org.apache.calcite.plan.AbstractRelOptPlanner.fireRule(AbstractRelOptPlanner.java:317)
      	at org.apache.calcite.plan.hep.HepPlanner.applyRule(HepPlanner.java:556)
      	at org.apache.calcite.plan.hep.HepPlanner.applyRules(HepPlanner.java:415)
      	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)
      ...
      

      As far as I can tell, the issue is in ReduceExpressionRules#reduceExpressions: when the expression is partially reduced, the reduced expression lost its type nullability, which is not added back by the simplifier.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                laurent Laurent Goujon
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m