Search in sources :

Example 6 with OffsetResultIterator

use of org.apache.phoenix.iterate.OffsetResultIterator in project phoenix by apache.

the class UnionPlan method iterator.

@Override
public final ResultIterator iterator(ParallelScanGrouper scanGrouper, Scan scan) throws SQLException {
    this.iterators = new UnionResultIterators(plans, parentContext);
    ResultIterator scanner;
    boolean isOrdered = !orderBy.getOrderByExpressions().isEmpty();
    if (isOrdered) {
        // TopN
        scanner = new MergeSortTopNResultIterator(iterators, limit, offset, orderBy.getOrderByExpressions());
    } else {
        scanner = new ConcatResultIterator(iterators);
        if (offset != null) {
            scanner = new OffsetResultIterator(scanner, offset);
        }
        if (limit != null) {
            scanner = new LimitingResultIterator(scanner, limit);
        }
    }
    return scanner;
}
Also used : OffsetResultIterator(org.apache.phoenix.iterate.OffsetResultIterator) UnionResultIterators(org.apache.phoenix.iterate.UnionResultIterators) MergeSortTopNResultIterator(org.apache.phoenix.iterate.MergeSortTopNResultIterator) LimitingResultIterator(org.apache.phoenix.iterate.LimitingResultIterator) OffsetResultIterator(org.apache.phoenix.iterate.OffsetResultIterator) ConcatResultIterator(org.apache.phoenix.iterate.ConcatResultIterator) ResultIterator(org.apache.phoenix.iterate.ResultIterator) MergeSortTopNResultIterator(org.apache.phoenix.iterate.MergeSortTopNResultIterator) LimitingResultIterator(org.apache.phoenix.iterate.LimitingResultIterator) ConcatResultIterator(org.apache.phoenix.iterate.ConcatResultIterator)

Example 7 with OffsetResultIterator

use of org.apache.phoenix.iterate.OffsetResultIterator in project phoenix by apache.

the class ScanPlan method newIterator.

@Override
protected ResultIterator newIterator(ParallelScanGrouper scanGrouper, Scan scan, Map<ImmutableBytesPtr, ServerCache> caches) throws SQLException {
    // Set any scan attributes before creating the scanner, as it will be too late afterwards
    scan.setAttribute(BaseScannerRegionObserver.NON_AGGREGATE_QUERY, QueryConstants.TRUE);
    ResultIterator scanner;
    TableRef tableRef = this.getTableRef();
    PTable table = tableRef.getTable();
    boolean isSalted = table.getBucketNum() != null;
    /* If no limit or topN, use parallel iterator so that we get results faster. Otherwise, if
         * limit is provided, run query serially.
         */
    boolean isOrdered = !orderBy.getOrderByExpressions().isEmpty();
    Integer perScanLimit = !allowPageFilter || isOrdered ? null : QueryUtil.getOffsetLimit(limit, offset);
    boolean isOffsetOnServer = isOffsetPossibleOnServer(context, orderBy, offset, isSalted, table.getIndexType());
    /*
         * For queries that are doing a row key order by and are not possibly querying more than a
         * threshold worth of data, then we only need to initialize scanners corresponding to the
         * first (or last, if reverse) scan per region.
         */
    boolean initFirstScanOnly = (orderBy == OrderBy.FWD_ROW_KEY_ORDER_BY || orderBy == OrderBy.REV_ROW_KEY_ORDER_BY) && isDataToScanWithinThreshold;
    BaseResultIterators iterators;
    if (isOffsetOnServer) {
        iterators = new SerialIterators(this, perScanLimit, offset, parallelIteratorFactory, scanGrouper, scan, caches, dataPlan);
    } else if (isSerial) {
        iterators = new SerialIterators(this, perScanLimit, null, parallelIteratorFactory, scanGrouper, scan, caches, dataPlan);
    } else {
        iterators = new ParallelIterators(this, perScanLimit, parallelIteratorFactory, scanGrouper, scan, initFirstScanOnly, caches, dataPlan);
    }
    estimatedRows = iterators.getEstimatedRowCount();
    estimatedSize = iterators.getEstimatedByteCount();
    estimateInfoTimestamp = iterators.getEstimateInfoTimestamp();
    splits = iterators.getSplits();
    scans = iterators.getScans();
    if (isOffsetOnServer) {
        scanner = new ConcatResultIterator(iterators);
        if (limit != null) {
            scanner = new LimitingResultIterator(scanner, limit);
        }
    } else if (isOrdered) {
        scanner = new MergeSortTopNResultIterator(iterators, limit, offset, orderBy.getOrderByExpressions());
    } else {
        if ((isSalted || table.getIndexType() == IndexType.LOCAL) && ScanUtil.shouldRowsBeInRowKeyOrder(orderBy, context)) {
            /*
                 * For salted tables or local index, a merge sort is needed if: 
                 * 1) The config phoenix.query.force.rowkeyorder is set to true 
                 * 2) Or if the query has an order by that wants to sort
                 * the results by the row key (forward or reverse ordering)
                 */
            scanner = new MergeSortRowKeyResultIterator(iterators, isSalted ? SaltingUtil.NUM_SALTING_BYTES : 0, orderBy == OrderBy.REV_ROW_KEY_ORDER_BY);
        } else if (useRoundRobinIterator()) {
            /*
                 * For any kind of tables, round robin is possible if there is
                 * no ordering of rows needed.
                 */
            scanner = new RoundRobinResultIterator(iterators, this);
        } else {
            scanner = new ConcatResultIterator(iterators);
        }
        if (offset != null) {
            scanner = new OffsetResultIterator(scanner, offset);
        }
        if (limit != null) {
            scanner = new LimitingResultIterator(scanner, limit);
        }
    }
    if (context.getSequenceManager().getSequenceCount() > 0) {
        scanner = new SequenceResultIterator(scanner, context.getSequenceManager());
    }
    return scanner;
}
Also used : ParallelIterators(org.apache.phoenix.iterate.ParallelIterators) MergeSortRowKeyResultIterator(org.apache.phoenix.iterate.MergeSortRowKeyResultIterator) OffsetResultIterator(org.apache.phoenix.iterate.OffsetResultIterator) SerialIterators(org.apache.phoenix.iterate.SerialIterators) MergeSortTopNResultIterator(org.apache.phoenix.iterate.MergeSortTopNResultIterator) SequenceResultIterator(org.apache.phoenix.iterate.SequenceResultIterator) MergeSortRowKeyResultIterator(org.apache.phoenix.iterate.MergeSortRowKeyResultIterator) SpoolingResultIterator(org.apache.phoenix.iterate.SpoolingResultIterator) ConcatResultIterator(org.apache.phoenix.iterate.ConcatResultIterator) ResultIterator(org.apache.phoenix.iterate.ResultIterator) MergeSortTopNResultIterator(org.apache.phoenix.iterate.MergeSortTopNResultIterator) ChunkedResultIterator(org.apache.phoenix.iterate.ChunkedResultIterator) SequenceResultIterator(org.apache.phoenix.iterate.SequenceResultIterator) LimitingResultIterator(org.apache.phoenix.iterate.LimitingResultIterator) OffsetResultIterator(org.apache.phoenix.iterate.OffsetResultIterator) RoundRobinResultIterator(org.apache.phoenix.iterate.RoundRobinResultIterator) BaseResultIterators(org.apache.phoenix.iterate.BaseResultIterators) LimitingResultIterator(org.apache.phoenix.iterate.LimitingResultIterator) RoundRobinResultIterator(org.apache.phoenix.iterate.RoundRobinResultIterator) PTable(org.apache.phoenix.schema.PTable) ConcatResultIterator(org.apache.phoenix.iterate.ConcatResultIterator) TableRef(org.apache.phoenix.schema.TableRef)

Aggregations

LimitingResultIterator (org.apache.phoenix.iterate.LimitingResultIterator)7 OffsetResultIterator (org.apache.phoenix.iterate.OffsetResultIterator)7 ResultIterator (org.apache.phoenix.iterate.ResultIterator)7 SequenceResultIterator (org.apache.phoenix.iterate.SequenceResultIterator)6 ConcatResultIterator (org.apache.phoenix.iterate.ConcatResultIterator)5 BaseResultIterators (org.apache.phoenix.iterate.BaseResultIterators)4 MergeSortRowKeyResultIterator (org.apache.phoenix.iterate.MergeSortRowKeyResultIterator)4 OrderedResultIterator (org.apache.phoenix.iterate.OrderedResultIterator)4 ParallelIterators (org.apache.phoenix.iterate.ParallelIterators)4 SerialIterators (org.apache.phoenix.iterate.SerialIterators)4 SpoolingResultIterator (org.apache.phoenix.iterate.SpoolingResultIterator)4 AggregatingResultIterator (org.apache.phoenix.iterate.AggregatingResultIterator)3 DistinctAggregatingResultIterator (org.apache.phoenix.iterate.DistinctAggregatingResultIterator)3 FilterAggregatingResultIterator (org.apache.phoenix.iterate.FilterAggregatingResultIterator)3 GroupedAggregatingResultIterator (org.apache.phoenix.iterate.GroupedAggregatingResultIterator)3 MergeSortTopNResultIterator (org.apache.phoenix.iterate.MergeSortTopNResultIterator)3 OrderedAggregatingResultIterator (org.apache.phoenix.iterate.OrderedAggregatingResultIterator)3 PeekingResultIterator (org.apache.phoenix.iterate.PeekingResultIterator)3 UngroupedAggregatingResultIterator (org.apache.phoenix.iterate.UngroupedAggregatingResultIterator)3 ChunkedResultIterator (org.apache.phoenix.iterate.ChunkedResultIterator)2