Search in sources :

Example 1 with PagingPredicateImpl

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);
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) PagingPredicateImpl(com.hazelcast.query.impl.predicates.PagingPredicateImpl)

Example 2 with PagingPredicateImpl

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;
}
Also used : CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) AbstractMap(java.util.AbstractMap) Map(java.util.Map) PagingPredicateImpl(com.hazelcast.query.impl.predicates.PagingPredicateImpl)

Example 3 with PagingPredicateImpl

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);
}
Also used : PartitionContainer(com.hazelcast.map.impl.PartitionContainer) ToHeapDataConverter.toHeapData(com.hazelcast.internal.util.ToHeapDataConverter.toHeapData) Data(com.hazelcast.internal.serialization.Data) MapContainer(com.hazelcast.map.impl.MapContainer) Extractors(com.hazelcast.query.impl.getters.Extractors) LazyMapEntry(com.hazelcast.map.impl.LazyMapEntry) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) Entry(java.util.Map.Entry) LazyMapEntry(com.hazelcast.map.impl.LazyMapEntry) Record(com.hazelcast.map.impl.record.Record) Map(java.util.Map) PagingPredicateImpl(com.hazelcast.query.impl.predicates.PagingPredicateImpl)

Example 4 with PagingPredicateImpl

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);
}
Also used : IterationType(com.hazelcast.internal.util.IterationType) PartitionPredicateImpl(com.hazelcast.query.impl.predicates.PartitionPredicateImpl) AbstractMap(java.util.AbstractMap) Map(java.util.Map) PartitionPredicate(com.hazelcast.query.PartitionPredicate) Predicate(com.hazelcast.query.Predicate) Comparator(java.util.Comparator) PagingPredicateImpl(com.hazelcast.query.impl.predicates.PagingPredicateImpl)

Example 5 with PagingPredicateImpl

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);
}
Also used : Data(com.hazelcast.internal.serialization.Data) PagingPredicateImpl(com.hazelcast.query.impl.predicates.PagingPredicateImpl)

Aggregations

PagingPredicateImpl (com.hazelcast.query.impl.predicates.PagingPredicateImpl)13 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)5 Map (java.util.Map)5 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)3 PagingPredicateHolder (com.hazelcast.client.impl.protocol.codec.holder.PagingPredicateHolder)3 CachedQueryEntry (com.hazelcast.query.impl.CachedQueryEntry)3 AbstractMap (java.util.AbstractMap)3 Data (com.hazelcast.internal.serialization.Data)2 SerializationService (com.hazelcast.internal.serialization.SerializationService)2 IterationType (com.hazelcast.internal.util.IterationType)2 Predicate (com.hazelcast.query.Predicate)2 MapEntriesWithPagingPredicateCodec (com.hazelcast.client.impl.protocol.codec.MapEntriesWithPagingPredicateCodec)1 MapKeySetWithPagingPredicateCodec (com.hazelcast.client.impl.protocol.codec.MapKeySetWithPagingPredicateCodec)1 MapValuesWithPagingPredicateCodec (com.hazelcast.client.impl.protocol.codec.MapValuesWithPagingPredicateCodec)1 CollectionUtil.objectToDataCollection (com.hazelcast.internal.util.CollectionUtil.objectToDataCollection)1 ToHeapDataConverter.toHeapData (com.hazelcast.internal.util.ToHeapDataConverter.toHeapData)1 LazyMapEntry (com.hazelcast.map.impl.LazyMapEntry)1 MapContainer (com.hazelcast.map.impl.MapContainer)1 PartitionContainer (com.hazelcast.map.impl.PartitionContainer)1 Record (com.hazelcast.map.impl.record.Record)1