Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
None
-
None
-
None
-
None
Description
RexSimplify fails with ClassCastException when the expression contains predicates with comparisons of operands with different types.
Test to reproduce this issue (placed into JdbcAdapterTest):
@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"); }
It fails with the error:
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
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:
8.2 <comparison predicate> Syntax Rules
3) The declared types of the corresponding fields of the two <row value predicand>s shall be comparable.
But it also allows implicit casts from numeric types to chars (6.13 <cast specification>).
Attachments
Issue Links
- is related to
-
CALCITE-2302 Implicit type cast support
- Closed
- relates to
-
DRILL-6905 ClassCastException happens when combining filters with numeric and varchar literals
- Resolved