Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Not A Problem
-
None
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
- links to