Search in sources :

Example 1 with QueryOptimizer

use of com.hazelcast.query.impl.predicates.QueryOptimizer in project hazelcast by hazelcast.

the class PartitionWideEntryWithPredicateOperationFactory method getKeysFromIndex.

private Set<Data> getKeysFromIndex(NodeEngine nodeEngine) {
    // Do not use index in this case, because it requires full-table-scan.
    if (predicate == TruePredicate.INSTANCE) {
        return emptySet();
    }
    // get indexes
    MapService mapService = nodeEngine.getService(SERVICE_NAME);
    MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    Indexes indexes = mapServiceContext.getMapContainer(name).getIndexes();
    // optimize predicate
    QueryOptimizer queryOptimizer = mapServiceContext.getQueryOptimizer();
    predicate = queryOptimizer.optimize(predicate, indexes);
    Set<QueryableEntry> querySet = indexes.query(predicate);
    if (querySet == null) {
        return emptySet();
    }
    List<Data> keys = null;
    for (QueryableEntry e : querySet) {
        if (keys == null) {
            keys = new ArrayList<Data>(querySet.size());
        }
        keys.add(e.getKeyData());
    }
    return keys == null ? Collections.<Data>emptySet() : newBuilder(keys).build();
}
Also used : Data(com.hazelcast.nio.serialization.Data) QueryOptimizer(com.hazelcast.query.impl.predicates.QueryOptimizer) MapService(com.hazelcast.map.impl.MapService) Indexes(com.hazelcast.query.impl.Indexes) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Aggregations

MapService (com.hazelcast.map.impl.MapService)1 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)1 Data (com.hazelcast.nio.serialization.Data)1 Indexes (com.hazelcast.query.impl.Indexes)1 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)1 QueryOptimizer (com.hazelcast.query.impl.predicates.QueryOptimizer)1