Search in sources :

Example 1 with OrderedResultIterator

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

the class ClientScanPlan method iterator.

@Override
public ResultIterator iterator(ParallelScanGrouper scanGrouper, Scan scan) throws SQLException {
    ResultIterator iterator = delegate.iterator(scanGrouper, scan);
    if (where != null) {
        iterator = new FilterResultIterator(iterator, where);
    }
    if (!orderBy.getOrderByExpressions().isEmpty()) {
        // TopN
        int thresholdBytes = context.getConnection().getQueryServices().getProps().getInt(QueryServices.SPOOL_THRESHOLD_BYTES_ATTRIB, QueryServicesOptions.DEFAULT_SPOOL_THRESHOLD_BYTES);
        iterator = new OrderedResultIterator(iterator, orderBy.getOrderByExpressions(), thresholdBytes, limit, offset, projector.getEstimatedRowByteSize());
    } else {
        if (offset != null) {
            iterator = new OffsetResultIterator(iterator, offset);
        }
        if (limit != null) {
            iterator = new LimitingResultIterator(iterator, limit);
        }
    }
    if (context.getSequenceManager().getSequenceCount() > 0) {
        iterator = new SequenceResultIterator(iterator, context.getSequenceManager());
    }
    return iterator;
}
Also used : OffsetResultIterator(org.apache.phoenix.iterate.OffsetResultIterator) OrderedResultIterator(org.apache.phoenix.iterate.OrderedResultIterator) SequenceResultIterator(org.apache.phoenix.iterate.SequenceResultIterator) SequenceResultIterator(org.apache.phoenix.iterate.SequenceResultIterator) OrderedResultIterator(org.apache.phoenix.iterate.OrderedResultIterator) LimitingResultIterator(org.apache.phoenix.iterate.LimitingResultIterator) OffsetResultIterator(org.apache.phoenix.iterate.OffsetResultIterator) FilterResultIterator(org.apache.phoenix.iterate.FilterResultIterator) ResultIterator(org.apache.phoenix.iterate.ResultIterator) LimitingResultIterator(org.apache.phoenix.iterate.LimitingResultIterator) FilterResultIterator(org.apache.phoenix.iterate.FilterResultIterator)

Example 2 with OrderedResultIterator

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

the class ClientAggregatePlan method iterator.

@Override
public ResultIterator iterator(ParallelScanGrouper scanGrouper, Scan scan) throws SQLException {
    ResultIterator iterator = delegate.iterator(scanGrouper, scan);
    if (where != null) {
        iterator = new FilterResultIterator(iterator, where);
    }
    AggregatingResultIterator aggResultIterator;
    if (groupBy.isEmpty()) {
        aggResultIterator = new ClientUngroupedAggregatingResultIterator(LookAheadResultIterator.wrap(iterator), serverAggregators);
        aggResultIterator = new UngroupedAggregatingResultIterator(LookAheadResultIterator.wrap(aggResultIterator), clientAggregators);
    } else {
        if (!groupBy.isOrderPreserving()) {
            int thresholdBytes = context.getConnection().getQueryServices().getProps().getInt(QueryServices.SPOOL_THRESHOLD_BYTES_ATTRIB, QueryServicesOptions.DEFAULT_SPOOL_THRESHOLD_BYTES);
            List<Expression> keyExpressions = groupBy.getKeyExpressions();
            List<OrderByExpression> keyExpressionOrderBy = Lists.newArrayListWithExpectedSize(keyExpressions.size());
            for (Expression keyExpression : keyExpressions) {
                keyExpressionOrderBy.add(new OrderByExpression(keyExpression, false, true));
            }
            iterator = new OrderedResultIterator(iterator, keyExpressionOrderBy, thresholdBytes, null, null, projector.getEstimatedRowByteSize());
        }
        aggResultIterator = new ClientGroupedAggregatingResultIterator(LookAheadResultIterator.wrap(iterator), serverAggregators, groupBy.getKeyExpressions());
        aggResultIterator = new GroupedAggregatingResultIterator(LookAheadResultIterator.wrap(aggResultIterator), clientAggregators);
    }
    if (having != null) {
        aggResultIterator = new FilterAggregatingResultIterator(aggResultIterator, having);
    }
    if (statement.isDistinct() && statement.isAggregate()) {
        // Dedup on client if select distinct and aggregation
        aggResultIterator = new DistinctAggregatingResultIterator(aggResultIterator, getProjector());
    }
    ResultIterator resultScanner = aggResultIterator;
    if (orderBy.getOrderByExpressions().isEmpty()) {
        if (offset != null) {
            resultScanner = new OffsetResultIterator(resultScanner, offset);
        }
        if (limit != null) {
            resultScanner = new LimitingResultIterator(resultScanner, limit);
        }
    } else {
        int thresholdBytes = context.getConnection().getQueryServices().getProps().getInt(QueryServices.SPOOL_THRESHOLD_BYTES_ATTRIB, QueryServicesOptions.DEFAULT_SPOOL_THRESHOLD_BYTES);
        resultScanner = new OrderedAggregatingResultIterator(aggResultIterator, orderBy.getOrderByExpressions(), thresholdBytes, limit, offset);
    }
    if (context.getSequenceManager().getSequenceCount() > 0) {
        resultScanner = new SequenceResultIterator(resultScanner, context.getSequenceManager());
    }
    return resultScanner;
}
Also used : OffsetResultIterator(org.apache.phoenix.iterate.OffsetResultIterator) GroupedAggregatingResultIterator(org.apache.phoenix.iterate.GroupedAggregatingResultIterator) BaseGroupedAggregatingResultIterator(org.apache.phoenix.iterate.BaseGroupedAggregatingResultIterator) SequenceResultIterator(org.apache.phoenix.iterate.SequenceResultIterator) OrderedResultIterator(org.apache.phoenix.iterate.OrderedResultIterator) UngroupedAggregatingResultIterator(org.apache.phoenix.iterate.UngroupedAggregatingResultIterator) FilterResultIterator(org.apache.phoenix.iterate.FilterResultIterator) AggregatingResultIterator(org.apache.phoenix.iterate.AggregatingResultIterator) GroupedAggregatingResultIterator(org.apache.phoenix.iterate.GroupedAggregatingResultIterator) FilterAggregatingResultIterator(org.apache.phoenix.iterate.FilterAggregatingResultIterator) ResultIterator(org.apache.phoenix.iterate.ResultIterator) DistinctAggregatingResultIterator(org.apache.phoenix.iterate.DistinctAggregatingResultIterator) PeekingResultIterator(org.apache.phoenix.iterate.PeekingResultIterator) BaseGroupedAggregatingResultIterator(org.apache.phoenix.iterate.BaseGroupedAggregatingResultIterator) SequenceResultIterator(org.apache.phoenix.iterate.SequenceResultIterator) LimitingResultIterator(org.apache.phoenix.iterate.LimitingResultIterator) OrderedAggregatingResultIterator(org.apache.phoenix.iterate.OrderedAggregatingResultIterator) OffsetResultIterator(org.apache.phoenix.iterate.OffsetResultIterator) LookAheadResultIterator(org.apache.phoenix.iterate.LookAheadResultIterator) LimitingResultIterator(org.apache.phoenix.iterate.LimitingResultIterator) UngroupedAggregatingResultIterator(org.apache.phoenix.iterate.UngroupedAggregatingResultIterator) AggregatingResultIterator(org.apache.phoenix.iterate.AggregatingResultIterator) GroupedAggregatingResultIterator(org.apache.phoenix.iterate.GroupedAggregatingResultIterator) FilterAggregatingResultIterator(org.apache.phoenix.iterate.FilterAggregatingResultIterator) DistinctAggregatingResultIterator(org.apache.phoenix.iterate.DistinctAggregatingResultIterator) BaseGroupedAggregatingResultIterator(org.apache.phoenix.iterate.BaseGroupedAggregatingResultIterator) OrderedAggregatingResultIterator(org.apache.phoenix.iterate.OrderedAggregatingResultIterator) FilterResultIterator(org.apache.phoenix.iterate.FilterResultIterator) DistinctAggregatingResultIterator(org.apache.phoenix.iterate.DistinctAggregatingResultIterator) UngroupedAggregatingResultIterator(org.apache.phoenix.iterate.UngroupedAggregatingResultIterator) OrderedResultIterator(org.apache.phoenix.iterate.OrderedResultIterator) Expression(org.apache.phoenix.expression.Expression) OrderByExpression(org.apache.phoenix.expression.OrderByExpression) OrderByExpression(org.apache.phoenix.expression.OrderByExpression) FilterAggregatingResultIterator(org.apache.phoenix.iterate.FilterAggregatingResultIterator) OrderedAggregatingResultIterator(org.apache.phoenix.iterate.OrderedAggregatingResultIterator)

Aggregations

FilterResultIterator (org.apache.phoenix.iterate.FilterResultIterator)2 LimitingResultIterator (org.apache.phoenix.iterate.LimitingResultIterator)2 OffsetResultIterator (org.apache.phoenix.iterate.OffsetResultIterator)2 OrderedResultIterator (org.apache.phoenix.iterate.OrderedResultIterator)2 ResultIterator (org.apache.phoenix.iterate.ResultIterator)2 SequenceResultIterator (org.apache.phoenix.iterate.SequenceResultIterator)2 Expression (org.apache.phoenix.expression.Expression)1 OrderByExpression (org.apache.phoenix.expression.OrderByExpression)1 AggregatingResultIterator (org.apache.phoenix.iterate.AggregatingResultIterator)1 BaseGroupedAggregatingResultIterator (org.apache.phoenix.iterate.BaseGroupedAggregatingResultIterator)1 DistinctAggregatingResultIterator (org.apache.phoenix.iterate.DistinctAggregatingResultIterator)1 FilterAggregatingResultIterator (org.apache.phoenix.iterate.FilterAggregatingResultIterator)1 GroupedAggregatingResultIterator (org.apache.phoenix.iterate.GroupedAggregatingResultIterator)1 LookAheadResultIterator (org.apache.phoenix.iterate.LookAheadResultIterator)1 OrderedAggregatingResultIterator (org.apache.phoenix.iterate.OrderedAggregatingResultIterator)1 PeekingResultIterator (org.apache.phoenix.iterate.PeekingResultIterator)1 UngroupedAggregatingResultIterator (org.apache.phoenix.iterate.UngroupedAggregatingResultIterator)1