Search in sources :

Example 1 with QueryResult

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

the class DefaultMapProjectMessageTask method reduce.

@Override
protected List<Data> reduce(Collection<QueryResult> results) {
    if (results.isEmpty()) {
        return Collections.emptyList();
    }
    QueryResult combinedResult = null;
    for (QueryResult result : results) {
        if (combinedResult == null) {
            combinedResult = result;
        } else {
            combinedResult.combine(result);
        }
    }
    Set result = QueryResultUtils.transformToSet(nodeEngine.getSerializationService(), combinedResult, getPredicate(), IterationType.VALUE, false);
    List<Data> serialized = new ArrayList<Data>(result.size());
    SerializationService serializationService = nodeEngine.getSerializationService();
    for (Object row : result) {
        serialized.add(serializationService.toData(row));
    }
    return serialized;
}
Also used : QueryResult(com.hazelcast.map.impl.query.QueryResult) Set(java.util.Set) ArrayList(java.util.ArrayList) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data)

Example 2 with QueryResult

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

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

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

the class NodeQueryCacheEndToEndConstructor method createPublishersAndGetQueryResults.

private Collection<QueryResult> createPublishersAndGetQueryResults(AccumulatorInfo info) {
    InvokerWrapper invokerWrapper = context.getInvokerWrapper();
    Collection<Member> members = context.getMemberList();
    List<Future<QueryResult>> futures = new ArrayList<Future<QueryResult>>(members.size());
    for (Member member : members) {
        Address address = member.getAddress();
        Future future = invokerWrapper.invokeOnTarget(new PublisherCreateOperation(info), address);
        futures.add(future);
    }
    return returnWithDeadline(futures, OPERATION_WAIT_TIMEOUT_MINUTES, MINUTES);
}
Also used : QueryResult(com.hazelcast.map.impl.query.QueryResult) Address(com.hazelcast.nio.Address) InvokerWrapper(com.hazelcast.map.impl.querycache.InvokerWrapper) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Member(com.hazelcast.core.Member) PublisherCreateOperation(com.hazelcast.map.impl.querycache.subscriber.operation.PublisherCreateOperation)

Example 5 with QueryResult

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

the class TransactionalMapProxy method values.

@Override
@SuppressWarnings("unchecked")
public Collection values(Predicate predicate) {
    checkTransactionState();
    checkNotNull(predicate, "Predicate can not be null!");
    checkNotInstanceOf(PagingPredicate.class, predicate, "Paging is not supported for Transactional queries");
    MapQueryEngine queryEngine = mapServiceContext.getMapQueryEngine(name);
    SerializationService serializationService = getNodeEngine().getSerializationService();
    Query query = Query.of().mapName(name).predicate(predicate).iterationType(IterationType.ENTRY).build();
    QueryResult queryResylt = queryEngine.execute(query, Target.ALL_NODES);
    Set result = QueryResultUtils.transformToSet(serializationService, queryResylt, predicate, IterationType.ENTRY, true);
    // TODO: Can't we just use the original set?
    List<Object> valueSet = new ArrayList<Object>();
    Set<Object> keyWontBeIncluded = new HashSet<Object>();
    Extractors extractors = mapServiceContext.getExtractors(name);
    // iterate over the txMap and see if the values are updated or removed
    for (Map.Entry<Data, TxnValueWrapper> entry : txMap.entrySet()) {
        boolean isRemoved = Type.REMOVED.equals(entry.getValue().type);
        boolean isUpdated = Type.UPDATED.equals(entry.getValue().type);
        Object keyObject = serializationService.toObject(entry.getKey());
        if (isRemoved) {
            keyWontBeIncluded.add(keyObject);
        } else {
            if (isUpdated) {
                keyWontBeIncluded.add(keyObject);
            }
            Object entryValue = entry.getValue().value;
            QueryableEntry queryEntry = new CachedQueryEntry((InternalSerializationService) serializationService, entry.getKey(), entryValue, extractors);
            if (predicate.apply(queryEntry)) {
                valueSet.add(queryEntry.getValue());
            }
        }
    }
    removeFromResultSet(result, valueSet, keyWontBeIncluded);
    return valueSet;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Query(com.hazelcast.map.impl.query.Query) ArrayList(java.util.ArrayList) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) QueryResult(com.hazelcast.map.impl.query.QueryResult) Extractors(com.hazelcast.query.impl.getters.Extractors) MapQueryEngine(com.hazelcast.map.impl.query.MapQueryEngine) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) HashMap(java.util.HashMap) Map(java.util.Map) TransactionalMap(com.hazelcast.core.TransactionalMap) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) HashSet(java.util.HashSet)

Aggregations

QueryResult (com.hazelcast.map.impl.query.QueryResult)13 Query (com.hazelcast.map.impl.query.Query)7 Data (com.hazelcast.nio.serialization.Data)7 MapQueryEngine (com.hazelcast.map.impl.query.MapQueryEngine)6 QueryResultRow (com.hazelcast.map.impl.query.QueryResultRow)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 TransactionalMap (com.hazelcast.core.TransactionalMap)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 SerializationService (com.hazelcast.spi.serialization.SerializationService)2 Set (java.util.Set)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 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