Search in sources :

Example 1 with GridSetQueryPredicate

use of org.apache.ignite.internal.processors.datastructures.GridSetQueryPredicate in project ignite by apache.

the class GridCacheQueryManager method sharedCacheSetIterator.

/**
 * @param qry Query.
 * @return Cache set items iterator.
 */
private GridCloseableIterator<IgniteBiTuple<K, V>> sharedCacheSetIterator(GridCacheQueryAdapter<?> qry) throws IgniteCheckedException {
    final GridSetQueryPredicate filter = (GridSetQueryPredicate) qry.scanFilter();
    IgniteUuid id = filter.setId();
    GridCacheQueryAdapter<CacheEntry<K, ?>> qry0 = new GridCacheQueryAdapter<>(cctx, SCAN, new IgniteBiPredicate<Object, Object>() {

        @Override
        public boolean apply(Object k, Object v) {
            return k instanceof SetItemKey && id.equals(((SetItemKey) k).setId());
        }
    }, new IgniteClosure<Map.Entry, Object>() {

        @Override
        public Object apply(Map.Entry entry) {
            return new IgniteBiTuple<K, V>((K) ((SetItemKey) entry.getKey()).item(), (V) Boolean.TRUE);
        }
    }, qry.partition(), false, true, qry.isDataPageScanEnabled());
    return scanQueryLocal(qry0, false);
}
Also used : CacheEntry(org.apache.ignite.cache.CacheEntry) CacheEntry(org.apache.ignite.cache.CacheEntry) IgniteUuid(org.apache.ignite.lang.IgniteUuid) GridSetQueryPredicate(org.apache.ignite.internal.processors.datastructures.GridSetQueryPredicate) SetItemKey(org.apache.ignite.internal.processors.datastructures.SetItemKey) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) GridLeanMap(org.apache.ignite.internal.util.GridLeanMap)

Example 2 with GridSetQueryPredicate

use of org.apache.ignite.internal.processors.datastructures.GridSetQueryPredicate in project ignite by apache.

the class GridCacheQueryManager method setIterator.

/**
 * @param qry Query.
 * @return Cache set items iterator.
 */
private GridCloseableIterator<IgniteBiTuple<K, V>> setIterator(GridCacheQueryAdapter<?> qry) {
    final GridSetQueryPredicate filter = (GridSetQueryPredicate) qry.scanFilter();
    filter.init(cctx);
    IgniteUuid id = filter.setId();
    Collection<SetItemKey> data = cctx.dataStructures().setData(id);
    if (data == null)
        data = Collections.emptyList();
    final GridIterator<IgniteBiTuple<K, V>> it = F.iterator(data, new C1<SetItemKey, IgniteBiTuple<K, V>>() {

        @Override
        public IgniteBiTuple<K, V> apply(SetItemKey e) {
            return new IgniteBiTuple<>((K) e.item(), (V) Boolean.TRUE);
        }
    }, true, new P1<SetItemKey>() {

        @Override
        public boolean apply(SetItemKey e) {
            return filter.apply(e, null);
        }
    });
    return new GridCloseableIteratorAdapter<IgniteBiTuple<K, V>>() {

        @Override
        protected boolean onHasNext() {
            return it.hasNext();
        }

        @Override
        protected IgniteBiTuple<K, V> onNext() {
            return it.next();
        }

        @Override
        protected void onRemove() {
            it.remove();
        }

        @Override
        protected void onClose() {
        // No-op.
        }
    };
}
Also used : GridCloseableIteratorAdapter(org.apache.ignite.internal.util.GridCloseableIteratorAdapter) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) IgniteUuid(org.apache.ignite.lang.IgniteUuid) GridSetQueryPredicate(org.apache.ignite.internal.processors.datastructures.GridSetQueryPredicate) SetItemKey(org.apache.ignite.internal.processors.datastructures.SetItemKey)

Aggregations

GridSetQueryPredicate (org.apache.ignite.internal.processors.datastructures.GridSetQueryPredicate)2 SetItemKey (org.apache.ignite.internal.processors.datastructures.SetItemKey)2 IgniteUuid (org.apache.ignite.lang.IgniteUuid)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 CacheEntry (org.apache.ignite.cache.CacheEntry)1 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)1 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)1 GridCloseableIteratorAdapter (org.apache.ignite.internal.util.GridCloseableIteratorAdapter)1 GridLeanMap (org.apache.ignite.internal.util.GridLeanMap)1 IgniteBiTuple (org.apache.ignite.lang.IgniteBiTuple)1