/** * 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; }
/** * 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); }
/** * Queries the specified cache using the specified filter. * * @param upstreamCache Ignite cache with {@code upstream} data. * @return Query cursor. */ private QueryCursor<Cache.Entry<K, V>> query(IgniteCache<K, V> upstreamCache) { ScanQuery<K, V> qry = new ScanQuery<>(); return upstreamCache.query(qry); }
/** * @param ignite Ignite. * @param orgId Organization id. * @return Count of found Person object with specified orgId */ private static int getPersonsCountByScanLocalQuery(final IgniteEx ignite, final int orgId) { List res = ignite.cache(Person.class.getSimpleName()) .query(new ScanQuery<>(new IgniteBiPredicate<Person.Key, Person>() { @Override public boolean apply(Person.Key key, Person person) { return person.getOrgId() == orgId; } }).setLocal(true)).getAll(); return res.size(); }
/** * @param node Node. * @param loc Local flag. * @param parts Partitions. */ protected void checkQueryPasses(Ignite node, boolean loc, int... parts) { // Scan queries don't support multiple partitions. if (parts != null && parts.length > 1) return; // TODO Local scan queries fail in non-safe modes - https://issues.apache.org/jira/browse/IGNITE-10059. if (loc) return; IgniteCache cache = node.cache(DEFAULT_CACHE_NAME); ScanQuery qry = new ScanQuery(); if (parts != null && parts.length > 0) qry.setPartition(parts[0]); if (loc) qry.setLocal(true); cache.query(qry).getAll(); }
List<Integer> res = cache.query(new ScanQuery<Integer, Value>().setPartition(0), transformer).getAll();
@Override public Object call() throws Exception { int nodeId = nodeIdx.getAndIncrement(); IgniteCache<Integer, Integer> cache = grid(nodeId).cache(DEFAULT_CACHE_NAME); int cntr = 0; while (!done.get()) { int part = ThreadLocalRandom.current().nextInt(ignite(nodeId).affinity(DEFAULT_CACHE_NAME).partitions()); if (cntr++ % 100 == 0) info("Running query [node=" + nodeId + ", part=" + part + ']'); try (QueryCursor<Cache.Entry<Integer, Integer>> cur = cache.query(new ScanQuery<Integer, Integer>(part).setPageSize(5))) { doTestScanQueryCursor(cur, part); } } return null; } }, GRID_CNT);
cur = new VisorNearCacheCursor<>(c.localEntries(CachePeekMode.NEAR).iterator()); else { ScanQuery<Object, Object> qry = new ScanQuery<>(filter); qry.setPageSize(arg.getPageSize()); qry.setLocal(arg.isLocal());
Query<Cache.Entry<Integer, String>> qry = new ScanQuery<Integer, String>() .setPageSize(data.size() / PAGE_CNT) .setFilter((i, s) -> i >= rangeStart && i < rangeEnd);
private void checkScanQuery(IgniteCache<Long,TestData> cache, Boolean dataPageScanEnabled, Boolean expLastDataPageScan) { assertTrue(cache.query(new ScanQuery<>(new TestPredicate()) .setDataPageScanEnabled(dataPageScanEnabled)).getAll().isEmpty()); assertEquals(expLastDataPageScan, CacheDataTree.isLastFindWithDataPageScan()); }
/** * Returns list of maintained TensorFlow clusters. * * @return List of maintained TensorFlow clusters. */ public Map<UUID, TensorFlowCluster> getAllClusters() { Map<UUID, TensorFlowCluster> res = new HashMap<>(); ScanQuery<UUID, TensorFlowCluster> qry = new ScanQuery<>(); QueryCursor<Cache.Entry<UUID, TensorFlowCluster>> cursor = cache.query(qry); for (Cache.Entry<UUID, TensorFlowCluster> e : cursor) res.put(e.getKey(), e.getValue()); return res; }
/** * @throws Exception If failed. */ @Test public void testScanLocalQuery() throws Exception { IgniteCache<Integer, String> cache = grid().getOrCreateCache(String.class.getSimpleName()); try { cache.query(new ScanQuery<>(new IgniteBiPredicate<Integer, String>() { @Override public boolean apply(Integer id, String s) { return s.equals(""); } }).setLocal(true)).getAll(); } catch (IgniteException ignored) { assertTrue("Scan query should work with disable query indexing.", false); } } /**
/** * @param node Node. * @param loc Local flag. * @param parts Partitions. */ protected void checkQueryFails(Ignite node, boolean loc, int... parts) { if (parts.length == 0) return; IgniteCache cache = node.cache(DEFAULT_CACHE_NAME); String msg = loc ? "forced local query" : "partition has been lost"; GridTestUtils.assertThrows(log, () -> { List res = null; for (int partition : parts) { ScanQuery qry = new ScanQuery(); qry.setPartition(partition); if (loc) qry.setLocal(true); res = cache.query(qry).getAll(); } return res; }, IgniteCheckedException.class, msg); }
/** * Scan should perform on the local node. * * @throws Exception If failed. */ @Test public void testScanLocal() throws Exception { cacheMode = CacheMode.PARTITIONED; backups = 0; commSpiFactory = new TestLocalCommunicationSpiFactory(); try { Ignite ignite = startGrids(GRID_CNT); IgniteCacheProxy<Integer, Integer> cache = fillCache(ignite); int part = anyLocalPartition(cache.context()); QueryCursor<Cache.Entry<Integer, Integer>> qry = cache.query(new ScanQuery<Integer, Integer>().setPartition(part)); doTestScanQuery(qry, part); } finally { stopAllGrids(); } }
/** * Test metrics for Scan queries. * * @throws Exception In case of error. */ @Test public void testScanQueryNotFullyFetchedMetrics() throws Exception { IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A"); ScanQuery<Integer, String> qry = new ScanQuery<>(); qry.setPageSize(10); checkQueryNotFullyFetchedMetrics(cache, qry, true); }
/** * Execute scan query. * * @param c Cache to scan. * @param arg Job argument with query parameters. * @return Query cursor. */ private QueryCursor<Cache.Entry<Object, Object>> scan(IgniteCache<Object, Object> c, VisorScanQueryTaskArg arg, IgniteBiPredicate<Object, Object> filter) { ScanQuery<Object, Object> qry = new ScanQuery<>(filter); qry.setPageSize(arg.getPageSize()); qry.setLocal(arg.isLocal()); return c.withKeepBinary().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); } } };
/** * 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); }
/** {@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; } }