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;
}
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);
}
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);
}
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);
}
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;
}
Aggregations