Search in sources :

Example 1 with Query

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

the class AbstractMapQueryMessageTask method createInvocationsForMissingPartitions.

private void createInvocationsForMissingPartitions(List<Integer> missingPartitionsList, List<Future> futures, Predicate predicate) {
    final InternalOperationService operationService = nodeEngine.getOperationService();
    Query query = buildQuery(predicate);
    for (Integer partitionId : missingPartitionsList) {
        QueryPartitionOperation queryPartitionOperation = new QueryPartitionOperation(query);
        queryPartitionOperation.setPartitionId(partitionId);
        try {
            Future future = operationService.invokeOnPartition(SERVICE_NAME, queryPartitionOperation, partitionId);
            futures.add(future);
        } catch (Throwable t) {
            throw rethrow(t);
        }
    }
}
Also used : Query(com.hazelcast.map.impl.query.Query) Future(java.util.concurrent.Future) QueryPartitionOperation(com.hazelcast.map.impl.query.QueryPartitionOperation) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService)

Example 2 with Query

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

the class AbstractMapQueryMessageTask method createInvocations.

private List<Future> createInvocations(Collection<Member> members, Predicate predicate) {
    List<Future> futures = new ArrayList<Future>(members.size());
    final InternalOperationService operationService = nodeEngine.getOperationService();
    final Query query = buildQuery(predicate);
    for (Member member : members) {
        try {
            Future future = operationService.createInvocationBuilder(SERVICE_NAME, new QueryOperation(query), member.getAddress()).invoke();
            futures.add(future);
        } catch (Throwable t) {
            if (t.getCause() instanceof QueryResultSizeExceededException) {
                throw rethrow(t);
            } else {
                // the missing partition IDs will be queried anyway, so it's not a terminal failure
                if (logger.isFineEnabled()) {
                    logger.fine("Query invocation failed on member " + member, t);
                }
            }
        }
    }
    return futures;
}
Also used : Query(com.hazelcast.map.impl.query.Query) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) QueryResultSizeExceededException(com.hazelcast.map.QueryResultSizeExceededException) Member(com.hazelcast.core.Member) QueryOperation(com.hazelcast.map.impl.query.QueryOperation)

Example 3 with Query

use of com.hazelcast.map.impl.query.Query 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 4 with Query

use of com.hazelcast.map.impl.query.Query 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 5 with Query

use of com.hazelcast.map.impl.query.Query 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)

Aggregations

Query (com.hazelcast.map.impl.query.Query)12 MapQueryEngine (com.hazelcast.map.impl.query.MapQueryEngine)9 QueryResult (com.hazelcast.map.impl.query.QueryResult)7 Data (com.hazelcast.nio.serialization.Data)3 TransactionalMap (com.hazelcast.core.TransactionalMap)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 AggregationResult (com.hazelcast.map.impl.query.AggregationResult)2 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)2 ArrayList (java.util.ArrayList)2 Future (java.util.concurrent.Future)2 MapAssignAndGetUuidsOperation (com.hazelcast.client.impl.protocol.task.map.MapAssignAndGetUuidsOperation)1 MapAssignAndGetUuidsOperationFactory (com.hazelcast.client.impl.protocol.task.map.MapAssignAndGetUuidsOperationFactory)1 Member (com.hazelcast.core.Member)1 BatchNearCacheInvalidation (com.hazelcast.internal.nearcache.impl.invalidation.BatchNearCacheInvalidation)1 SingleNearCacheInvalidation (com.hazelcast.internal.nearcache.impl.invalidation.SingleNearCacheInvalidation)1 ArrayDataSerializableFactory (com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory)1 QueryResultSizeExceededException (com.hazelcast.map.QueryResultSizeExceededException)1 MapEntriesWithCursor (com.hazelcast.map.impl.iterator.MapEntriesWithCursor)1 MapKeysWithCursor (com.hazelcast.map.impl.iterator.MapKeysWithCursor)1 UuidFilter (com.hazelcast.map.impl.nearcache.invalidation.UuidFilter)1