use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class VisitorUtilsTest method acceptVisitor_whenThereIsChange_thenReturnNewArray.
@Test
public void acceptVisitor_whenThereIsChange_thenReturnNewArray() {
Visitor mockVisitor = mock(Visitor.class);
Predicate[] predicates = new Predicate[2];
Predicate p1 = createMockVisitablePredicate();
predicates[0] = p1;
Predicate transformed = mock(Predicate.class);
Predicate p2 = createMockVisitablePredicate(transformed);
predicates[1] = p2;
Predicate[] result = VisitorUtils.acceptVisitor(predicates, mockVisitor, mockIndexes);
assertThat(result, not(sameInstance(predicates)));
assertThat(result, arrayWithSize(2));
assertThat(result, arrayContainingInAnyOrder(p1, transformed));
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class MapAddEntryListenerWithPredicateMessageTask method getEventFilter.
@Override
protected EventFilter getEventFilter() {
Predicate predicate = serializationService.toObject(parameters.predicate);
QueryEventFilter eventFilter = new QueryEventFilter(parameters.includeValue, null, predicate);
return new EventListenerFilter(parameters.listenerFlags, eventFilter);
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class QueryRunner method runIndexOrPartitionScanQueryOnOwnedPartitions.
// full query = index query (if possible), then partition-scan query
public Result runIndexOrPartitionScanQueryOnOwnedPartitions(Query query) throws ExecutionException, InterruptedException {
int migrationStamp = getMigrationStamp();
Collection<Integer> initialPartitions = mapServiceContext.getOwnedPartitions();
MapContainer mapContainer = mapServiceContext.getMapContainer(query.getMapName());
// first we optimize the query
Predicate predicate = queryOptimizer.optimize(query.getPredicate(), mapContainer.getIndexes());
// then we try to run using an index, but if that doesn't work, we'll try a full table scan
// This would be the point where a query-plan should be added. It should determine f a full table scan
// or an index should be used.
Collection<QueryableEntry> entries = runUsingIndexSafely(predicate, mapContainer, migrationStamp);
if (entries == null) {
entries = runUsingPartitionScanSafely(query.getMapName(), predicate, initialPartitions, migrationStamp);
}
updateStatistics(mapContainer);
if (entries != null) {
// so that caller is aware of partitions from which results were obtained.
return populateTheResult(query, entries, initialPartitions);
} else {
// then return empty result set without any partition IDs set (so that it is ignored by callers).
return resultProcessorRegistry.get(query.getResultType()).populateResult(query, queryResultSizeLimiter.getNodeResultLimit(initialPartitions.size()));
}
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class AbstractQueryCacheConfigurator method setPredicateImpl.
protected void setPredicateImpl(QueryCacheConfig config) {
PredicateConfig predicateConfig = config.getPredicateConfig();
if (predicateConfig.getImplementation() != null) {
return;
}
Predicate predicate = getPredicate(predicateConfig);
if (predicate == null) {
return;
}
predicateConfig.setImplementation(predicate);
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class AbstractQueryCacheEndToEndConstructor method initQueryCacheConfig.
protected QueryCacheConfig initQueryCacheConfig(QueryCacheRequest request) {
Predicate predicate = request.getPredicate();
QueryCacheConfig queryCacheConfig;
if (predicate == null) {
queryCacheConfig = getOrNullQueryCacheConfig(mapName, request.getUserGivenCacheName());
} else {
queryCacheConfig = getOrCreateQueryCacheConfig(mapName, request.getUserGivenCacheName());
queryCacheConfig.setIncludeValue(request.isIncludeValue());
queryCacheConfig.getPredicateConfig().setImplementation(predicate);
}
if (queryCacheConfig == null) {
return null;
}
// init some required parameters
this.includeValue = queryCacheConfig.isIncludeValue();
this.predicate = queryCacheConfig.getPredicateConfig().getImplementation();
return queryCacheConfig;
}
Aggregations