[
https://issues.apache.org/jira/browse/CALCITE-6617?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17887381#comment-17887381
]
Claude Brisson commented on CALCITE-6617:
-----------------------------------------
I found another place that has the same problem, during rex expressions
simplification: for the query below, the ReduceExpressionsRule optimizer builds
a tree map of ranges, and tries to insert into it both BigDecimals and Doubles,
leading to a ClassCastException.
{code:java}
SELECT * FROM (SELECT 1 ROUND(RANDOM()) AS A) WHERE A BETWEEN 1 AND 10 OR A
IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) {code}
Stack trace:
{code:java}
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:360)
at com.google.common.collect.Range.compareOrThrow(Range.java:702)
at com.google.common.collect.Cut.compareTo(Cut.java:81)
at com.google.common.collect.Cut$BelowValue.compareTo(Cut.java:315)
at java.base/java.util.TreeMap.compare(TreeMap.java:1606)
at java.base/java.util.TreeMap.getLowerEntry(TreeMap.java:527)
at java.base/java.util.TreeMap.lowerEntry(TreeMap.java:1012)
at com.google.common.collect.TreeRangeSet.add(TreeRangeSet.java:191)
at
org.apache.calcite.rex.RexSimplify$RexSargBuilder.addRange(RexSimplify.java:3186)
at
org.apache.calcite.rex.RexSimplify$SargCollector.accept2b(RexSimplify.java:3034)
at
org.apache.calcite.rex.RexSimplify$SargCollector.accept2(RexSimplify.java:2960)
at
org.apache.calcite.rex.RexSimplify$SargCollector.accept_(RexSimplify.java:2941)
at
org.apache.calcite.rex.RexSimplify$SargCollector.accept(RexSimplify.java:2926)
at
org.apache.calcite.rex.RexSimplify$SargCollector.access$500(RexSimplify.java:2909)
at
org.apache.calcite.rex.RexSimplify.lambda$simplifyOrs$7(RexSimplify.java:2002)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)
at org.apache.calcite.rex.RexSimplify.simplifyOrs(RexSimplify.java:2002)
at org.apache.calcite.rex.RexSimplify.simplifyOr(RexSimplify.java:1979)
at org.apache.calcite.rex.RexSimplify.simplify(RexSimplify.java:284)
at
org.apache.calcite.rex.RexSimplify.simplifyUnknownAs(RexSimplify.java:251)
at
org.apache.calcite.rex.RexSimplify.simplifyPreservingType(RexSimplify.java:190)
at
org.apache.calcite.rel.rules.ReduceExpressionsRule.reduceExpressions(ReduceExpressionsRule.java:720)
at
org.apache.calcite.rel.rules.ReduceExpressionsRule$FilterReduceExpressionsRule.onMatch(ReduceExpressionsRule.java:157)
at
org.apache.calcite.plan.AbstractRelOptPlanner.fireRule(AbstractRelOptPlanner.java:336)
at org.apache.calcite.plan.hep.HepPlanner.applyRule(HepPlanner.java:556)
at org.apache.calcite.plan.hep.HepPlanner.applyRules(HepPlanner.java:420)
at
org.apache.calcite.plan.hep.HepPlanner.executeEndGroup(HepPlanner.java:360)
at
org.apache.calcite.plan.hep.HepInstruction$EndGroup$State.execute(HepInstruction.java:349)
at
org.apache.calcite.plan.hep.HepPlanner.lambda$executeProgram$0(HepPlanner.java:211)
at com.google.common.collect.ImmutableList.forEach(ImmutableList.java:423)
at
org.apache.calcite.plan.hep.HepPlanner.executeProgram(HepPlanner.java:210)
at org.apache.calcite.plan.hep.HepProgram$State.execute(HepProgram.java:118)
at
org.apache.calcite.plan.hep.HepPlanner.executeProgram(HepPlanner.java:205)
at org.apache.calcite.plan.hep.HepPlanner.findBestExp(HepPlanner.java:191)
{code}
> Regression after CALCITE-2067 which gives a ClassCastException
> --------------------------------------------------------------
>
> Key: CALCITE-6617
> URL: https://issues.apache.org/jira/browse/CALCITE-6617
> Project: Calcite
> Issue Type: Bug
> Components: core
> Reporter: Claude Brisson
> Priority: Blocker
> Fix For: 1.38.0
>
>
> The following statement:
> {code:java}
> SELECT * FROM (VALUES (1, 2, 3), (5E0::REAL, 5E0, NULL)) AS foo {code}
> will provoke a ClassCastException between a Double and a BigDecimal, while it
> was working in 1.37.0.
> It's due to the fact that when trying to infer a collation on a Values
> tuples, the comparator still assumes that all numbers are of the same class,
> which changed with CALCITE-2067.
> Here is the full stack trace:
>
> {code:java}
> Caused by: java.lang.ClassCastException: class java.lang.Double cannot be
> cast to class java.math.BigDecimal (java.lang.Double and java.math.BigDecimal
> are in module java.base of loader 'bootstrap')
> at java.base/java.math.BigDecimal.compareTo(BigDecimal.java:330)
> at
> org.apache.calcite.rel.RelFieldCollation.compare(RelFieldCollation.java:45)
> at
> org.apache.calcite.rel.metadata.RelMdCollation$1.compare(RelMdCollation.java:458)
> at
> org.apache.calcite.rel.metadata.RelMdCollation$1.compare(RelMdCollation.java:454)
> at com.google.common.collect.Ordering.isOrdered(Ordering.java:910)
> at
> org.apache.calcite.rel.metadata.RelMdCollation.values(RelMdCollation.java:434)
> at
> org.apache.calcite.rel.logical.LogicalValues.lambda$create$0(LogicalValues.java:111)
> at org.apache.calcite.plan.RelTraitSet.replaceIfs(RelTraitSet.java:246)
> at
> org.apache.calcite.rel.logical.LogicalValues.create(LogicalValues.java:110)
> at
> org.apache.calcite.rel.core.RelFactories$ValuesFactoryImpl.createValues(RelFactories.java:521)
> at org.apache.calcite.tools.RelBuilder.values(RelBuilder.java:3497)
> at org.apache.calcite.tools.RelBuilder.setOp(RelBuilder.java:2924)
> at org.apache.calcite.tools.RelBuilder.union(RelBuilder.java:2946)
> at
> org.apache.calcite.sql2rel.SqlToRelConverter.convertValuesImpl(SqlToRelConverter.java:5050)
> at
> org.apache.calcite.sql2rel.SqlToRelConverter.convertFrom(SqlToRelConverter.java:2488)
> at
> org.apache.calcite.sql2rel.SqlToRelConverter.convertFrom(SqlToRelConverter.java:2393)
> at
> org.apache.calcite.sql2rel.SqlToRelConverter.convertFrom(SqlToRelConverter.java:2355)
> at
> org.apache.calcite.sql2rel.SqlToRelConverter.convertSelectImpl(SqlToRelConverter.java:754)
> at
> org.apache.calcite.sql2rel.SqlToRelConverter.convertSelect(SqlToRelConverter.java:734)
> at
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQueryRecursive(SqlToRelConverter.java:3905)
> at
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:627)
> {code}
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)