Search in sources :

Example 1 with CachedQueryEntry

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

the class AbstractInternalQueryCache method doFullValueScan.

protected void doFullValueScan(Predicate predicate, Set<V> resultingSet) {
    InternalSerializationService serializationService = this.serializationService;
    CachedQueryEntry queryEntry = new CachedQueryEntry();
    Set<Map.Entry<Data, QueryCacheRecord>> entries = recordStore.entrySet();
    for (Map.Entry<Data, QueryCacheRecord> entry : entries) {
        Data keyData = entry.getKey();
        QueryCacheRecord record = entry.getValue();
        Object value = record.getValue();
        queryEntry.init(serializationService, keyData, value, Extractors.empty());
        boolean valid = predicate.apply(queryEntry);
        if (valid) {
            Object valueObject = queryEntry.getValue();
            resultingSet.add((V) valueObject);
        }
    }
}
Also used : CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) QueryCacheRecord(com.hazelcast.map.impl.querycache.subscriber.record.QueryCacheRecord) Data(com.hazelcast.nio.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) AbstractMap(java.util.AbstractMap) IMap(com.hazelcast.core.IMap) Map(java.util.Map)

Example 2 with CachedQueryEntry

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

the class AbstractInternalQueryCache method doFullEntryScan.

protected void doFullEntryScan(Predicate predicate, Set<Map.Entry<K, V>> resultingSet) {
    InternalSerializationService serializationService = this.serializationService;
    CachedQueryEntry queryEntry = new CachedQueryEntry();
    Set<Map.Entry<Data, QueryCacheRecord>> entries = recordStore.entrySet();
    for (Map.Entry<Data, QueryCacheRecord> entry : entries) {
        Data keyData = entry.getKey();
        QueryCacheRecord record = entry.getValue();
        Object value = record.getValue();
        queryEntry.init(serializationService, keyData, value, Extractors.empty());
        boolean valid = predicate.apply(queryEntry);
        if (valid) {
            Object keyObject = queryEntry.getKey();
            Object valueObject = queryEntry.getValue();
            Map.Entry simpleEntry = new AbstractMap.SimpleEntry(keyObject, valueObject);
            resultingSet.add(simpleEntry);
        }
    }
}
Also used : CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) QueryCacheRecord(com.hazelcast.map.impl.querycache.subscriber.record.QueryCacheRecord) Data(com.hazelcast.nio.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) AbstractMap(java.util.AbstractMap) IMap(com.hazelcast.core.IMap) Map(java.util.Map)

Example 3 with CachedQueryEntry

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

the class AbstractMapQueryWithPagingPredicateMessageTask method reduce.

@Override
protected Object reduce(Collection<QueryResultRow> result) {
    ArrayList<QueryableEntry> accumulatedList = new ArrayList<>(result.size());
    // TODO: The following lines will be replaced by k-way merge sort algorithm as described at
    // https://github.com/hazelcast/hazelcast/issues/12205
    result.forEach(row -> accumulatedList.add(new CachedQueryEntry(serializationService, row.getKey(), row.getValue(), null)));
    PagingPredicateImpl pagingPredicateImpl = getPagingPredicate();
    List pageData = SortingUtil.getSortedSubListData(accumulatedList, pagingPredicateImpl);
    return new AbstractMap.SimpleImmutableEntry(getPagingPredicate().getAnchorList(), pageData);
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) PagingPredicateImpl(com.hazelcast.query.impl.predicates.PagingPredicateImpl)

Example 4 with CachedQueryEntry

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

the class DefaultQueryCache method addIndex.

@Override
public void addIndex(IndexConfig config) {
    checkNotNull(config, "Index config cannot be null.");
    assert indexes.isGlobal();
    IndexConfig config0 = getNormalizedIndexConfig(config);
    indexes.addOrGetIndex(config0);
    InternalSerializationService serializationService = context.getSerializationService();
    CachedQueryEntry<?, ?> newEntry = new CachedQueryEntry<>(serializationService, extractors);
    Set<Map.Entry<Object, QueryCacheRecord>> entries = recordStore.entrySet();
    for (Map.Entry<Object, QueryCacheRecord> entry : entries) {
        Object queryCacheKey = entry.getKey();
        QueryCacheRecord record = entry.getValue();
        Object value = record.getValue();
        Data keyData = toData(queryCacheKey);
        QueryEntry queryable = new QueryEntry(serializationService, keyData, value, extractors);
        newEntry.init(keyData, value);
        indexes.putEntry(newEntry, null, queryable, Index.OperationSource.USER);
    }
}
Also used : CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) QueryEntry(com.hazelcast.query.impl.QueryEntry) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) QueryEntry(com.hazelcast.query.impl.QueryEntry) IndexConfig(com.hazelcast.config.IndexConfig) QueryCacheRecord(com.hazelcast.map.impl.querycache.subscriber.record.QueryCacheRecord) Data(com.hazelcast.internal.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) IMap(com.hazelcast.map.IMap)

Example 5 with CachedQueryEntry

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

the class TransactionalMapProxy method values.

@Override
@SuppressWarnings("unchecked")
public Collection values(Predicate predicate) {
    checkTransactionState();
    checkNotNull(predicate, "Predicate can not be null!");
    checkNotInstanceOf(PagingPredicate.class, predicate, "Paging is not supported for Transactional queries");
    QueryEngine queryEngine = mapServiceContext.getQueryEngine(name);
    Query query = Query.of().mapName(name).predicate(predicate).iterationType(IterationType.ENTRY).build();
    QueryResult queryResult = queryEngine.execute(query, Target.ALL_NODES);
    Set result = QueryResultUtils.transformToSet(ss, queryResult, predicate, IterationType.ENTRY, true, true);
    // TODO: can't we just use the original set?
    List<Object> valueSet = new ArrayList<>();
    Set<Data> keyWontBeIncluded = new HashSet<>();
    Extractors extractors = mapServiceContext.getExtractors(name);
    CachedQueryEntry cachedQueryEntry = new CachedQueryEntry();
    // iterate over the txMap and see if the values are updated or removed
    for (Map.Entry<Data, TxnValueWrapper> entry : txMap.entrySet()) {
        boolean isRemoved = Type.REMOVED.equals(entry.getValue().type);
        boolean isUpdated = Type.UPDATED.equals(entry.getValue().type);
        if (isRemoved) {
            keyWontBeIncluded.add(entry.getKey());
        } else {
            if (isUpdated) {
                keyWontBeIncluded.add(entry.getKey());
            }
            Object entryValue = entry.getValue().value;
            cachedQueryEntry.init(ss, entry.getKey(), entryValue, extractors);
            if (predicate.apply(cachedQueryEntry)) {
                valueSet.add(toObjectIfNeeded(cachedQueryEntry.getValueData()));
            }
        }
    }
    removeFromResultSet(result, valueSet, keyWontBeIncluded);
    return valueSet;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Query(com.hazelcast.map.impl.query.Query) ArrayList(java.util.ArrayList) Data(com.hazelcast.internal.serialization.Data) QueryEngine(com.hazelcast.map.impl.query.QueryEngine) QueryResult(com.hazelcast.map.impl.query.QueryResult) Extractors(com.hazelcast.query.impl.getters.Extractors) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) HashMap(java.util.HashMap) Map(java.util.Map) TransactionalMap(com.hazelcast.transaction.TransactionalMap) HashSet(java.util.HashSet)

Aggregations

CachedQueryEntry (com.hazelcast.query.impl.CachedQueryEntry)15 Map (java.util.Map)10 QueryCacheRecord (com.hazelcast.map.impl.querycache.subscriber.record.QueryCacheRecord)6 Data (com.hazelcast.internal.serialization.Data)5 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)4 Data (com.hazelcast.nio.serialization.Data)4 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)4 Extractors (com.hazelcast.query.impl.getters.Extractors)4 AbstractMap (java.util.AbstractMap)4 IMap (com.hazelcast.core.IMap)3 QueryEntry (com.hazelcast.query.impl.QueryEntry)3 ArrayList (java.util.ArrayList)3 IMap (com.hazelcast.map.IMap)2 Query (com.hazelcast.map.impl.query.Query)2 QueryEngine (com.hazelcast.map.impl.query.QueryEngine)2 QueryResult (com.hazelcast.map.impl.query.QueryResult)2 Record (com.hazelcast.map.impl.record.Record)2 TransactionalMap (com.hazelcast.transaction.TransactionalMap)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2