[
https://issues.apache.org/jira/browse/CALCITE-7201?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
ASF GitHub Bot updated CALCITE-7201:
------------------------------------
Labels: pull-request-available (was: )
> ClassCastException in RexInterpreter#search with different NUMERIC values
> -------------------------------------------------------------------------
>
> Key: CALCITE-7201
> URL: https://issues.apache.org/jira/browse/CALCITE-7201
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.40.0
> Reporter: Stamatis Zampetakis
> Assignee: Stamatis Zampetakis
> Priority: Major
> Labels: pull-request-available
>
> {{RexInterpreter}} throws {{ClassCastException}} when evaluating {{SEARCH}}
> calls with NUMERIC arguments that don't have the same Class in their runtime
> representation. The most vivid example is when we compare approximate
> numerics with exact numerics.
> +Example+
> {code:sql}
> SELECT 10035e-2 IN (100, 200) AS foo;
> {code}
> The approximate numerics are internally represented using Double while exact
> numerics are represented using BigDecimal. The easiest way to reproduce the
> problem is through the simplifier which internally calls the interpreter.
> The following test can be added in {{{}RexProgramTest{}}}:
> {code:java}
> @Test void testSimplifySearch() {
> RexNode d100_35 = rexBuilder.makeApproxLiteral(100.35,
> typeFactory.createSqlType(SqlTypeName.DOUBLE));
> RexNode d100 = rexBuilder.makeExactLiteral(BigDecimal.valueOf(100),
> typeFactory.createSqlType(SqlTypeName.INTEGER));
> RexNode d200 = rexBuilder.makeExactLiteral(BigDecimal.valueOf(200),
> typeFactory.createSqlType(SqlTypeName.INTEGER));
> checkSimplify(rexBuilder.makeIn(d100_35, Arrays.asList(d100, d200)),"");
> }
> {code}
> {noformat}
> class java.math.BigDecimal cannot be cast to class java.lang.Double
> (java.math.BigDecimal and java.lang.Double are in module java.base of loader
> 'bootstrap')
> java.lang.ClassCastException: class java.math.BigDecimal cannot be cast to
> class java.lang.Double (java.math.BigDecimal and java.lang.Double are in
> module java.base of loader 'bootstrap')
> at java.base/java.lang.Double.compareTo(Double.java:216)
> at com.google.common.collect.Range.compareOrThrow(Range.java:715)
> at com.google.common.collect.Cut.compareTo(Cut.java:79)
> at com.google.common.collect.Cut$BelowValue.compareTo(Cut.java:313)
> at
> com.google.common.collect.NaturalOrdering.compare(NaturalOrdering.java:42)
> at
> com.google.common.collect.NaturalOrdering.compare(NaturalOrdering.java:29)
> at
> com.google.common.collect.SortedLists.binarySearch(SortedLists.java:291)
> at
> com.google.common.collect.SortedLists.binarySearch(SortedLists.java:244)
> at
> com.google.common.collect.ImmutableRangeSet.rangeContaining(ImmutableRangeSet.java:197)
> at
> com.google.common.collect.AbstractRangeSet.contains(AbstractRangeSet.java:32)
> at
> com.google.common.collect.ImmutableRangeSet.contains(ImmutableRangeSet.java:54)
> at org.apache.calcite.rex.RexInterpreter.search(RexInterpreter.java:319)
> at
> org.apache.calcite.rex.RexInterpreter.visitCall(RexInterpreter.java:246)
> at
> org.apache.calcite.rex.RexInterpreter.visitCall(RexInterpreter.java:58)
> at org.apache.calcite.rex.RexCall.accept(RexCall.java:208)
> at
> org.apache.calcite.rex.RexInterpreter.evaluate(RexInterpreter.java:91)
> at org.apache.calcite.rex.RexSimplify.verify(RexSimplify.java:2300)
> at
> org.apache.calcite.rex.RexSimplify.simplifyUnknownAs(RexSimplify.java:255)
> at
> org.apache.calcite.rex.RexProgramTestBase.checkSimplifyAs(RexProgramTestBase.java:147)
> at
> org.apache.calcite.rex.RexProgramTestBase.checkSimplify3_(RexProgramTestBase.java:131)
> at
> org.apache.calcite.rex.RexProgramTestBase.checkSimplify(RexProgramTestBase.java:90)
> at
> org.apache.calcite.rex.RexProgramTest.testSimplifySearch(RexProgramTest.java:853)
> {noformat}
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)