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));
}
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);
}
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;
}
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);
}
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;
}
Aggregations