Zhen Chen created CALCITE-7367:
----------------------------------
Summary: NULLS FIRST throws ClassCastException when sorting arrays
Key: CALCITE-7367
URL: https://issues.apache.org/jira/browse/CALCITE-7367
Project: Calcite
Issue Type: Bug
Components: core
Affects Versions: 1.41.0
Reporter: Zhen Chen
Assignee: Zhen Chen
Fix For: 1.42.0
The following SQL statement should produce the following result, but it will
throw an error when executed. NULLS LAST works normally, but NULLS FIRST will
throw an error.
{code:java}
select * from
(values
(2, array[null, 3]),
(3, array[3, 4]),
(1, array[1, 2]),
(4, array[4, 5]),
(5, cast(null as integer array))) as t(id, arr)
order by arr nulls first;
+----+-----------+
| ID | ARR |
+----+-----------+
| 5 | |
| 1 | [1, 2] |
| 3 | [3, 4] |
| 4 | [4, 5] |
| 2 | [null, 3] |
+----+-----------+
(5 rows)
!ok {code}
Error message:
> Caused by: java.lang.ClassCastException: class java.util.ArrayList cannot be
> cast to class java.lang.Comparable (java.util.ArrayList and
> java.lang.Comparable are in module java.base of loader 'bootstrap')
> at
> org.apache.calcite.linq4j.function.Functions$NullsFirstComparator.compare(Functions.java:539)
> at java.base/java.util.TreeMap.compare(TreeMap.java:1570)
> at java.base/java.util.TreeMap.addEntryToEmptyMap(TreeMap.java:776)
> at java.base/java.util.TreeMap.put(TreeMap.java:785)
> at java.base/java.util.TreeMap.put(TreeMap.java:534)
> at
> org.apache.calcite.linq4j.EnumerableDefaults.toLookup_(EnumerableDefaults.java:3818)
> at
> org.apache.calcite.linq4j.EnumerableDefaults$15.enumerator(EnumerableDefaults.java:2857)
> at
> org.apache.calcite.linq4j.AbstractEnumerable.iterator(AbstractEnumerable.java:33)
> at org.apache.calcite.avatica.MetaImpl.createCursor(MetaImpl.java:91)
> at
> org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:186)
> at
> org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:64)
> at
> org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:43)
> at
> org.apache.calcite.avatica.AvaticaConnection$1.execute(AvaticaConnection.java:669)
> at
> org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:669)
> at
> org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:677)
> at
> org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:157)
--
This message was sent by Atlassian Jira
(v8.20.10#820010)