Search in sources :

Example 1 with QueryableEntriesSegment

use of com.hazelcast.query.impl.QueryableEntriesSegment in project hazelcast by hazelcast.

the class PartitionScanRunner method run.

/**
 * Executes the predicate on a partition chunk. The offset in the partition
 * is defined by the {@code pointers} and the soft limit is defined by the
 * {@code fetchSize}. The method returns the matched entries and updated
 * pointers from which new entries can be fetched which allows for efficient
 * iteration of query results.
 * <p>
 * <b>NOTE</b>
 * The iteration may be done when the map is being mutated or when there are
 * membership changes. The iterator does not reflect the state when it has
 * been constructed - it may return some entries that were added after the
 * iteration has started and may not return some entries that were removed
 * after iteration has started.
 * The iterator will not, however, skip an entry if it has not been changed
 * and will not return an entry twice.
 *
 * @param mapName     the map name
 * @param predicate   the predicate which the entries must match
 * @param partitionId the partition which is queried
 * @param pointers    the pointers defining the state of iteration
 * @param fetchSize   the soft limit for the number of entries to fetch
 * @return entries matching the predicate and a table index from which new
 * entries can be fetched
 */
public QueryableEntriesSegment run(String mapName, Predicate predicate, int partitionId, IterationPointer[] pointers, int fetchSize) {
    List<QueryableEntry> resultList = new LinkedList<>();
    PartitionContainer partitionContainer = mapServiceContext.getPartitionContainer(partitionId);
    RecordStore recordStore = partitionContainer.getRecordStore(mapName);
    Extractors extractors = mapServiceContext.getExtractors(mapName);
    while (resultList.size() < fetchSize && pointers[pointers.length - 1].getIndex() >= 0) {
        MapEntriesWithCursor cursor = recordStore.fetchEntries(pointers, fetchSize - resultList.size());
        pointers = cursor.getIterationPointers();
        Collection<? extends Entry<Data, Data>> entries = cursor.getBatch();
        if (entries.isEmpty()) {
            break;
        }
        for (Entry<Data, Data> entry : entries) {
            QueryableEntry queryEntry = new LazyMapEntry(entry.getKey(), entry.getValue(), ss, extractors);
            if (predicate.apply(queryEntry)) {
                resultList.add(queryEntry);
            }
        }
    }
    return new QueryableEntriesSegment(resultList, pointers);
}
Also used : Extractors(com.hazelcast.query.impl.getters.Extractors) PartitionContainer(com.hazelcast.map.impl.PartitionContainer) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) MapEntriesWithCursor(com.hazelcast.map.impl.iterator.MapEntriesWithCursor) LazyMapEntry(com.hazelcast.map.impl.LazyMapEntry) ToHeapDataConverter.toHeapData(com.hazelcast.internal.util.ToHeapDataConverter.toHeapData) Data(com.hazelcast.internal.serialization.Data) QueryableEntriesSegment(com.hazelcast.query.impl.QueryableEntriesSegment) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) LinkedList(java.util.LinkedList)

Example 2 with QueryableEntriesSegment

use of com.hazelcast.query.impl.QueryableEntriesSegment in project hazelcast by hazelcast.

the class QueryRunner method runPartitionScanQueryOnPartitionChunk.

/**
 * Runs a query on a chunk of a single partition. The chunk is defined by
 * the {@code pointers} and the soft limit is defined by the {@code fetchSize}.
 *
 * @param query       the query
 * @param partitionId the partition which is queried
 * @param pointers    the pointers defining the state of iteration
 * @param fetchSize   the soft limit for the number of items to be queried
 * @return the queried entries along with the next {@code tableIndex} to resume querying
 */
public ResultSegment runPartitionScanQueryOnPartitionChunk(Query query, int partitionId, IterationPointer[] pointers, int fetchSize) {
    MapContainer mapContainer = mapServiceContext.getMapContainer(query.getMapName());
    Predicate predicate = queryOptimizer.optimize(query.getPredicate(), mapContainer.getIndexes(partitionId));
    QueryableEntriesSegment entries = partitionScanExecutor.execute(query.getMapName(), predicate, partitionId, pointers, fetchSize);
    ResultProcessor processor = resultProcessorRegistry.get(query.getResultType());
    Result result = processor.populateResult(query, Long.MAX_VALUE, entries.getEntries(), singletonPartitionIdSet(partitionCount, partitionId));
    return new ResultSegment(result, entries.getPointers());
}
Also used : QueryableEntriesSegment(com.hazelcast.query.impl.QueryableEntriesSegment) MapContainer(com.hazelcast.map.impl.MapContainer) Predicate(com.hazelcast.query.Predicate)

Aggregations

QueryableEntriesSegment (com.hazelcast.query.impl.QueryableEntriesSegment)2 Data (com.hazelcast.internal.serialization.Data)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 MapEntriesWithCursor (com.hazelcast.map.impl.iterator.MapEntriesWithCursor)1 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)1 Predicate (com.hazelcast.query.Predicate)1 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)1 Extractors (com.hazelcast.query.impl.getters.Extractors)1 LinkedList (java.util.LinkedList)1