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