Ruben Q L created CALCITE-6089: ---------------------------------- Summary: EnumerableSortedAggregate fails with ClassCastException: class X cannot be cast to class org.apache.calcite.runtime.FlatLists$ComparableList Key: CALCITE-6089 URL: https://issues.apache.org/jira/browse/CALCITE-6089 Project: Calcite Issue Type: Bug Components: core Affects Versions: 1.35.0 Reporter: Ruben Q L
The problem can be reproduced with this test (to be added e.g. into {{EnumerableSortedAggregateTest.java}}): {code} @Test void sortedAggCountUnion() { tester(false, new HrSchema()) .query( "select count(*) as c from ( " + "select * from emps where deptno=10 " + "union all " + "select * from emps where deptno=20)") .withHook(Hook.PLANNER, (Consumer<RelOptPlanner>) planner -> { planner.removeRule(EnumerableRules.ENUMERABLE_AGGREGATE_RULE); planner.addRule(EnumerableRules.ENUMERABLE_SORTED_AGGREGATE_RULE); }) .explainContains( "EnumerableSortedAggregate(group=[{}], c=[COUNT()])\n" + " EnumerableUnion(all=[true])\n" + " EnumerableCalc(expr#0..4=[{inputs}], expr#5=[CAST($t1):INTEGER NOT NULL], expr#6=[10], expr#7=[=($t5, $t6)], commission=[$t4], $condition=[$t7])\n" + " EnumerableTableScan(table=[[s, emps]])\n" + " EnumerableCalc(expr#0..4=[{inputs}], expr#5=[CAST($t1):INTEGER NOT NULL], expr#6=[20], expr#7=[=($t5, $t6)], commission=[$t4], $condition=[$t7])\n" + " EnumerableTableScan(table=[[s, emps]])") .returnsOrdered( "c=4"); } {code} Which fails with: {noformat} ... Caused by: java.lang.ClassCastException: class java.lang.Integer cannot be cast to class org.apache.calcite.runtime.FlatLists$ComparableList (java.lang.Integer is in module java.base of loader 'bootstrap'; org.apache.calcite.runtime.FlatLists$ComparableList is in unnamed module of loader 'app') at Baz$6.compare(Unknown Source) at org.apache.calcite.linq4j.EnumerableDefaults$SortedAggregateEnumerator.moveNext(EnumerableDefaults.java:938) at org.apache.calcite.linq4j.Linq4j$EnumeratorIterator.<init>(Linq4j.java:679) at org.apache.calcite.linq4j.Linq4j.enumeratorIterator(Linq4j.java:97) ... {noformat} The same test with EnumerableAggregate (instead of EnumerableSortedAggregate) will execute the query correctly. -- This message was sent by Atlassian Jira (v8.20.10#820010)