use of org.apache.flink.table.runtime.operators.over.RowTimeRowsUnboundedPrecedingFunction in project flink by apache.
the class StreamExecOverAggregate method createUnboundedOverProcessFunction.
/**
* Create an ProcessFunction for unbounded OVER window to evaluate final aggregate value.
*
* @param ctx code generator context
* @param aggCalls physical calls to aggregate functions and their output field names
* @param constants the constants in aggregates parameters, such as sum(1)
* @param aggInputRowType physical type of the input row which consists of input and constants.
* @param inputRowType physical type of the input row which only consists of input.
* @param rowTimeIdx the index of the rowtime field or None in case of processing time.
* @param isRowsClause it is a tag that indicates whether the OVER clause is ROWS clause
*/
private KeyedProcessFunction<RowData, RowData, RowData> createUnboundedOverProcessFunction(CodeGeneratorContext ctx, List<AggregateCall> aggCalls, List<RexLiteral> constants, RowType aggInputRowType, RowType inputRowType, int rowTimeIdx, boolean isRowsClause, ExecNodeConfig config, RelBuilder relBuilder) {
AggregateInfoList aggInfoList = AggregateUtil.transformToStreamAggregateInfoList(// inputSchema.relDataType
aggInputRowType, JavaScalaConversionUtil.toScala(aggCalls), new boolean[aggCalls.size()], // needRetraction
false, // isStateBackendDataViews
true, // needDistinctInfo
true);
LogicalType[] fieldTypes = inputRowType.getChildren().toArray(new LogicalType[0]);
AggsHandlerCodeGenerator generator = new AggsHandlerCodeGenerator(ctx, relBuilder, JavaScalaConversionUtil.toScala(Arrays.asList(fieldTypes)), // copyInputField
false);
GeneratedAggsHandleFunction genAggsHandler = generator.needAccumulate().withConstants(JavaScalaConversionUtil.toScala(constants)).generateAggsHandler("UnboundedOverAggregateHelper", aggInfoList);
LogicalType[] flattenAccTypes = Arrays.stream(aggInfoList.getAccTypes()).map(LogicalTypeDataTypeConverter::fromDataTypeToLogicalType).toArray(LogicalType[]::new);
if (rowTimeIdx >= 0) {
if (isRowsClause) {
// ROWS unbounded over process function
return new RowTimeRowsUnboundedPrecedingFunction<>(config.getStateRetentionTime(), config.getMaxIdleStateRetentionTime(), genAggsHandler, flattenAccTypes, fieldTypes, rowTimeIdx);
} else {
// RANGE unbounded over process function
return new RowTimeRangeUnboundedPrecedingFunction<>(config.getStateRetentionTime(), config.getMaxIdleStateRetentionTime(), genAggsHandler, flattenAccTypes, fieldTypes, rowTimeIdx);
}
} else {
return new ProcTimeUnboundedPrecedingFunction<>(config.getStateRetentionTime(), config.getMaxIdleStateRetentionTime(), genAggsHandler, flattenAccTypes);
}
}
Aggregations