Search in sources :

Example 11 with Extractors

use of com.hazelcast.query.impl.getters.Extractors in project hazelcast by hazelcast.

the class AbstractFilteringStrategy method evaluateQueryEventFilter.

/**
 * Evaluates the {@code filter} using a {@link CachedQueryEntry} together with the
 * value {@link Extractors} configured for this map. The filter must be of {@link QueryEventFilter} type.
 *
 * @param filter        a {@link QueryEventFilter} filter
 * @param dataKey       the entry key
 * @param testValue     the value used to evaluate the filter
 * @param mapNameOrNull the map name. May be null if this is not a map event (e.g. cache event)
 * @return {@code true} if the entry matches the query event filter
 */
protected boolean evaluateQueryEventFilter(EventFilter filter, Data dataKey, Object testValue, String mapNameOrNull) {
    Extractors extractors = getExtractorsForMapName(mapNameOrNull);
    QueryEventFilter queryEventFilter = (QueryEventFilter) filter;
    QueryableEntry entry = new CachedQueryEntry(serializationService, dataKey, testValue, extractors);
    return queryEventFilter.eval(entry);
}
Also used : Extractors(com.hazelcast.query.impl.getters.Extractors) QueryEventFilter(com.hazelcast.map.impl.query.QueryEventFilter) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Example 12 with Extractors

use of com.hazelcast.query.impl.getters.Extractors in project hazelcast by hazelcast.

the class TransactionalMapProxy method keySet.

@Override
@SuppressWarnings("unchecked")
public Set keySet(Predicate predicate) {
    checkTransactionState();
    checkNotNull(predicate, "Predicate should 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.KEY).build();
    QueryResult queryResult = queryEngine.execute(query, Target.ALL_NODES);
    Set queryResultSet = QueryResultUtils.transformToSet(ss, queryResult, predicate, IterationType.KEY, true, tx.isOriginatedFromClient());
    Extractors extractors = mapServiceContext.getExtractors(name);
    Set<Object> returningKeySet = new HashSet<Object>(queryResultSet);
    CachedQueryEntry cachedQueryEntry = new CachedQueryEntry();
    for (Map.Entry<Data, TxnValueWrapper> entry : txMap.entrySet()) {
        if (entry.getValue().type == Type.REMOVED) {
            // meanwhile remove keys which are not in txMap
            returningKeySet.remove(toObjectIfNeeded(entry.getKey()));
        } else {
            Data keyData = entry.getKey();
            if (predicate == Predicates.alwaysTrue()) {
                returningKeySet.add(toObjectIfNeeded(keyData));
            } else {
                cachedQueryEntry.init(ss, keyData, entry.getValue().value, extractors);
                // apply predicate on txMap
                if (predicate.apply(cachedQueryEntry)) {
                    returningKeySet.add(toObjectIfNeeded(keyData));
                }
            }
        }
    }
    return returningKeySet;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Query(com.hazelcast.map.impl.query.Query) 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)

Example 13 with Extractors

use of com.hazelcast.query.impl.getters.Extractors in project hazelcast by hazelcast.

the class IndexImplTest method setUp.

@Before
public void setUp() {
    InternalSerializationService mockSerializationService = mock(InternalSerializationService.class);
    Extractors mockExtractors = Extractors.newBuilder(mockSerializationService).build();
    IndexConfig config = IndexUtils.createTestIndexConfig(IndexType.HASH, ATTRIBUTE_NAME);
    index = new IndexImpl(config, mockSerializationService, mockExtractors, IndexCopyBehavior.COPY_ON_READ, PerIndexStats.EMPTY, MemberPartitionStateImpl.DEFAULT_PARTITION_COUNT);
}
Also used : Extractors(com.hazelcast.query.impl.getters.Extractors) IndexConfig(com.hazelcast.config.IndexConfig) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) Before(org.junit.Before)

Aggregations

Extractors (com.hazelcast.query.impl.getters.Extractors)13 Data (com.hazelcast.internal.serialization.Data)4 CachedQueryEntry (com.hazelcast.query.impl.CachedQueryEntry)4 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)4 QueryTarget (com.hazelcast.sql.impl.extract.QueryTarget)4 Map (java.util.Map)4 Parameters (junitparams.Parameters)4 Test (org.junit.Test)4 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)3 PartitionContainer (com.hazelcast.map.impl.PartitionContainer)3 IndexConfig (com.hazelcast.config.IndexConfig)2 ToHeapDataConverter.toHeapData (com.hazelcast.internal.util.ToHeapDataConverter.toHeapData)2 LazyMapEntry (com.hazelcast.map.impl.LazyMapEntry)2 MapContainer (com.hazelcast.map.impl.MapContainer)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