Search in sources :

Example 16 with QueryableEntry

use of com.hazelcast.query.impl.QueryableEntry in project hazelcast by hazelcast.

the class CallerRunsPartitionScanExecutor method execute.

@Override
public Collection<QueryableEntry> execute(String mapName, Predicate predicate, Collection<Integer> partitions) {
    RetryableHazelcastException storedException = null;
    Collection<QueryableEntry> result = new ArrayList<QueryableEntry>();
    for (Integer partitionId : partitions) {
        try {
            result.addAll(partitionScanRunner.run(mapName, predicate, partitionId));
        } catch (RetryableHazelcastException e) {
            // see discussion at https://github.com/hazelcast/hazelcast/pull/5049#discussion_r28773099 for details.
            if (storedException == null) {
                storedException = e;
            }
        }
    }
    if (storedException != null) {
        throw storedException;
    }
    return result;
}
Also used : RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) ArrayList(java.util.ArrayList) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Example 17 with QueryableEntry

use of com.hazelcast.query.impl.QueryableEntry in project hazelcast by hazelcast.

the class NodeQueryCacheEventService method canPassFilter.

private boolean canPassFilter(LocalEntryEventData localEntryEventData, EventFilter filter) {
    if (filter == null || filter instanceof TrueEventFilter) {
        return true;
    }
    NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    SerializationService serializationService = nodeEngine.getSerializationService();
    Data keyData = localEntryEventData.getKeyData();
    Object value = getValueOrOldValue(localEntryEventData);
    QueryableEntry entry = new QueryEntry((InternalSerializationService) serializationService, keyData, value, Extractors.empty());
    return filter.eval(entry);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) QueryEntry(com.hazelcast.query.impl.QueryEntry) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.spi.serialization.SerializationService) LocalCacheWideEventData(com.hazelcast.map.impl.querycache.event.LocalCacheWideEventData) EventData(com.hazelcast.map.impl.event.EventData) Data(com.hazelcast.nio.serialization.Data) LocalEntryEventData(com.hazelcast.map.impl.querycache.event.LocalEntryEventData) TrueEventFilter(com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Example 18 with QueryableEntry

use of com.hazelcast.query.impl.QueryableEntry in project hazelcast by hazelcast.

the class ParallelAccumulationExecutor method split.

private Collection<QueryableEntry>[] split(Collection<QueryableEntry> entries, int chunkCount) {
    if (entries.size() < chunkCount * 2) {
        return null;
    }
    int counter = 0;
    Collection<QueryableEntry>[] entriesSplit = new Collection[chunkCount];
    int entriesPerChunk = entries.size() / chunkCount;
    for (int i = 0; i < chunkCount; i++) {
        entriesSplit[i] = new ArrayList<QueryableEntry>(entriesPerChunk);
    }
    for (QueryableEntry entry : entries) {
        entriesSplit[counter++ % THREAD_SPLIT_COUNT].add(entry);
    }
    return entriesSplit;
}
Also used : Collection(java.util.Collection) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Example 19 with QueryableEntry

use of com.hazelcast.query.impl.QueryableEntry in project hazelcast by hazelcast.

the class PartitionScanRunner method run.

@SuppressWarnings("unchecked")
public Collection<QueryableEntry> run(String mapName, Predicate predicate, int partitionId) {
    PagingPredicate pagingPredicate = predicate instanceof PagingPredicate ? (PagingPredicate) predicate : null;
    List<QueryableEntry> resultList = new LinkedList<QueryableEntry>();
    PartitionContainer partitionContainer = mapServiceContext.getPartitionContainer(partitionId);
    MapContainer mapContainer = mapServiceContext.getMapContainer(mapName);
    Iterator<Record> iterator = partitionContainer.getRecordStore(mapName).loadAwareIterator(getNow(), false);
    Map.Entry<Integer, Map.Entry> nearestAnchorEntry = getNearestAnchorEntry(pagingPredicate);
    boolean useCachedValues = isUseCachedDeserializedValuesEnabled(mapContainer);
    Extractors extractors = mapServiceContext.getExtractors(mapName);
    while (iterator.hasNext()) {
        Record record = iterator.next();
        Data key = (Data) toData(record.getKey());
        Object value = toData(useCachedValues ? Records.getValueOrCachedValue(record, serializationService) : record.getValue());
        if (value == null) {
            continue;
        }
        //we want to always use CachedQueryEntry as these are short-living objects anyway
        QueryableEntry queryEntry = new CachedQueryEntry(serializationService, key, value, extractors);
        if (predicate.apply(queryEntry) && compareAnchor(pagingPredicate, queryEntry, nearestAnchorEntry)) {
            resultList.add(queryEntry);
        }
    }
    return getSortedSubList(resultList, pagingPredicate, nearestAnchorEntry);
}
Also used : PartitionContainer(com.hazelcast.map.impl.PartitionContainer) Data(com.hazelcast.nio.serialization.Data) LinkedList(java.util.LinkedList) MapContainer(com.hazelcast.map.impl.MapContainer) PagingPredicate(com.hazelcast.query.PagingPredicate) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) PagingPredicateAccessor.getNearestAnchorEntry(com.hazelcast.query.PagingPredicateAccessor.getNearestAnchorEntry) Extractors(com.hazelcast.query.impl.getters.Extractors) Record(com.hazelcast.map.impl.record.Record) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) Map(java.util.Map) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Example 20 with QueryableEntry

use of com.hazelcast.query.impl.QueryableEntry in project hazelcast by hazelcast.

the class DefaultQueryCache method keySet.

@Override
public Set<K> keySet(Predicate predicate) {
    checkNotNull(predicate, "Predicate cannot be null!");
    Set<K> resultingSet = new HashSet<K>();
    Set<QueryableEntry> query = indexes.query(predicate);
    if (query != null) {
        for (QueryableEntry entry : query) {
            K key = (K) entry.getKey();
            resultingSet.add(key);
        }
    } else {
        doFullKeyScan(predicate, resultingSet);
    }
    return resultingSet;
}
Also used : QueryableEntry(com.hazelcast.query.impl.QueryableEntry) HashSet(java.util.HashSet)

Aggregations

QueryableEntry (com.hazelcast.query.impl.QueryableEntry)34 Data (com.hazelcast.nio.serialization.Data)14 Predicate (com.hazelcast.query.Predicate)10 ParallelTest (com.hazelcast.test.annotation.ParallelTest)10 QuickTest (com.hazelcast.test.annotation.QuickTest)10 Test (org.junit.Test)10 TruePredicate (com.hazelcast.query.TruePredicate)5 FalsePredicate (com.hazelcast.query.impl.FalsePredicate)5 HashSet (java.util.HashSet)5 CachedQueryEntry (com.hazelcast.query.impl.CachedQueryEntry)4 Indexes (com.hazelcast.query.impl.Indexes)4 Extractors (com.hazelcast.query.impl.getters.Extractors)4 SerializationService (com.hazelcast.spi.serialization.SerializationService)4 Map (java.util.Map)4 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)3 MapContainer (com.hazelcast.map.impl.MapContainer)3 Record (com.hazelcast.map.impl.record.Record)3 TransactionalMap (com.hazelcast.core.TransactionalMap)2 MapQueryEngine (com.hazelcast.map.impl.query.MapQueryEngine)2 Query (com.hazelcast.map.impl.query.Query)2