/** * Tests offset and limit clauses for query. * * @throws Exception If failed. */ public void testOffsetLimit() throws Exception { IgniteCache<Integer, Integer> c = ignite(0).getOrCreateCache(cacheConfig("ints", true, Integer.class, Integer.class)); try { List<Integer> res = new ArrayList<>(); Random rnd = new GridRandom(); for (int i = 0; i < 10; i++) { int val = rnd.nextInt(100); c.put(i, val); res.add(val); } Collections.sort(res); String qry = "select _val from Integer order by _val "; assertEqualsCollections(res, columnQuery(c, qry)); assertEqualsCollections(res.subList(0, 0), columnQuery(c, qry + "limit ?", 0)); assertEqualsCollections(res.subList(0, 3), columnQuery(c, qry + "limit ?", 3)); assertEqualsCollections(res.subList(0, 9), columnQuery(c, qry + "limit ? offset ?", 9, 0)); assertEqualsCollections(res.subList(3, 7), columnQuery(c, qry + "limit ? offset ?", 4, 3)); assertEqualsCollections(res.subList(7, 9), columnQuery(c, qry + "limit ? offset ?", 2, 7)); assertEqualsCollections(res.subList(8, 10), columnQuery(c, qry + "limit ? offset ?", 2, 8)); assertEqualsCollections(res.subList(9, 10), columnQuery(c, qry + "limit ? offset ?", 1, 9)); assertEqualsCollections(res.subList(10, 10), columnQuery(c, qry + "limit ? offset ?", 1, 10)); assertEqualsCollections( res.subList(9, 10), columnQuery(c, qry + "limit ? offset abs(-(4 + ?))", 1, 5)); } finally { c.destroy(); } }