use of io.crate.expression.symbol.Aggregation in project crate by crate.
the class ProjectionBuilder method getAggregations.
private ArrayList<Aggregation> getAggregations(Collection<Function> functions, AggregateMode mode, InputColumns.SourceSymbols sourceSymbols, SearchPath searchPath, java.util.function.Function<Symbol, Symbol> subQueryAndParamBinder) {
ArrayList<Aggregation> aggregations = new ArrayList<>(functions.size());
for (Function function : functions) {
assert function.type() == FunctionType.AGGREGATE : "function type must be " + FunctionType.AGGREGATE;
List<Symbol> aggregationInputs;
Symbol filterInput;
switch(mode) {
case ITER_FINAL:
case ITER_PARTIAL:
// ITER means that there is no aggregation part upfront, therefore the input
// symbols need to be in arguments
aggregationInputs = InputColumns.create(function.arguments(), sourceSymbols);
Symbol filter = function.filter();
if (filter != null) {
filterInput = InputColumns.create(filter, sourceSymbols);
} else {
filterInput = Literal.BOOLEAN_TRUE;
}
break;
case PARTIAL_FINAL:
aggregationInputs = List.of(sourceSymbols.getICForSource(function));
filterInput = Literal.BOOLEAN_TRUE;
break;
default:
throw new AssertionError("Invalid mode: " + mode.name());
}
AggregationFunction<?, ?> aggregationFunction = (AggregationFunction<?, ?>) nodeCtx.functions().getQualified(function, searchPath);
assert aggregationFunction != null : "Aggregation function implementation not found using full qualified lookup: " + function;
var valueType = mode.returnType(aggregationFunction);
var functionInfo = FunctionInfo.of(aggregationFunction.signature(), aggregationFunction.boundSignature().getArgumentDataTypes(), valueType);
Aggregation aggregation = new Aggregation(aggregationFunction.signature(), functionInfo, aggregationFunction.boundSignature().getReturnType().createType(), valueType, Lists2.map(aggregationInputs, subQueryAndParamBinder), subQueryAndParamBinder.apply(filterInput));
aggregations.add(aggregation);
}
return aggregations;
}
Aggregations