You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Laurent Goujon (JIRA)" <ji...@apache.org> on 2018/04/28 00:16:00 UTC

[jira] [Commented] (CALCITE-2288) Type assertion error when reducing partially constant expression

    [ https://issues.apache.org/jira/browse/CALCITE-2288?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16457254#comment-16457254 ] 

Laurent Goujon commented on CALCITE-2288:
-----------------------------------------

I guess the simplifier cannot add back the correct type, because the information is already lost. In that case, the type of expressions returned by {{ReduceExpressionRule#reduceExpressionInternal}} should be correct. But there's also a phase of simplification in that method, which is only using {{RexSimplifier}} and not {{ExprSimplifier}}. However since CALCITE-2041, {{RexSimplifier}} will strip a type from its nullability flag if reduced to a literal or similar.

> Type assertion error when reducing partially constant expression
> ----------------------------------------------------------------
>
>                 Key: CALCITE-2288
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2288
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: Laurent Goujon
>            Assignee: Julian Hyde
>            Priority: Major
>
> Probably a follow up of CALCITE-2041
> The following query failed at planning time with an assertion error:
> {code:sql}
> 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
> {code}
> Stacktrace is:
> {noformat}
> 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)
> ...
> {noformat}
> 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.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)