[
https://issues.apache.org/jira/browse/CALCITE-6376?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17841036#comment-17841036
]
ShenDa commented on CALCITE-6376:
---------------------------------
The problem encountered is due to the fact that when there are six or fewer
elements, Calcite creates a collection called Flat6List, which implements its
own compareTo method, thereby sidestepping the requirement that the elements
must be Comparable.
In your case, you have exactly seven columns queried, exceeding the limit of
six, so it uses ComparableListImpl, which ultimately leads to this issue in
your sample.
I can now submit a PR to help resolve the problem you're currently facing.
> Filtering CTE of at least 6 columns with QUALIFY operation results in
> exception
> -------------------------------------------------------------------------------
>
> Key: CALCITE-6376
> URL: https://issues.apache.org/jira/browse/CALCITE-6376
> Project: Calcite
> Issue Type: Bug
> Affects Versions: 1.36.0
> Reporter: Austin Richardson
> Priority: Major
>
> Example query:
>
> {code:java}
> WITH MyCTE AS (
> SELECT
> column1,
> column2,
> column3,
> column4,
> column5,
> column6
> FROM (
> VALUES
> ('value1', 10, 5.0, 'data1', 'info1', 'test1'),
> ('value2', 20, 4.0, 'data2', 'info2', 'test2'),
> ('value3', 30, 3.0, 'data3', 'info3', 'test3'),
> ('value4', 40, 2.0, 'data4', 'info4', 'test4'),
> ('value5', 50, 1.0, 'data5', 'info5', 'test5')
> ) AS t(column1, column2, column3, column4, column5, column6)
> )
> SELECT *
> FROM MyCTE
> QUALIFY RANK() OVER (ORDER BY column3) = 1{code}
>
> And exception snippet:
>
> {code:java}
> Caused by: java.lang.ClassCastException: class
> org.apache.calcite.rex.RexInputRef cannot be cast to class
> java.lang.Comparable (org.apache.calcite.rex.RexInputRef is in unnamed module
> of loader org.springframework.boot.loader.LaunchedURLClassLoader @257f30f7;
> java.lang.Comparable is in module java.base of loader 'bootstrap')
> at
> org.apache.calcite.runtime.FlatLists$ComparableListImpl.get(FlatLists.java:1319)
> at
> org.apache.calcite.runtime.FlatLists$ComparableListImpl.get(FlatLists.java:1309)
> at
> java.base/java.util.AbstractList$Itr.next(AbstractList.java:373){code}
>
> Either removing one of the columns or the QUALIFY filter results in a
> successful query.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)