Vladsz83 commented on code in PR #9987:
URL: https://github.com/apache/ignite/pull/9987#discussion_r873137100


##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/LimitExecutionTest.java:
##########
@@ -48,6 +52,59 @@ public void testLimit() throws Exception {
         checkLimit(2000, 3000);
     }
 
+    /** Tests Sort node can limit its output when fetch param is set. */
+    @Test
+    public void testSortLimit() throws Exception {
+        int bufSize = U.field(AbstractNode.class, "IN_BUFFER_SIZE");
+
+        checkLimitSort(0, 1);
+        checkLimitSort(1, 0);
+        checkLimitSort(1, 1);
+        checkLimitSort(0, bufSize);
+        checkLimitSort(bufSize, 0);
+        checkLimitSort(bufSize, bufSize);
+        checkLimitSort(bufSize - 1, 1);
+        checkLimitSort(2000, 0);
+        checkLimitSort(0, 3000);
+        checkLimitSort(2000, 3000);
+    }
+
+    /**
+     * @param offset Rows offset.
+     * @param fetch Fetch rows count (zero means unlimited).
+     */
+    private void checkLimitSort(int offset, int fetch) {
+        assert offset >= 0;
+        assert fetch >= 0;
+
+        ExecutionContext<Object[]> ctx = executionContext(F.first(nodes()), 
UUID.randomUUID(), 0);
+        IgniteTypeFactory tf = ctx.getTypeFactory();
+        RelDataType rowType = TypeUtils.createRowType(tf, int.class);
+
+        RootNode<Object[]> rootNode = new RootNode<>(ctx, rowType);
+
+        SortNode<Object[]> sortNode = new SortNode<>(ctx, rowType, 
F::compareArrays, () -> offset,
+            fetch == 0 ? null : () -> fetch);
+
+        List<Object[]> data = IntStream.range(0, SourceNode.IN_BUFFER_SIZE + 
fetch + offset).boxed()
+            .map(i -> new Object[] {i}).collect(Collectors.toList());
+        Collections.shuffle(data);
+
+        ScanNode<Object[]> srcNode = new ScanNode<>(ctx, rowType, data);
+
+        rootNode.register(sortNode);
+
+        sortNode.register(srcNode);
+
+        for (int i = 0; i < offset + fetch; i++) {
+            assertTrue(rootNode.hasNext());
+            assertEquals(i, rootNode.next()[0]);
+        }
+
+        if (fetch > 0)
+            assertFalse(rootNode.hasNext());

Review Comment:
   Fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to