use of com.hazelcast.map.impl.query.QueryEngine 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");
QueryEngine queryEngine = mapServiceContext.getQueryEngine(name);
Query query = Query.of().mapName(name).predicate(predicate).iterationType(IterationType.ENTRY).build();
QueryResult queryResult = queryEngine.execute(query, Target.ALL_NODES);
Set result = QueryResultUtils.transformToSet(ss, queryResult, predicate, IterationType.ENTRY, true, true);
// TODO: can't we just use the original set?
List<Object> valueSet = new ArrayList<>();
Set<Data> keyWontBeIncluded = new HashSet<>();
Extractors extractors = mapServiceContext.getExtractors(name);
CachedQueryEntry cachedQueryEntry = new CachedQueryEntry();
// 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);
if (isRemoved) {
keyWontBeIncluded.add(entry.getKey());
} else {
if (isUpdated) {
keyWontBeIncluded.add(entry.getKey());
}
Object entryValue = entry.getValue().value;
cachedQueryEntry.init(ss, entry.getKey(), entryValue, extractors);
if (predicate.apply(cachedQueryEntry)) {
valueSet.add(toObjectIfNeeded(cachedQueryEntry.getValueData()));
}
}
}
removeFromResultSet(result, valueSet, keyWontBeIncluded);
return valueSet;
}
use of com.hazelcast.map.impl.query.QueryEngine in project hazelcast by hazelcast.
the class PublisherCreateOperation method runInitialQuery.
private QueryResult runInitialQuery() {
QueryEngine queryEngine = getMapServiceContext().getQueryEngine(name);
IterationType iterationType = info.isIncludeValue() ? IterationType.ENTRY : IterationType.KEY;
Query query = Query.of().mapName(name).predicate(info.getPredicate()).iterationType(iterationType).build();
return queryEngine.execute(query, Target.LOCAL_NODE);
}
use of com.hazelcast.map.impl.query.QueryEngine in project hazelcast by hazelcast.
the class TransactionalMapProxy method keySet.
@Override
@SuppressWarnings("unchecked")
public Set keySet(Predicate predicate) {
checkTransactionState();
checkNotNull(predicate, "Predicate should not be null!");
checkNotInstanceOf(PagingPredicate.class, predicate, "Paging is not supported for Transactional queries!");
QueryEngine queryEngine = mapServiceContext.getQueryEngine(name);
Query query = Query.of().mapName(name).predicate(predicate).iterationType(IterationType.KEY).build();
QueryResult queryResult = queryEngine.execute(query, Target.ALL_NODES);
Set queryResultSet = QueryResultUtils.transformToSet(ss, queryResult, predicate, IterationType.KEY, true, tx.isOriginatedFromClient());
Extractors extractors = mapServiceContext.getExtractors(name);
Set<Object> returningKeySet = new HashSet<Object>(queryResultSet);
CachedQueryEntry cachedQueryEntry = new CachedQueryEntry();
for (Map.Entry<Data, TxnValueWrapper> entry : txMap.entrySet()) {
if (entry.getValue().type == Type.REMOVED) {
// meanwhile remove keys which are not in txMap
returningKeySet.remove(toObjectIfNeeded(entry.getKey()));
} else {
Data keyData = entry.getKey();
if (predicate == Predicates.alwaysTrue()) {
returningKeySet.add(toObjectIfNeeded(keyData));
} else {
cachedQueryEntry.init(ss, keyData, entry.getValue().value, extractors);
// apply predicate on txMap
if (predicate.apply(cachedQueryEntry)) {
returningKeySet.add(toObjectIfNeeded(keyData));
}
}
}
}
return returningKeySet;
}
use of com.hazelcast.map.impl.query.QueryEngine in project hazelcast by hazelcast.
the class MapProxySupport method executeQueryInternal.
protected <T extends Result> T executeQueryInternal(Predicate predicate, Aggregator aggregator, Projection projection, IterationType iterationType, Target target) {
QueryEngine queryEngine = getMapQueryEngine();
final Predicate userPredicate;
if (predicate instanceof PartitionPredicate) {
PartitionPredicate partitionPredicate = (PartitionPredicate) predicate;
Data key = toData(partitionPredicate.getPartitionKey());
int partitionId = partitionService.getPartitionId(key);
if (target.mode() == TargetMode.LOCAL_NODE && !partitionService.isPartitionOwner(partitionId) || target.mode() == TargetMode.PARTITION_OWNER && !target.partitions().contains(partitionId)) {
userPredicate = alwaysFalse();
} else {
target = createPartitionTarget(new PartitionIdSet(partitionService.getPartitionCount(), partitionId));
userPredicate = partitionPredicate.getTarget();
}
} else {
userPredicate = predicate;
}
handleHazelcastInstanceAwareParams(userPredicate);
Query query = Query.of().mapName(getName()).predicate(userPredicate).iterationType(iterationType).aggregator(aggregator).projection(projection).build();
return queryEngine.execute(query, target);
}
Aggregations