You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (Jira)" <ji...@apache.org> on 2023/05/31 00:39:00 UTC

[jira] [Commented] (CALCITE-5730) Initial null values can be dropped by EnumerableLimitSort with offset

    [ https://issues.apache.org/jira/browse/CALCITE-5730?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17727738#comment-17727738 ] 

Julian Hyde commented on CALCITE-5730:
--------------------------------------

A test case (a chunk of java code added to Calcite's test suite) is definitely required in the PR, but when the bug is logged it's useful to have a simple SQL query that illustrates the problem. And a statement about what's wrong: "The query returns 3 rows but should only return 2 because ...". That's what I meant by "test case", but I didn't explain myself very well.

> Initial null values can be dropped by EnumerableLimitSort with offset
> ---------------------------------------------------------------------
>
>                 Key: CALCITE-5730
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5730
>             Project: Calcite
>          Issue Type: Bug
>          Components: linq4j
>            Reporter: Feng Guo
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.35.0
>
>
> *Description*
> The EnumerableSortLimit Node deals with offset with following logic:
> {code:java}
> // skip the first 'offset' rows by deleting them from the map
> if (offset > 0) {
>   // search the key up to (but excluding) which we have to remove entries from the map
>   int skipped = 0;
>   TKey until = null;
>   for (Map.Entry<TKey, List<TSource>> e : map.entrySet()) {
>     skipped += e.getValue().size();
>     if (skipped > offset) {
>       // we might need to remove entries from the list
>       List<TSource> l = e.getValue();
>       int toKeep = skipped - offset;
>       if (toKeep < l.size()) {
>         l.subList(0, l.size() - toKeep).clear();
>       }
>       until = e.getKey();
>       break;
>     }
>   }
>   if (until == null) {
>     // the offset is bigger than the number of rows in the map
>     return Linq4j.emptyEnumerator();
>   }
>   map.headMap(until, false).clear();
> }
> {code}
>  In a NULLS FIRST sort, if we set offset=1, limit = 1 when first 10 rows have null compare key, the until will be null. But that does not mean offset bigger than number of rows, it should have results instead of emptyEnumerator;



--
This message was sent by Atlassian Jira
(v8.20.10#820010)