Vladimir Sitnikov created CALCITE-7877:
------------------------------------------

             Summary: EnumerableDefaults.asOrderedQueryable throws 
NullPointerException for any Enumerable that is not already an OrderedQueryable
                 Key: CALCITE-7877
                 URL: https://issues.apache.org/jira/browse/CALCITE-7877
             Project: Calcite
          Issue Type: Bug
          Components: linq4j
    Affects Versions: 1.42.0
            Reporter: Vladimir Sitnikov


Calling {{EnumerableDefaults.asOrderedQueryable(source)}} with an 
{{Enumerable}} that is not an {{OrderedQueryable}} throws 
{{NullPointerException}} instead of returning a queryable over {{source}}.

{code:java}
EnumerableDefaults.asOrderedQueryable(Linq4j.asEnumerable(java.util.Arrays.asList(1,
 2)));
{code}

On main ({{6ff13eaccd}}, 1.43.0-SNAPSHOT), in jshell with 
{{linq4j/build/classes/java/main}} on the class path:

{noformat}
|  Exception java.lang.NullPointerException: null
|        at Objects.requireNonNull (Objects.java:259)
|        at EnumerableDefaults.asOrderedQueryable (EnumerableDefaults.java:4507)
{noformat}

The same exception fails a SQL query against a {{QueryableTable}} whose 
{{asQueryable}} returns {{EnumerableDefaults.asOrderedQueryable(enumerable)}}:

{noformat}
java.sql.SQLException: Error while executing SQL "select max("ts"), min("tm"), 
max("dt") from T": null
  ...
Caused by: java.lang.NullPointerException: null
  at java.base/java.util.Objects.requireNonNull(Objects.java:259)
  at 
org.apache.calcite.linq4j.EnumerableDefaults.asOrderedQueryable(EnumerableDefaults.java:4507)
  at <the table's asQueryable>
  at org.apache.calcite.schema.Schemas.queryable(Schemas.java:256)
{noformat}

The method passes {{requireNonNull(null, "null")}} as the {{QueryProvider}} 
argument of {{EnumerableOrderedQueryable}}, so it cannot succeed for any input 
that takes that branch. All four {{EnumerableQueryable.orderBy}} and 
{{orderByDescending}} overloads pass it the result of 
{{EnumerableDefaults.orderBy}} or {{orderByDescending}}, which is a plain 
{{AbstractEnumerable}}, so they always throw too.

Expected: the call returns an {{OrderedQueryable}} that enumerates {{1, 2}}, as 
it did up to 1.26.0, where the provider argument was {{null}}. The 
{{requireNonNull(null)}} came in with CALCITE-4199 (1.27.0), and CALCITE-4431 
only added the message.

Found while checking PR 971 (CALCITE-1703), whose test table uses this method.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to