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