use of com.hazelcast.query.impl.predicates.PagingPredicateImpl in project hazelcast by hazelcast.
the class AbstractMapQueryWithPagingPredicateMessageTask method reduce.
@Override
protected Object reduce(Collection<QueryResultRow> result) {
ArrayList<QueryableEntry> accumulatedList = new ArrayList<>(result.size());
// TODO: The following lines will be replaced by k-way merge sort algorithm as described at
// https://github.com/hazelcast/hazelcast/issues/12205
result.forEach(row -> accumulatedList.add(new CachedQueryEntry(serializationService, row.getKey(), row.getValue(), null)));
PagingPredicateImpl pagingPredicateImpl = getPagingPredicate();
List pageData = SortingUtil.getSortedSubListData(accumulatedList, pagingPredicateImpl);
return new AbstractMap.SimpleImmutableEntry(getPagingPredicate().getAnchorList(), pageData);
}
use of com.hazelcast.query.impl.predicates.PagingPredicateImpl in project hazelcast by hazelcast.
the class SortingUtil method compareAnchor.
public static boolean compareAnchor(PagingPredicate pagingPredicate, QueryableEntry queryEntry, Map.Entry<Integer, Map.Entry> nearestAnchorEntry) {
if (pagingPredicate == null) {
return true;
}
Map.Entry anchor = nearestAnchorEntry.getValue();
if (anchor == null) {
return true;
}
PagingPredicateImpl pagingPredicateImpl = (PagingPredicateImpl) pagingPredicate;
Comparator<Map.Entry> comparator = pagingPredicate.getComparator();
IterationType iterationType = pagingPredicateImpl.getIterationType();
return SortingUtil.compare(comparator, iterationType, anchor, queryEntry) < 0;
}
use of com.hazelcast.query.impl.predicates.PagingPredicateImpl in project hazelcast by hazelcast.
the class PartitionScanRunner method run.
@SuppressWarnings("unchecked")
public void run(String mapName, Predicate predicate, int partitionId, Result result) {
PagingPredicateImpl pagingPredicate = predicate instanceof PagingPredicateImpl ? (PagingPredicateImpl) predicate : null;
PartitionContainer partitionContainer = mapServiceContext.getPartitionContainer(partitionId);
MapContainer mapContainer = mapServiceContext.getMapContainer(mapName);
RecordStore<Record> recordStore = partitionContainer.getRecordStore(mapName);
boolean nativeMemory = recordStore.getInMemoryFormat() == InMemoryFormat.NATIVE;
boolean useCachedValues = isUseCachedDeserializedValuesEnabled(mapContainer, partitionId);
Extractors extractors = mapServiceContext.getExtractors(mapName);
Map.Entry<Integer, Map.Entry> nearestAnchorEntry = pagingPredicate == null ? null : pagingPredicate.getNearestAnchorEntry();
recordStore.forEachAfterLoad(new BiConsumer<Data, Record>() {
LazyMapEntry queryEntry = new LazyMapEntry();
@Override
public void accept(Data key, Record record) {
Object value = useCachedValues ? getValueOrCachedValue(record, ss) : record.getValue();
// TODO how can a value be null?
if (value == null) {
return;
}
queryEntry.init(ss, key, value, extractors);
queryEntry.setRecord(record);
queryEntry.setMetadata(recordStore.getOrCreateMetadataStore().get(key));
if (predicate.apply(queryEntry) && compareAnchor(pagingPredicate, queryEntry, nearestAnchorEntry)) {
// always copy key&value to heap if map is backed by native memory
value = nativeMemory ? toHeapData((Data) value) : value;
result.add(queryEntry.init(ss, toHeapData(key), value, extractors));
// We can't reuse the existing entry after it was added to the
// result. Allocate the new one.
queryEntry = new LazyMapEntry();
}
}
}, false);
result.orderAndLimit(pagingPredicate, nearestAnchorEntry);
}
use of com.hazelcast.query.impl.predicates.PagingPredicateImpl in project hazelcast by hazelcast.
the class PagingPredicateHolder method asPredicate.
public <K, V> Predicate<K, V> asPredicate(SerializationService serializationService) {
List<Map.Entry<Integer, Map.Entry<K, V>>> anchorList = anchorDataListHolder.asAnchorList(serializationService);
Predicate predicate = serializationService.toObject(predicateData);
Comparator comparator = serializationService.toObject(comparatorData);
IterationType iterationType = IterationType.getById(iterationTypeId);
PagingPredicateImpl<K, V> pagingPredicate = new PagingPredicateImpl<K, V>(anchorList, predicate, comparator, pageSize, page, iterationType);
if (partitionKeyData == null) {
return pagingPredicate;
}
return new PartitionPredicateImpl<>(serializationService.toObject(partitionKeyData), pagingPredicate);
}
use of com.hazelcast.query.impl.predicates.PagingPredicateImpl in project hazelcast by hazelcast.
the class PagingPredicateHolder method ofInternal.
private static <K, V> PagingPredicateHolder ofInternal(@Nonnull PartitionPredicate<K, V> partitionPredicate, SerializationService serializationService) {
PagingPredicateImpl<K, V> pagingPredicate = (PagingPredicateImpl<K, V>) partitionPredicate.getTarget();
Data partitionKeyData = serializationService.toData(partitionPredicate.getPartitionKey());
return buildHolder(serializationService, pagingPredicate, partitionKeyData);
}
Aggregations