use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class AbstractQueryCacheEndToEndConstructor method initQueryCacheConfig.
private QueryCacheConfig initQueryCacheConfig(QueryCacheRequest request, String cacheId) {
Predicate predicate = request.getPredicate();
QueryCacheConfig queryCacheConfig;
if (predicate == null) {
// user called IMap#getQueryCache method only providing
// a name (but without a predicate), here we are trying
// to find a matching configuration for this query cache.
queryCacheConfig = getOrNullQueryCacheConfig(mapName, request.getCacheName(), cacheId);
} else {
queryCacheConfig = getOrCreateQueryCacheConfig(mapName, request.getCacheName(), cacheId);
queryCacheConfig.setIncludeValue(request.isIncludeValue());
queryCacheConfig.getPredicateConfig().setImplementation(predicate);
}
if (queryCacheConfig == null) {
return null;
}
this.predicate = queryCacheConfig.getPredicateConfig().getImplementation();
return queryCacheConfig;
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class QueryRunner method runPartitionScanQueryOnPartitionChunk.
/**
* Runs a query on a chunk of a single partition. The chunk is defined by
* the {@code pointers} and the soft limit is defined by the {@code fetchSize}.
*
* @param query the query
* @param partitionId the partition which is queried
* @param pointers the pointers defining the state of iteration
* @param fetchSize the soft limit for the number of items to be queried
* @return the queried entries along with the next {@code tableIndex} to resume querying
*/
public ResultSegment runPartitionScanQueryOnPartitionChunk(Query query, int partitionId, IterationPointer[] pointers, int fetchSize) {
MapContainer mapContainer = mapServiceContext.getMapContainer(query.getMapName());
Predicate predicate = queryOptimizer.optimize(query.getPredicate(), mapContainer.getIndexes(partitionId));
QueryableEntriesSegment entries = partitionScanExecutor.execute(query.getMapName(), predicate, partitionId, pointers, fetchSize);
ResultProcessor processor = resultProcessorRegistry.get(query.getResultType());
Result result = processor.populateResult(query, Long.MAX_VALUE, entries.getEntries(), singletonPartitionIdSet(partitionCount, partitionId));
return new ResultSegment(result, entries.getPointers());
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class QueryRunner method runIndexQueryOnOwnedPartitions.
/**
* Performs the given query using indexes.
* <p>
* The method may return a special failure result, which has {@code null}
* {@link Result#getPartitionIds() partition IDs}, in the following
* situations:
* <ul>
* <li>If a partition migration is detected during the query execution.
* <li>If it's impossible to perform the given query using indexes.
* </ul>
* <p>
* The method may be invoked on any thread.
*
* @param query the query to perform.
* @return the result of the query; if the result has {@code null} {@link
* Result#getPartitionIds() partition IDs} this indicates a failure.
*/
public Result runIndexQueryOnOwnedPartitions(Query query) {
int migrationStamp = getMigrationStamp();
PartitionIdSet initialPartitions = mapServiceContext.getOrInitCachedMemberPartitions();
MapContainer mapContainer = mapServiceContext.getMapContainer(query.getMapName());
// to optimize the query we need to get any index instance
Indexes indexes = mapContainer.getIndexes();
if (indexes == null) {
indexes = mapContainer.getIndexes(initialPartitions.iterator().next());
}
// first we optimize the query
Predicate predicate = queryOptimizer.optimize(query.getPredicate(), indexes);
// then we try to run using an index
Iterable<QueryableEntry> entries = runUsingGlobalIndexSafely(predicate, mapContainer, migrationStamp, initialPartitions.size());
Result result;
if (entries == null) {
// failed with index query because of ongoing migrations
result = populateEmptyResult(query, initialPartitions);
} else {
// success
result = populateNonEmptyResult(query, entries, initialPartitions);
}
return result;
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class PredicateBuilderImpl method accept.
@Override
public Predicate accept(Visitor visitor, Indexes indexes) {
Predicate predicate = lsPredicates.get(0);
if (predicate instanceof VisitablePredicate) {
Predicate newPredicate = ((VisitablePredicate) predicate).accept(visitor, indexes);
if (newPredicate != predicate) {
PredicateBuilderImpl newPredicateBuilder = new PredicateBuilderImpl();
newPredicateBuilder.attribute = attribute;
newPredicateBuilder.lsPredicates.addAll(lsPredicates);
newPredicateBuilder.lsPredicates.set(0, newPredicate);
return newPredicateBuilder;
}
}
return this;
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class PredicateBuilderImpl method or.
@Override
public PredicateBuilder or(Predicate predicate) {
if (predicate != PredicateBuilderImpl.this) {
throw new RuntimeException("Illegal or 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.or(first, second));
}
Aggregations