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

Volodymyr Vysotskyi edited comment on CALCITE-2745 at 12/17/18 6:23 PM:
------------------------------------------------------------------------

Similar problem, but with another methodĀ of {{RexSimplify}}:
This test
{code:java}
checkSimplifyUnchanged(and(gt(vInt(1), literal(10)), eq(vInt(1), 
literal("2"))));
{code}
fails with
{noformat}
java.lang.ClassCastException: java.math.BigDecimal cannot be cast to 
org.apache.calcite.util.NlsString

        at org.apache.calcite.util.NlsString.compareTo(NlsString.java:45)
        at com.google.common.collect.Range.compareOrThrow(Range.java:672)
        at com.google.common.collect.Cut.compareTo(Cut.java:79)
        at com.google.common.collect.Range.encloses(Range.java:497)
        at org.apache.calcite.rex.RexSimplify.residue(RexSimplify.java:1413)
        at 
org.apache.calcite.rex.RexSimplify.simplifyUsingPredicates(RexSimplify.java:1349)
        at 
org.apache.calcite.rex.RexSimplify.simplifyComparison(RexSimplify.java:366)
        at 
org.apache.calcite.rex.RexSimplify.simplifyComparison(RexSimplify.java:294)
        at org.apache.calcite.rex.RexSimplify.simplify(RexSimplify.java:285)
        at 
org.apache.calcite.rex.RexSimplify.simplifyAndTerms(RexSimplify.java:406)
        at org.apache.calcite.rex.RexSimplify.simplifyAnd(RexSimplify.java:1031)
        at org.apache.calcite.rex.RexSimplify.simplify(RexSimplify.java:257)
        at 
org.apache.calcite.rex.RexSimplify.lambda$simplifyUnknownAs$0(RexSimplify.java:232)
        at org.apache.calcite.rex.RexSimplify.verify(RexSimplify.java:1486)
        at 
org.apache.calcite.rex.RexSimplify.simplifyUnknownAs(RexSimplify.java:231)
        at 
org.apache.calcite.test.RexProgramTest.checkSimplify3_(RexProgramTest.java:182)
        at 
org.apache.calcite.test.RexProgramTest.checkSimplify2(RexProgramTest.java:157)
        at 
org.apache.calcite.test.RexProgramTest.testSimplifyAndNot(RexProgramTest.java:2415)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
        at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
        at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at 
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
        at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
        at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
        at 
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
        at 
com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
        at 
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
        at 
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
{noformat}


was (Author: vvysotskyi):
Similar problem, but with another methodĀ of {{RexSimplify}}:
This test
{code:java}
    checkSimplify2(and(gt(vInt(1), literal(1)), eq(vInt(1), literal("2"))),
        "AND(>(?0.int1, 1), =(?0.int1, '2'))",
        "=(?0.int1, '2')");
{code}
fails with
{noformat}
java.lang.ClassCastException: java.math.BigDecimal cannot be cast to 
org.apache.calcite.util.NlsString

        at org.apache.calcite.util.NlsString.compareTo(NlsString.java:45)
        at com.google.common.collect.Range.compareOrThrow(Range.java:672)
        at com.google.common.collect.Cut.compareTo(Cut.java:79)
        at com.google.common.collect.Range.encloses(Range.java:497)
        at org.apache.calcite.rex.RexSimplify.residue(RexSimplify.java:1413)
        at 
org.apache.calcite.rex.RexSimplify.simplifyUsingPredicates(RexSimplify.java:1349)
        at 
org.apache.calcite.rex.RexSimplify.simplifyComparison(RexSimplify.java:366)
        at 
org.apache.calcite.rex.RexSimplify.simplifyComparison(RexSimplify.java:294)
        at org.apache.calcite.rex.RexSimplify.simplify(RexSimplify.java:285)
        at 
org.apache.calcite.rex.RexSimplify.simplifyAndTerms(RexSimplify.java:406)
        at org.apache.calcite.rex.RexSimplify.simplifyAnd(RexSimplify.java:1031)
        at org.apache.calcite.rex.RexSimplify.simplify(RexSimplify.java:257)
        at 
org.apache.calcite.rex.RexSimplify.lambda$simplifyUnknownAs$0(RexSimplify.java:232)
        at org.apache.calcite.rex.RexSimplify.verify(RexSimplify.java:1486)
        at 
org.apache.calcite.rex.RexSimplify.simplifyUnknownAs(RexSimplify.java:231)
        at 
org.apache.calcite.test.RexProgramTest.checkSimplify3_(RexProgramTest.java:182)
        at 
org.apache.calcite.test.RexProgramTest.checkSimplify2(RexProgramTest.java:157)
        at 
org.apache.calcite.test.RexProgramTest.testSimplifyAndNot(RexProgramTest.java:2415)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
        at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
        at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at 
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
        at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
        at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
        at 
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
        at 
com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
        at 
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
        at 
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
{noformat}

> 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