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

Julian Hyde commented on CALCITE-2745:
--------------------------------------

No, it is not acceptable.

Making Rex a dynamically-typed language increases the burden for everyone else.

For dynamic record types, we should adopt something similar to how one does 
dynamic typing in java - either treat everything as an object, or use casts 
preceded by an "instanceof" check. Now, we currently don't have an "instanceof" 
operator. I wish we had one. I don't even know what it should be called in SQL. 
I suspect that Oracle added one as part of their "object" support in Oracle 8.

> 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