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/06/03 05:36:00 UTC

[jira] [Comment Edited] (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=17728586#comment-17728586 ] 

Julian Hyde edited comment on CALCITE-5730 at 6/3/23 5:35 AM:
--------------------------------------------------------------

Fixed via [{{e34caf70}}|https://github.com/apache/calcite/commit/e34caf70ac97996035b8fd8fc494a64022b07f91]

Thanks [~gf2121] for the patch!


was (Author: rubenql):
Fixed via [{{295df90}}|https://github.com/apache/calcite/commit/295df907d126ffa059756e2e0cc8b69051ff6da7]

Thanks [~gf2121] for the patch!

> 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)