Java Code Examples for org.apache.ignite.cache.query.ScanQuery#setFilter()
The following examples show how to use
org.apache.ignite.cache.query.ScanQuery#setFilter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IgniteCacheRandomOperationBenchmark.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public void run() { IgniteCache cache = node.cache(cacheName); // Getting a list of the partitions owned by this node. List<Integer> myPartitions = cachePart.get(node.cluster().localNode().id()); for (Integer part : myPartitions) { ScanQuery scanQry = new ScanQuery(); scanQry.setPartition(part); scanQry.setFilter(igniteBiPred); try (QueryCursor cursor = cache.query(scanQry)) { for (Object obj : cursor) { // No-op. } } } }
Example 2
Source File: CacheBasedLabelPairCursor.java From ignite with Apache License 2.0 | 5 votes |
/** * 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); }
Example 3
Source File: IgniteClientReconnectQueriesTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @param setPart If {@code true} sets partition for scan query. * @throws Exception If failed. */ private void scanQueryReconnectInProgress(boolean setPart) throws Exception { Ignite cln = grid(serverCount()); assertTrue(cln.cluster().localNode().isClient()); final Ignite srv = clientRouter(cln); final IgniteCache<Integer, Person> clnCache = cln.getOrCreateCache(QUERY_CACHE); clnCache.put(1, new Person(1, "name1", "surname1")); clnCache.put(2, new Person(2, "name2", "surname2")); clnCache.put(3, new Person(3, "name3", "surname3")); final ScanQuery<Integer, Person> scanQry = new ScanQuery<>(); scanQry.setPageSize(1); scanQry.setFilter(new IgniteBiPredicate<Integer, Person>() { @Override public boolean apply(Integer integer, Person person) { return true; } }); if (setPart) scanQry.setPartition(1); blockMessage(GridCacheQueryResponse.class); final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() { @Override public Object call() throws Exception { try { QueryCursor<Cache.Entry<Integer, Person>> qryCursor = clnCache.query(scanQry); qryCursor.getAll(); } catch (CacheException e) { checkAndWait(e); return true; } return false; } }); // Check that client waiting operation. GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { return fut.get(200); } }, IgniteFutureTimeoutCheckedException.class, null); assertNotDone(fut); unblockMessage(); reconnectClientNode(cln, srv, null); assertTrue((Boolean)fut.get(2, SECONDS)); QueryCursor<Cache.Entry<Integer, Person>> qryCursor2 = clnCache.query(scanQry); List<Cache.Entry<Integer, Person>> entries = qryCursor2.getAll(); assertEquals(setPart ? 1 : 3, entries.size()); for (Cache.Entry<Integer, Person> entry : entries) { assertEquals(Integer.class, entry.getKey().getClass()); assertEquals(Person.class, entry.getValue().getClass()); } }
Example 4
Source File: IgniteScanQueryBenchmark.java From ignite with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public boolean test(Map<Object, Object> ctx) throws Exception { int key = nextRandom(args.range()); ScanQuery<Integer, Object> qry = new ScanQuery<>(); qry.setFilter(new KeyFilter(key)); IgniteCache<Integer, Object> cache = cacheForOperation().withKeepBinary(); List<IgniteCache.Entry<Integer, Object>> res = cache.query(qry).getAll(); if (res.size() != 1) throw new Exception("Invalid result size: " + res.size()); if (res.get(0).getKey() != key) throw new Exception("Invalid entry found [key=" + key + ", entryKey=" + res.get(0).getKey() + ']'); return true; }
Example 5
Source File: PlatformCache.java From ignite with Apache License 2.0 | 4 votes |
/** * 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; }
Example 6
Source File: TrainTestDatasetSplitterExample.java From ignite with Apache License 2.0 | 4 votes |
/** * Run example. */ public static void main(String[] args) throws IOException { System.out.println(); System.out.println(">>> Linear regression model over cache based dataset usage example started."); // Start ignite grid. try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(">>> Ignite grid started."); IgniteCache<Integer, Vector> dataCache = null; try { dataCache = new SandboxMLCache(ignite).fillCacheWith(MLSandboxDatasets.MORTALITY_DATA); System.out.println(">>> Create new linear regression trainer object."); LinearRegressionLSQRTrainer trainer = new LinearRegressionLSQRTrainer(); System.out.println(">>> Create new training dataset splitter object."); TrainTestSplit<Integer, Vector> split = new TrainTestDatasetSplitter<Integer, Vector>() .split(0.75); System.out.println(">>> Perform the training to get the model."); Vectorizer<Integer, Vector, Integer, Double> vectorizer = new DummyVectorizer<Integer>() .labeled(Vectorizer.LabelCoordinate.FIRST); LinearRegressionModel mdl = trainer.fit(ignite, dataCache, split.getTrainFilter(), vectorizer); System.out.println(">>> Linear regression model: " + mdl); System.out.println(">>> ---------------------------------"); System.out.println(">>> | Prediction\t| Ground Truth\t|"); System.out.println(">>> ---------------------------------"); ScanQuery<Integer, Vector> qry = new ScanQuery<>(); qry.setFilter(split.getTestFilter()); try (QueryCursor<Cache.Entry<Integer, Vector>> observations = dataCache.query(qry)) { for (Cache.Entry<Integer, Vector> observation : observations) { Vector val = observation.getValue(); Vector inputs = val.copyOfRange(1, val.size()); double groundTruth = val.get(0); double prediction = mdl.predict(inputs); System.out.printf(">>> | %.4f\t\t| %.4f\t\t|\n", prediction, groundTruth); } } System.out.println(">>> ---------------------------------"); System.out.println(">>> Linear regression model over cache based dataset usage example completed."); } finally { if (dataCache != null) dataCache.destroy(); } } finally { System.out.flush(); } }