Search in sources :

Example 31 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class ClientMapStandaloneTest method testPortable_query_with_index.

@Test
public void testPortable_query_with_index() {
    IMap<Integer, MyPortableElement> map = createMap();
    for (int i = 0; i < 100; i++) {
        MyPortableElement element = new MyPortableElement(i);
        map.put(i, element);
    }
    map.addIndex(IndexType.HASH, "id");
    Predicate predicate = or(equal("id", 0), equal("id", 1));
    Collection values = map.values(predicate);
    assertEquals(2, values.size());
}
Also used : MyPortableElement(com.hazelcast.client.standalone.model.MyPortableElement) Collection(java.util.Collection) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 32 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class AbstractMapQueryMessageTask method call.

@Override
protected final Object call() throws Exception {
    Collection<AccumulatedResults> result = new LinkedList<AccumulatedResults>();
    try {
        Predicate predicate = getPredicate();
        if (predicate instanceof PartitionPredicate) {
            int partitionId = clientMessage.getPartitionId();
            QueryResult queryResult = invokeOnPartition((PartitionPredicate) predicate, partitionId);
            extractAndAppendResult(result, queryResult);
            return reduce(result);
        }
        int partitionCount = clientEngine.getPartitionService().getPartitionCount();
        PartitionIdSet finishedPartitions = invokeOnMembers(result, predicate, partitionCount);
        invokeOnMissingPartitions(result, predicate, finishedPartitions);
    } catch (Throwable t) {
        throw rethrow(t);
    }
    return reduce(result);
}
Also used : PartitionPredicate(com.hazelcast.query.PartitionPredicate) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) LinkedList(java.util.LinkedList) PartitionPredicate(com.hazelcast.query.PartitionPredicate) Predicate(com.hazelcast.query.Predicate)

Example 33 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class MapAddEntryListenerToKeyWithPredicateMessageTask method getEventFilter.

@Override
protected EventFilter getEventFilter() {
    Predicate predicate = serializationService.toObject(parameters.predicate);
    QueryEventFilter eventFilter = new QueryEventFilter(parameters.key, predicate, parameters.includeValue);
    return new EventListenerFilter(parameters.listenerFlags, eventFilter);
}
Also used : QueryEventFilter(com.hazelcast.map.impl.query.QueryEventFilter) EventListenerFilter(com.hazelcast.map.impl.EventListenerFilter) Predicate(com.hazelcast.query.Predicate)

Example 34 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class MapFetchWithQueryMessageTask method prepareOperation.

@Override
protected Operation prepareOperation() {
    MapOperationProvider operationProvider = getMapOperationProvider(parameters.name);
    Projection<?, ?> projection = nodeEngine.getSerializationService().toObject(parameters.projection);
    Predicate predicate = nodeEngine.getSerializationService().toObject(parameters.predicate);
    Query query = Query.of().mapName(parameters.name).iterationType(IterationType.VALUE).predicate(predicate).projection(projection).build();
    IterationPointer[] pointers = decodePointers(parameters.iterationPointers);
    return operationProvider.createFetchWithQueryOperation(parameters.name, pointers, parameters.batch, query);
}
Also used : IterationPointer(com.hazelcast.internal.iteration.IterationPointer) Query(com.hazelcast.map.impl.query.Query) MapOperationProvider(com.hazelcast.map.impl.operation.MapOperationProvider) Predicate(com.hazelcast.query.Predicate)

Example 35 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class PartitionAccumulatorRegistry method createEventFilter.

private EventFilter createEventFilter() {
    boolean includeValue = info.isIncludeValue();
    Predicate predicate = info.getPredicate();
    return new QueryEventFilter(null, predicate, includeValue);
}
Also used : QueryEventFilter(com.hazelcast.map.impl.query.QueryEventFilter) Predicate(com.hazelcast.query.Predicate)

Aggregations

Predicate (com.hazelcast.query.Predicate)248 Test (org.junit.Test)165 QuickTest (com.hazelcast.test.annotation.QuickTest)159 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)105 HazelcastInstance (com.hazelcast.core.HazelcastInstance)38 MapListener (com.hazelcast.map.listener.MapListener)17 ParallelTest (com.hazelcast.test.annotation.ParallelTest)17 EntryListener (com.hazelcast.core.EntryListener)16 FalsePredicate (com.hazelcast.query.impl.FalsePredicate)15 ArrayList (java.util.ArrayList)15 EntryObject (com.hazelcast.query.PredicateBuilder.EntryObject)14 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)14 Value (com.hazelcast.query.SampleTestObjects.Value)10 SqlPredicate (com.hazelcast.query.SqlPredicate)10 Config (com.hazelcast.config.Config)9 PredicateTestUtils.createMockVisitablePredicate (com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockVisitablePredicate)9 EntryEvent (com.hazelcast.core.EntryEvent)8 Data (com.hazelcast.internal.serialization.Data)8 MapListenerAdapter (com.hazelcast.map.impl.MapListenerAdapter)8 Indexes (com.hazelcast.query.impl.Indexes)8