Search in sources :

Example 6 with SingleAggregateFunction

use of org.apache.phoenix.expression.function.SingleAggregateFunction in project phoenix by apache.

the class AggregationManager method compile.

/**
     * Compiles projection by:
     * 1) Adding RowCount aggregate function if not present when limiting rows. We need this
     *    to track how many rows have been scanned.
     * 2) Reordering aggregation functions (by putting fixed length aggregates first) to
     *    optimize the positional access of the aggregated value.
     */
public void compile(StatementContext context, GroupByCompiler.GroupBy groupBy) throws SQLException {
    final Set<SingleAggregateFunction> aggFuncSet = Sets.newHashSetWithExpectedSize(context.getExpressionManager().getExpressionCount());
    Iterator<Expression> expressions = context.getExpressionManager().getExpressions();
    while (expressions.hasNext()) {
        Expression expression = expressions.next();
        expression.accept(new SingleAggregateFunctionVisitor() {

            @Override
            public Iterator<Expression> visitEnter(SingleAggregateFunction function) {
                aggFuncSet.add(function);
                return Iterators.emptyIterator();
            }
        });
    }
    if (aggFuncSet.isEmpty() && groupBy.isEmpty()) {
        return;
    }
    List<SingleAggregateFunction> aggFuncs = new ArrayList<SingleAggregateFunction>(aggFuncSet);
    Collections.sort(aggFuncs, SingleAggregateFunction.SCHEMA_COMPARATOR);
    int minNullableIndex = getMinNullableIndex(aggFuncs, groupBy.isEmpty());
    context.getScan().setAttribute(BaseScannerRegionObserver.AGGREGATORS, ServerAggregators.serialize(aggFuncs, minNullableIndex));
    ClientAggregators clientAggregators = new ClientAggregators(aggFuncs, minNullableIndex);
    context.getAggregationManager().setAggregators(clientAggregators);
}
Also used : ClientAggregators(org.apache.phoenix.expression.aggregator.ClientAggregators) Expression(org.apache.phoenix.expression.Expression) SingleAggregateFunctionVisitor(org.apache.phoenix.expression.visitor.SingleAggregateFunctionVisitor) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) SingleAggregateFunction(org.apache.phoenix.expression.function.SingleAggregateFunction)

Aggregations

SingleAggregateFunction (org.apache.phoenix.expression.function.SingleAggregateFunction)6 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 IOException (java.io.IOException)2 Expression (org.apache.phoenix.expression.Expression)2 ClientAggregators (org.apache.phoenix.expression.aggregator.ClientAggregators)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 KeyValue (org.apache.hadoop.hbase.KeyValue)1 Scan (org.apache.hadoop.hbase.client.Scan)1 AggregationManager (org.apache.phoenix.compile.AggregationManager)1 SequenceManager (org.apache.phoenix.compile.SequenceManager)1 StatementContext (org.apache.phoenix.compile.StatementContext)1 KeyValueColumnExpression (org.apache.phoenix.expression.KeyValueColumnExpression)1 Aggregator (org.apache.phoenix.expression.aggregator.Aggregator)1 SumAggregateFunction (org.apache.phoenix.expression.function.SumAggregateFunction)1 SingleAggregateFunctionVisitor (org.apache.phoenix.expression.visitor.SingleAggregateFunctionVisitor)1 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)1