/** * Create scan query with filter. * * @param part Partition. * @param filter Filter. If {@code null} then all entries will be returned. */ public ScanQuery(@Nullable Integer part, @Nullable IgniteBiPredicate<K, V> filter) { setPartition(part); setFilter(filter); }
/** * Queries the specified cache using the specified filter. * * @param upstreamCache Ignite cache with {@code upstream} data. * @param filter Filter for {@code upstream} data. If {@code null} then all entries will be returned. * @return Query cursor. */ private QueryCursor<Cache.Entry<K, V>> query(IgniteCache<K, V> upstreamCache, IgniteBiPredicate<K, V> filter) { ScanQuery<K, V> qry = new ScanQuery<>(); if (filter != null) // This section was added to keep code correct of qry.setFilter(null) behaviour will changed. qry.setFilter(filter); return upstreamCache.query(qry); }
@Override public List<Person> applyx(CountDownLatch startLatch, CountDownLatch endLatch2) throws IgniteCheckedException { IgniteBiPredicate<Integer, Person> f = new IgniteBiPredicate<Integer, Person>() { @Override public boolean apply(Integer k, Person v) { return k % 2 == 0; } }; try (QueryCursor<Cache.Entry<Integer, Person>> cur = cache().query(new ScanQuery<Integer, Person>() .setFilter(f))) { Iterator<Cache.Entry<Integer, Person>> it = cur.iterator(); List<Cache.Entry<Integer, Person>> pres = new ArrayList<>(); for (int i = 0; i < 50; i++) pres.add(it.next()); if (startLatch != null) startLatch.countDown(); while (it.hasNext()) pres.add(it.next()); if (endLatch2 != null) U.await(endLatch2); return entriesToPersons(pres); } } };
.setFilter((i, s) -> i >= rangeStart && i < rangeEnd);
/** * 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; }
qry.setLocal(true); qry.setPartition(part); qry.setFilter(filter);
qry.setLocal(true); qry.setPartition(part); qry.setFilter(filter);
/** * @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); } } } }
/** {@inheritDoc} */ @Override public ClientResponse process(ClientConnectionContext ctx) { IgniteCache cache = filterPlatform == FILTER_PLATFORM_JAVA && !isKeepBinary() ? rawCache(ctx) : cache(ctx); ScanQuery qry = new ScanQuery() .setLocal(loc) .setPageSize(pageSize) .setPartition(part) .setFilter(createFilter(ctx)); ctx.incrementCursors(); try { QueryCursor cur = cache.query(qry); ClientCacheEntryQueryCursor cliCur = new ClientCacheEntryQueryCursor(cur, pageSize, ctx); long cursorId = ctx.resources().put(cliCur); cliCur.id(cursorId); return new ClientCacheQueryResponse(requestId(), cliCur); } catch (Exception e) { ctx.decrementCursors(); throw e; } }
scanQry.setFilter(new IgniteBiPredicate<Integer, Person>() { @Override public boolean apply(Integer integer, Person person) { return true;
qry.setFilter(new TestFilter());
/** * Create scan query with filter. * * @param part Partition. * @param filter Filter. If {@code null} then all entries will be returned. */ public ScanQuery(@Nullable Integer part, @Nullable IgniteBiPredicate<K, V> filter) { setPartition(part); setFilter(filter); }
/** * 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; }
/** {@inheritDoc} */ @Override public ClientResponse process(ClientConnectionContext ctx) { authorize(ctx, SecurityPermission.CACHE_READ); IgniteCache cache = filterPlatform == FILTER_PLATFORM_JAVA && !isKeepBinary() ? rawCache(ctx) : cache(ctx); ScanQuery qry = new ScanQuery() .setLocal(loc) .setPageSize(pageSize) .setPartition(part) .setFilter(createFilter(ctx)); ctx.incrementCursors(); try { QueryCursor cur = cache.query(qry); ClientCacheEntryQueryCursor cliCur = new ClientCacheEntryQueryCursor(cur, pageSize, ctx); long cursorId = ctx.resources().put(cliCur); cliCur.id(cursorId); return new ClientCacheQueryResponse(requestId(), cliCur); } catch (Exception e) { ctx.decrementCursors(); throw e; } }