use of org.apache.ignite.cache.query.ScanQuery in project ignite by apache.
the class GridCacheQueryTransformerSelfTest method testLocalKeepBinaryFiltered.
/**
* @throws Exception If failed.
*/
public void testLocalKeepBinaryFiltered() throws Exception {
IgniteCache<Integer, Value> cache = grid().createCache("test-cache");
try {
for (int i = 0; i < 50; i++) cache.put(i, new Value("str" + i, i * 100));
Collection<List<Integer>> lists = grid().compute().broadcast(new IgniteCallable<List<Integer>>() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public List<Integer> call() throws Exception {
IgniteBiPredicate<Integer, BinaryObject> filter = new IgniteBiPredicate<Integer, BinaryObject>() {
@Override
public boolean apply(Integer k, BinaryObject v) {
return v.<Integer>field("idx") % 1000 == 0;
}
};
IgniteClosure<Cache.Entry<Integer, BinaryObject>, Integer> transformer = new IgniteClosure<Cache.Entry<Integer, BinaryObject>, Integer>() {
@Override
public Integer apply(Cache.Entry<Integer, BinaryObject> e) {
return e.getValue().field("idx");
}
};
return ignite.cache("test-cache").withKeepBinary().query(new ScanQuery<>(filter).setLocal(true), transformer).getAll();
}
});
List<Integer> res = new ArrayList<>(F.flatCollections(lists));
assertEquals(5, res.size());
Collections.sort(res);
for (int i = 0; i < 5; i++) assertEquals(i * 1000, res.get(i).intValue());
} finally {
cache.destroy();
}
}
use of org.apache.ignite.cache.query.ScanQuery in project ignite by apache.
the class GridCacheQueryTransformerSelfTest method testLocalKeepBinary.
/**
* @throws Exception If failed.
*/
public void testLocalKeepBinary() throws Exception {
IgniteCache<Integer, Value> cache = grid().createCache("test-cache");
try {
for (int i = 0; i < 50; i++) cache.put(i, new Value("str" + i, i * 100));
Collection<List<Integer>> lists = grid().compute().broadcast(new IgniteCallable<List<Integer>>() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public List<Integer> call() throws Exception {
IgniteClosure<Cache.Entry<Integer, BinaryObject>, Integer> transformer = new IgniteClosure<Cache.Entry<Integer, BinaryObject>, Integer>() {
@Override
public Integer apply(Cache.Entry<Integer, BinaryObject> e) {
return e.getValue().field("idx");
}
};
return ignite.cache("test-cache").withKeepBinary().query(new ScanQuery<Integer, BinaryObject>().setLocal(true), transformer).getAll();
}
});
List<Integer> res = new ArrayList<>(F.flatCollections(lists));
assertEquals(50, res.size());
Collections.sort(res);
for (int i = 0; i < 50; i++) assertEquals(i * 100, res.get(i).intValue());
} finally {
cache.destroy();
}
}
use of org.apache.ignite.cache.query.ScanQuery in project ignite by apache.
the class IgniteCacheQueryCacheDestroySelfTest method runQuery.
/**
* @throws Exception If failed.
*/
private void runQuery() throws Exception {
ScanQuery<String, String> scanQuery = new ScanQuery<String, String>().setLocal(true).setFilter(new IgniteBiPredicate<String, String>() {
@Override
public boolean apply(String key, String p) {
return key != null && key.isEmpty();
}
});
Ignite ignite = ignite(ThreadLocalRandom.current().nextInt(GRID_CNT));
IgniteCache<String, String> example = ignite.cache(CACHE_NAME);
for (int partition : ignite.affinity(CACHE_NAME).primaryPartitions(ignite.cluster().localNode())) {
scanQuery.setPartition(partition);
try (QueryCursor cursor = example.query(scanQuery)) {
for (Object p : cursor) {
String value = (String) ((Cache.Entry) p).getValue();
assertNotNull(value);
}
}
}
}
use of org.apache.ignite.cache.query.ScanQuery in project ignite by apache.
the class PlatformCache method readScanQuery.
/**
* Reads scan query.
*
* @param reader Binary reader.
* @return Query.
*/
private Query readScanQuery(BinaryRawReaderEx reader) {
boolean loc = reader.readBoolean();
final int pageSize = reader.readInt();
boolean hasPart = reader.readBoolean();
Integer part = hasPart ? reader.readInt() : null;
ScanQuery qry = new ScanQuery().setPageSize(pageSize);
qry.setPartition(part);
Object pred = reader.readObjectDetached();
if (pred != null)
qry.setFilter(platformCtx.createCacheEntryFilter(pred, 0));
qry.setLocal(loc);
return qry;
}
Aggregations