use of org.apache.ignite.internal.cache.query.index.sorted.inline.IndexQueryContext in project ignite by apache.
the class H2TreeIndex method findFirstOrLast.
/**
* {@inheritDoc}
*/
@Override
public Cursor findFirstOrLast(Session ses, boolean b) {
try {
QueryContext qctx = H2Utils.context(ses);
IndexQueryContext qryCtx = idxQryContext(qctx);
GridCursor<IndexRow> cursor = b ? queryIndex.findFirst(segment(qctx), qryCtx) : queryIndex.findLast(segment(qctx), qryCtx);
return new H2Cursor(new IndexValueCursor<>(cursor, this::mapIndexRow));
} catch (IgniteCheckedException e) {
throw DbException.convert(e);
}
}
use of org.apache.ignite.internal.cache.query.index.sorted.inline.IndexQueryContext in project ignite by apache.
the class IndexQueryProcessor method querySortedIndex.
/**
* Runs an index query.
*
* @return Result cursor.
*/
private GridCursor<IndexRow> querySortedIndex(GridCacheContext<?, ?> cctx, SortedSegmentedIndex idx, IndexingQueryFilter cacheFilter, IndexRangeQuery qry) throws IgniteCheckedException {
int segmentsCnt = cctx.isPartitioned() ? cctx.config().getQueryParallelism() : 1;
BPlusTree.TreeRowClosure<IndexRow, IndexRow> treeFilter = null;
// Also skips filtering if the current search is unbounded (both boundaries equal to null).
if (qry.criteria.length > 1 && !(qry.lower == null && qry.upper == null)) {
LinkedHashMap<String, IndexKeyDefinition> idxDef = idxProc.indexDefinition(idx.id()).indexKeyDefinitions();
treeFilter = new IndexQueryCriteriaClosure(qry, idxDef, ((SortedIndexDefinition) idxProc.indexDefinition(idx.id())).rowComparator());
}
IndexQueryContext qryCtx = new IndexQueryContext(cacheFilter, treeFilter, null);
if (segmentsCnt == 1)
return treeIndexRange(idx, 0, qry, qryCtx);
final GridCursor<IndexRow>[] segmentCursors = new GridCursor[segmentsCnt];
// Actually it just traverses BPlusTree to find boundaries. It's too fast to parallelize this.
for (int i = 0; i < segmentsCnt; i++) segmentCursors[i] = treeIndexRange(idx, i, qry, qryCtx);
return new SegmentedIndexCursor(segmentCursors, (SortedIndexDefinition) idxProc.indexDefinition(idx.id()));
}
Aggregations