Search in sources :

Example 41 with Predicate

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

the class PredicateBuilderImpl method and.

@Override
public PredicateBuilder and(Predicate predicate) {
    if (predicate != PredicateBuilderImpl.this) {
        throw new QueryException("Illegal and statement expected: " + PredicateBuilderImpl.class.getSimpleName() + ", found: " + ((predicate == null) ? "null" : predicate.getClass().getSimpleName()));
    }
    int index = lsPredicates.size() - 2;
    Predicate first = lsPredicates.remove(index);
    Predicate second = lsPredicates.remove(index);
    return addPredicate(Predicates.and(first, second));
}
Also used : QueryException(com.hazelcast.query.QueryException) IndexAwarePredicate(com.hazelcast.query.impl.predicates.IndexAwarePredicate) VisitablePredicate(com.hazelcast.query.impl.predicates.VisitablePredicate) Predicate(com.hazelcast.query.Predicate)

Example 42 with Predicate

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

the class AndPredicate method filter.

@Override
public Set<QueryableEntry> filter(QueryContext queryContext) {
    Set<QueryableEntry> smallestResultSet = null;
    List<Set<QueryableEntry>> otherResultSets = null;
    List<Predicate> unindexedPredicates = null;
    for (Predicate predicate : predicates) {
        if (isIndexedPredicate(predicate, queryContext)) {
            // Avoid checking indexed partitions count twice to avoid
            // scenario when the owner partitions count changes concurrently and null
            // value from the filter method may indicate that the index is under
            // construction.
            int ownedPartitionsCount = queryContext.getOwnedPartitionCount();
            queryContext.setOwnedPartitionCount(SKIP_PARTITIONS_COUNT_CHECK);
            Set<QueryableEntry> currentResultSet = ((IndexAwarePredicate) predicate).filter(queryContext);
            queryContext.setOwnedPartitionCount(ownedPartitionsCount);
            if (smallestResultSet == null) {
                smallestResultSet = currentResultSet;
            } else if (estimatedSizeOf(currentResultSet) < estimatedSizeOf(smallestResultSet)) {
                otherResultSets = initOrGetListOf(otherResultSets);
                otherResultSets.add(smallestResultSet);
                smallestResultSet = currentResultSet;
            } else {
                otherResultSets = initOrGetListOf(otherResultSets);
                otherResultSets.add(currentResultSet);
            }
        } else {
            unindexedPredicates = initOrGetListOf(unindexedPredicates);
            unindexedPredicates.add(predicate);
        }
    }
    if (smallestResultSet == null) {
        return null;
    }
    return new AndResultSet(smallestResultSet, otherResultSets, unindexedPredicates);
}
Also used : Set(java.util.Set) AndResultSet(com.hazelcast.query.impl.AndResultSet) AndResultSet(com.hazelcast.query.impl.AndResultSet) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) Predicate(com.hazelcast.query.Predicate)

Example 43 with Predicate

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

the class AndPredicate method negate.

@Override
public Predicate negate() {
    int size = predicates.length;
    Predicate[] inners = new Predicate[size];
    for (int i = 0; i < size; i++) {
        Predicate original = predicates[i];
        Predicate negated;
        if (original instanceof NegatablePredicate) {
            negated = ((NegatablePredicate) original).negate();
        } else {
            negated = new NotPredicate(original);
        }
        inners[i] = negated;
    }
    OrPredicate orPredicate = new OrPredicate(inners);
    return orPredicate;
}
Also used : Predicate(com.hazelcast.query.Predicate)

Example 44 with Predicate

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

the class NotPredicate method accept.

@Override
public Predicate accept(Visitor visitor, Indexes indexes) {
    Predicate target = predicate;
    if (predicate instanceof VisitablePredicate) {
        target = ((VisitablePredicate) predicate).accept(visitor, indexes);
    }
    if (target == predicate) {
        // visitor didn't change the inner predicate
        return visitor.visit(this, indexes);
    }
    // visitor returned a different copy of the inner predicate.
    // We have to create our copy with the new inner predicate to maintained immutability
    NotPredicate copy = new NotPredicate(target);
    return visitor.visit(copy, indexes);
}
Also used : Predicate(com.hazelcast.query.Predicate)

Example 45 with Predicate

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

the class OrToInVisitor method replaceInnerPredicates.

private Predicate[] replaceInnerPredicates(Predicate[] innerPredicates, int toBeRemoved) {
    if (toBeRemoved == 0) {
        return innerPredicates;
    }
    int removed = 0;
    int newSize = innerPredicates.length - toBeRemoved;
    Predicate[] newPredicates = new Predicate[newSize];
    for (int i = 0; i < innerPredicates.length; i++) {
        Predicate p = innerPredicates[i];
        if (p != null) {
            newPredicates[i - removed] = p;
        } else {
            removed++;
        }
    }
    return newPredicates;
}
Also used : 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