git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[jira] [Created] (CALCITE-2745) RexSimplify fails with ClassCastException when the expression contains comparisons of operands with different types


Volodymyr Vysotskyi created CALCITE-2745:
--------------------------------------------

             Summary: 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


{{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)