use of org.apache.flink.table.planner.functions.aggfunctions.CountAggFunction in project flink by apache.
the class AggregatePushDownSpec method buildAggregateExpressions.
private static List<AggregateExpression> buildAggregateExpressions(RowType inputType, List<AggregateCall> aggregateCalls) {
AggregateInfoList aggInfoList = AggregateUtil.transformToBatchAggregateInfoList(inputType, JavaScalaConversionUtil.toScala(aggregateCalls), null, null);
if (aggInfoList.aggInfos().length == 0) {
// no agg function need to be pushed down
return Collections.emptyList();
}
List<AggregateExpression> aggExpressions = new ArrayList<>();
for (AggregateInfo aggInfo : aggInfoList.aggInfos()) {
List<FieldReferenceExpression> arguments = new ArrayList<>(1);
for (int argIndex : aggInfo.argIndexes()) {
DataType argType = TypeConversions.fromLogicalToDataType(inputType.getFields().get(argIndex).getType());
FieldReferenceExpression field = new FieldReferenceExpression(inputType.getFieldNames().get(argIndex), argType, 0, argIndex);
arguments.add(field);
}
if (aggInfo.function() instanceof AvgAggFunction) {
Tuple2<Sum0AggFunction, CountAggFunction> sum0AndCountFunction = AggregateUtil.deriveSumAndCountFromAvg((AvgAggFunction) aggInfo.function());
AggregateExpression sum0Expression = new AggregateExpression(sum0AndCountFunction._1(), arguments, null, aggInfo.externalResultType(), aggInfo.agg().isDistinct(), aggInfo.agg().isApproximate(), aggInfo.agg().ignoreNulls());
aggExpressions.add(sum0Expression);
AggregateExpression countExpression = new AggregateExpression(sum0AndCountFunction._2(), arguments, null, aggInfo.externalResultType(), aggInfo.agg().isDistinct(), aggInfo.agg().isApproximate(), aggInfo.agg().ignoreNulls());
aggExpressions.add(countExpression);
} else {
AggregateExpression aggregateExpression = new AggregateExpression(aggInfo.function(), arguments, null, aggInfo.externalResultType(), aggInfo.agg().isDistinct(), aggInfo.agg().isApproximate(), aggInfo.agg().ignoreNulls());
aggExpressions.add(aggregateExpression);
}
}
return aggExpressions;
}
Aggregations