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

Volodymyr Vysotskyi commented on CALCITE-2745:
----------------------------------------------

Thanks for looking into this.
I agree that {{SqlToRelConverter}} should be responsible for adding casts, 
where it is required. But for the case of dynamic record type, it is impossible 
to determine whether cast should be added or not.

Is it acceptable to modify {{RexSimplify}} do not attempt to simplify only 
expression parts which be compared without casts? So it will allow postponing 
the responsibility for the handling of expressions to the executors.

> RexSimplify fails with ClassCastException when the expression contains 
> comparisons of operands with different types
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-2745
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2745
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Volodymyr Vysotskyi
>            Assignee: Julian Hyde
>            Priority: Major
>
> {{RexSimplify}} fails with {{ClassCastException}} when the expression 
> contains predicates with comparisons of operands with different types.
> Test to reproduce this issue (placed into {{JdbcAdapterTest}}):
> {code:sql}
>   @Test public void testSeveralTypesComparison() {
>     CalciteAssert.model(JdbcTest.FOODMART_MODEL)
>         .query("SELECT \"full_name\" FROM \"employee\" WHERE "
>             + "\"employee_id\" = '1' and \"employee_id\" > 0")
>         .returns("full_name=Sheri Nowmer\n");
>   }
> {code}
> It fails with the error:
> {noformat}
> Caused by: java.lang.ClassCastException: org.apache.calcite.util.NlsString 
> cannot be cast to java.math.BigDecimal
>       at java.math.BigDecimal.compareTo(BigDecimal.java:220)
>       at 
> org.apache.calcite.rex.RexSimplify.processRange(RexSimplify.java:1780)
>       at 
> org.apache.calcite.rex.RexSimplify.simplifyAnd2ForUnknownAsFalse(RexSimplify.java:1242)
>       at 
> org.apache.calcite.rex.RexSimplify.simplifyAnd2ForUnknownAsFalse(RexSimplify.java:1109)
>       at org.apache.calcite.rex.RexSimplify.simplifyAnds(RexSimplify.java:386)
>       at 
> org.apache.calcite.rex.RexSimplify.simplifyFilterPredicates(RexSimplify.java:2028)
>       at org.apache.calcite.tools.RelBuilder.filter(RelBuilder.java:1048)
>       at org.apache.calcite.tools.RelBuilder.filter(RelBuilder.java:1037)
>       at 
> org.apache.calcite.rel.rules.PushProjector.convertProject(PushProjector.java:382)
>       at 
> org.apache.calcite.rel.rules.ProjectFilterTransposeRule.onMatch(ProjectFilterTransposeRule.java:104)
>       at 
> org.apache.calcite.plan.volcano.VolcanoRuleCall.onMatch(VolcanoRuleCall.java:212)
>       ... 41 more
> {noformat}
> When the query has any of the {{AND}} operands, or when 
> {{ProjectFilterTransposeRule}} is not applied it is passed.
> Regarding the comparison of different data types, SQL spec says the following:
> {quote}8.2 <comparison predicate> Syntax Rules
>  3) The declared types of the corresponding fields of the two <row value 
> predicand>s shall be comparable.
> {quote}
> But it also allows implicit casts from numeric types to chars (6.13 <cast 
> specification>).



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

Reply via email to