Search in sources :

Example 1 with MapQueryEngine

use of com.hazelcast.map.impl.query.MapQueryEngine in project hazelcast by hazelcast.

the class MapProxyImpl method aggregate.

@Override
public <R> R aggregate(Aggregator<Map.Entry<K, V>, R> aggregator, Predicate<K, V> predicate) {
    checkNotNull(aggregator, NULL_AGGREGATOR_IS_NOT_ALLOWED);
    checkNotNull(predicate, NULL_PREDICATE_IS_NOT_ALLOWED);
    aggregator = serializationService.toObject(serializationService.toData(aggregator));
    MapQueryEngine queryEngine = getMapQueryEngine();
    if (predicate instanceof PagingPredicate) {
        throw new IllegalArgumentException("PagingPredicate now allowed with EntryAggregator.");
    }
    Query query = Query.of().mapName(getName()).predicate(predicate).iterationType(IterationType.ENTRY).aggregator(aggregator).build();
    AggregationResult result = queryEngine.execute(query, Target.ALL_NODES);
    return result.<R>getAggregator().aggregate();
}
Also used : PagingPredicate(com.hazelcast.query.PagingPredicate) Query(com.hazelcast.map.impl.query.Query) AggregationResult(com.hazelcast.map.impl.query.AggregationResult) MapQueryEngine(com.hazelcast.map.impl.query.MapQueryEngine)

Example 2 with MapQueryEngine

use of com.hazelcast.map.impl.query.MapQueryEngine in project hazelcast by hazelcast.

the class MapProxyImpl method aggregate.

@Override
public <R> R aggregate(Aggregator<Map.Entry<K, V>, R> aggregator) {
    checkNotNull(aggregator, NULL_AGGREGATOR_IS_NOT_ALLOWED);
    MapQueryEngine queryEngine = getMapQueryEngine();
    aggregator = serializationService.toObject(serializationService.toData(aggregator));
    Query query = Query.of().mapName(getName()).predicate(TruePredicate.INSTANCE).iterationType(IterationType.ENTRY).aggregator(aggregator).build();
    AggregationResult result = queryEngine.execute(query, Target.ALL_NODES);
    return result.<R>getAggregator().aggregate();
}
Also used : Query(com.hazelcast.map.impl.query.Query) AggregationResult(com.hazelcast.map.impl.query.AggregationResult) MapQueryEngine(com.hazelcast.map.impl.query.MapQueryEngine)

Example 3 with MapQueryEngine

use of com.hazelcast.map.impl.query.MapQueryEngine in project hazelcast by hazelcast.

the class MapProxyImpl method project.

@Override
public <R> Collection<R> project(Projection<Map.Entry<K, V>, R> projection, Predicate<K, V> predicate) {
    checkNotNull(projection, NULL_PROJECTION_IS_NOT_ALLOWED);
    checkNotNull(predicate, NULL_PREDICATE_IS_NOT_ALLOWED);
    projection = serializationService.toObject(serializationService.toData(projection));
    MapQueryEngine queryEngine = getMapQueryEngine();
    Query query = Query.of().mapName(getName()).predicate(predicate).iterationType(IterationType.VALUE).projection(projection).build();
    queryEngine.execute(query, Target.ALL_NODES);
    QueryResult result = queryEngine.execute(query, Target.ALL_NODES);
    return QueryResultUtils.transformToSet(serializationService, result, predicate, IterationType.VALUE, false);
}
Also used : QueryResult(com.hazelcast.map.impl.query.QueryResult) Query(com.hazelcast.map.impl.query.Query) MapQueryEngine(com.hazelcast.map.impl.query.MapQueryEngine)

Example 4 with MapQueryEngine

use of com.hazelcast.map.impl.query.MapQueryEngine in project hazelcast by hazelcast.

the class MapProxyImpl method project.

@Override
public <R> Collection<R> project(Projection<Map.Entry<K, V>, R> projection) {
    checkNotNull(projection, NULL_PROJECTION_IS_NOT_ALLOWED);
    MapQueryEngine queryEngine = getMapQueryEngine();
    projection = serializationService.toObject(serializationService.toData(projection));
    Query query = Query.of().mapName(getName()).predicate(TruePredicate.INSTANCE).iterationType(IterationType.VALUE).projection(projection).build();
    QueryResult result = queryEngine.execute(query, Target.ALL_NODES);
    return QueryResultUtils.transformToSet(serializationService, result, TruePredicate.INSTANCE, IterationType.VALUE, false);
}
Also used : QueryResult(com.hazelcast.map.impl.query.QueryResult) Query(com.hazelcast.map.impl.query.Query) MapQueryEngine(com.hazelcast.map.impl.query.MapQueryEngine)

Example 5 with MapQueryEngine

use of com.hazelcast.map.impl.query.MapQueryEngine in project hazelcast by hazelcast.

the class MapProxyImpl method executePredicate.

private Set executePredicate(Predicate predicate, IterationType iterationType, boolean uniqueResult) {
    checkNotNull(predicate, NULL_PREDICATE_IS_NOT_ALLOWED);
    MapQueryEngine queryEngine = getMapQueryEngine();
    QueryResult result;
    if (predicate instanceof PartitionPredicate) {
        PartitionPredicate partitionPredicate = (PartitionPredicate) predicate;
        Data key = toData(partitionPredicate.getPartitionKey());
        int partitionId = getNodeEngine().getPartitionService().getPartitionId(key);
        Query query = Query.of().mapName(getName()).predicate(partitionPredicate.getTarget()).iterationType(iterationType).build();
        result = queryEngine.execute(query, Target.of().partitionOwner(partitionId).build());
    } else {
        Query query = Query.of().mapName(getName()).predicate(predicate).iterationType(iterationType).build();
        result = queryEngine.execute(query, Target.ALL_NODES);
    }
    return QueryResultUtils.transformToSet(serializationService, result, predicate, iterationType, uniqueResult);
}
Also used : QueryResult(com.hazelcast.map.impl.query.QueryResult) PartitionPredicate(com.hazelcast.query.PartitionPredicate) Query(com.hazelcast.map.impl.query.Query) Data(com.hazelcast.nio.serialization.Data) MapQueryEngine(com.hazelcast.map.impl.query.MapQueryEngine)

Aggregations

MapQueryEngine (com.hazelcast.map.impl.query.MapQueryEngine)5 Query (com.hazelcast.map.impl.query.Query)5 QueryResult (com.hazelcast.map.impl.query.QueryResult)3 AggregationResult (com.hazelcast.map.impl.query.AggregationResult)2 Data (com.hazelcast.nio.serialization.Data)1 PagingPredicate (com.hazelcast.query.PagingPredicate)1 PartitionPredicate (com.hazelcast.query.PartitionPredicate)1