Search in sources :

Example 76 with Predicate

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));
}
Also used : PredicateTestUtils.createMockVisitablePredicate(com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockVisitablePredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 77 with Predicate

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);
}
Also used : QueryEventFilter(com.hazelcast.map.impl.query.QueryEventFilter) EventListenerFilter(com.hazelcast.map.impl.EventListenerFilter) Predicate(com.hazelcast.query.Predicate)

Example 78 with Predicate

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()));
    }
}
Also used : MapContainer(com.hazelcast.map.impl.MapContainer) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) Predicate(com.hazelcast.query.Predicate)

Example 79 with Predicate

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);
}
Also used : PredicateConfig(com.hazelcast.config.PredicateConfig) SqlPredicate(com.hazelcast.query.SqlPredicate) Predicate(com.hazelcast.query.Predicate)

Example 80 with 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;
}
Also used : QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Predicate(com.hazelcast.query.Predicate)

Aggregations

Predicate (com.hazelcast.query.Predicate)160 Test (org.junit.Test)125 QuickTest (com.hazelcast.test.annotation.QuickTest)124 ParallelTest (com.hazelcast.test.annotation.ParallelTest)107 TruePredicate (com.hazelcast.query.TruePredicate)41 SqlPredicate (com.hazelcast.query.SqlPredicate)33 HazelcastInstance (com.hazelcast.core.HazelcastInstance)26 FalsePredicate (com.hazelcast.query.impl.FalsePredicate)23 PredicateBuilder (com.hazelcast.query.PredicateBuilder)19 EntryListener (com.hazelcast.core.EntryListener)16 MapListener (com.hazelcast.map.listener.MapListener)16 EntryObject (com.hazelcast.query.EntryObject)14 IndexAwarePredicate (com.hazelcast.query.IndexAwarePredicate)12 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)10 Value (com.hazelcast.query.SampleObjects.Value)9 PredicateTestUtils.createMockVisitablePredicate (com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockVisitablePredicate)9 ArrayList (java.util.ArrayList)9 EntryEvent (com.hazelcast.core.EntryEvent)8 MapListenerAdapter (com.hazelcast.map.impl.MapListenerAdapter)8 ValueType (com.hazelcast.query.SampleObjects.ValueType)7