use of org.apache.ignite.cache.query.QueryCursor in project ignite by apache.
the class BaseSqlTest method select.
/**
* Performs scan query with custom transformer (mapper).
*
* @param cache cache to query.
* @param filter filter for rows.
* @param transformer result mapper.
*/
@SuppressWarnings("unchecked")
protected static <K, V, R> List<R> select(IgniteCache<K, V> cache, @Nullable IgnitePredicate<Map<String, Object>> filter, IgniteClosure<Map<String, Object>, R> transformer) {
Collection<QueryEntity> entities = cache.getConfiguration(CacheConfiguration.class).getQueryEntities();
assert entities.size() == 1 : "Cache should contain exactly one table";
final QueryEntity meta = entities.iterator().next();
IgniteClosure<Cache.Entry<K, V>, R> transformerAdapter = entry -> {
Map<String, Object> row = entryToMap(meta, entry.getKey(), entry.getValue());
return transformer.apply(row);
};
IgniteBiPredicate<K, V> filterAdapter = (filter == null) ? null : (key, val) -> filter.apply(entryToMap(meta, key, val));
QueryCursor<R> cursor = cache.withKeepBinary().query(new ScanQuery<>(filterAdapter), transformerAdapter);
return cursor.getAll();
}
use of org.apache.ignite.cache.query.QueryCursor in project ignite by apache.
the class KillCommandsTests method checkScanQueryCancelDuringFetching.
/**
* Checks cancel of the scan query during fetching.
*
* @param cli Client node.
* @param srvs Server nodes.
* @param qryCanceler Query cancel closure.
*/
private static void checkScanQueryCancelDuringFetching(IgniteEx cli, List<IgniteEx> srvs, Consumer<T3<UUID, String, Long>> qryCanceler) throws Exception {
filterLatch = new CountDownLatch(1);
cancelLatch = new CountDownLatch(1);
IgniteCache<Object, Object> cache = cli.cache(DEFAULT_CACHE_NAME);
QueryCursor<Cache.Entry<Object, Object>> qry = cache.query(new ScanQuery<>().setFilter((o, o2) -> {
try {
filterLatch.countDown();
cancelLatch.await(TIMEOUT, TimeUnit.MILLISECONDS);
} catch (Exception ignored) {
// No-op.
}
return true;
}));
IgniteInternalFuture<?> fut = GridTestUtils.runAsync((Runnable) () -> qry.iterator().next());
assertTrue(filterLatch.await(TIMEOUT, TimeUnit.MILLISECONDS));
T3<UUID, String, Long> qryInfo = scanQuery(srvs.get(0));
qryCanceler.accept(qryInfo);
cancelLatch.countDown();
assertThrowsAnyCause(null, fut::get, NoSuchElementException.class, "Iterator has been closed.");
checkScanQueryResources(cli, srvs, qryInfo.get3());
}
Aggregations