You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ignite.apache.org by "Stanislav Lukyanov (JIRA)" <ji...@apache.org> on 2018/03/09 13:10:00 UTC

[jira] [Created] (IGNITE-7908) NULLS LAST works incorrectly for PARTITIONED caches

Stanislav Lukyanov created IGNITE-7908:
------------------------------------------

             Summary: NULLS LAST works incorrectly for PARTITIONED caches
                 Key: IGNITE-7908
                 URL: https://issues.apache.org/jira/browse/IGNITE-7908
             Project: Ignite
          Issue Type: Bug
          Components: sql
            Reporter: Stanislav Lukyanov


When a `SELECT .... ORDER BY ... NULLS LAST` query is executed on a partitioned cache, the null values at the end of the result are interleaved with non-null values. 
It seems that for each node participating in the query all null values that are stored on that node are returned immediately after the last non-null value. As a result, non-null values are correctly ordered and null values appear in a few "portions" (the number of "portions" is equal to the number of nodes) among the last values.

Example:
 ====================
{code:java}
public class NullsLastBug {
    public static void main(String[] args) throws Exception {
        try (
            Ignite srv1 = IgnitionEx.start("examples/config/example-ignite.xml", "server-1");
            Ignite srv2 = IgnitionEx.start("examples/config/example-ignite.xml", "server-2");
            Ignite srv3 = IgnitionEx.start("examples/config/example-ignite.xml", "server-3")
        ) {
            Ignition.setClientMode(true);
            try (Ignite client = IgnitionEx.start("examples/config/example-ignite.xml", "client")) {
                IgniteCache<Long, Box> cache = client.getOrCreateCache(
                    new CacheConfiguration<Long, Box>("cache")
                        .setCacheMode(CacheMode.PARTITIONED)
                        .setIndexedTypes(Long.class, Box.class)
                );

                for (long i = 0; i < 30; i++) {
                    Long num = (i % 2 != 0) ? i : null;
                    cache.put(i, new Box(num));
                }

                SqlFieldsQuery selectAll = new SqlFieldsQuery("SELECT num FROM Box ORDER BY num NULLS LAST");
                for (List<?> list : cache.query(selectAll))
                    System.out.println(list);
            }
        }
    }
}

class Box implements Serializable {
    @QuerySqlField(index = true) private Long num;

    Box(Long num) {
        this.num = num;
    }
}
{code}
 ====================

Output:
 ====================
{code}
 [1]
 [3]
 [5]
 [7]
 [9]
 [11]
 [13]
 [15]
 [17]
 [19]
 [21]
 [23]
 [null]
 [null]
 [25]
 [27]
 [null]
 [null]
 [null]
 [null]
 [null]
 [null]
 [null]
 [null]
 [29]
 [null]
 [null]
 [null]
 [null]
 [null]
{code}
 ====================



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)