[
https://issues.apache.org/jira/browse/CALCITE-2745?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16723345#comment-16723345
]
Julian Hyde edited comment on CALCITE-2745 at 12/17/18 8:34 PM:
----------------------------------------------------------------
Remember that there are many things that are valid in SQL expressions that are
not valid in RexNode-land. SQL allows implicit conversions, but Rex does not.
In this case, it seems that Rex is missing a necessary cast. That would be the
fault of whoever built the Rex (probably SqlToRelConverter?).
Arguably we should also have better validation in Rex. But we don't want to
spend as much effort validating Rex as we do validating SQL, because we it is
not as important to be nice to developers as it is to be nice to end-users who
write SQL.
The second case, {{eq(vInt(1), literal("2"))}} is quite simply invalid. It is
not a fault in RexSimplify that it cannot handle such an expression.
was (Author: julianhyde):
Remember that there are many things that are valid in SQL expressions that are
not valid in RexNode-land. SQL allows implicit conversions, but Rex does not.
In this case, it seems that Rex is missing a necessary cast. That would be the
fault of whoever built the Rex (probably SqlToRelConverter?).
Arguably we should also have better validation in Rex. But we don't want to
spend as much effort validating Rex as we do validating SQL, because we it is
not as important to be nice to developers as it is to be nice to end-users who
write SQL.
> 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)