Skip to content

Commit 15380a5

Browse files
IGNITE-29191 Fix local IndexQuery ignoring setLimit() (#13735)
1 parent 061f0bc commit 15380a5

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

‎modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,13 +1156,20 @@ public GridCloseableIterator indexQueryLocal(final CacheQuery qry) throws Ignite
11561156
GridCloseableIterator<IgniteBiTuple<K, V>> iter = idxQryRes.iter();
11571157

11581158
return new GridCloseableIteratorAdapter() {
1159+
/** */
1160+
private int cnt;
1161+
11591162
@Override protected Object onNext() throws IgniteCheckedException {
11601163
IgniteBiTuple<K, V> entry = iter.nextX();
1164+
cnt++;
11611165

11621166
return new CacheEntryImpl<>(entry.getKey(), entry.getValue());
11631167
}
11641168

11651169
@Override protected boolean onHasNext() throws IgniteCheckedException {
1170+
if (qry.limit() > 0 && qry.limit() <= cnt)
1171+
return false;
1172+
11661173
return iter.hasNextX();
11671174
}
11681175
};

‎modules/indexing/src/test/java/org/apache/ignite/cache/query/IndexQueryLimitTest.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ public void testSetLimit() {
108108
assertEquals(limit, qry.getLimit());
109109
}
110110

111+
/** */
112+
@Test
113+
public void testLocalQueryLimit() {
114+
insertData(1);
115+
116+
IndexQuery<Long, Person> qry = new IndexQuery<Long, Person>(Person.class, IDX).setLimit(3);
117+
118+
qry.setLocal(true);
119+
120+
assertEquals(3, crd.cache(CACHE).query(qry).getAll().size());
121+
}
122+
111123
/** */
112124
private void checkRangeQueries(int duplicates) throws Exception {
113125
// Add data

0 commit comments

Comments
 (0)