use of org.apache.flink.table.runtime.operators.over.RowTimeRowsBoundedPrecedingFunction in project flink by apache.
the class StreamExecOverAggregate method createBoundedOverProcessFunction.
/**
* Create an ProcessFunction for ROWS clause bounded 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 aggInputType physical type of the input row which consists of input and constants.
* @param inputType 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> createBoundedOverProcessFunction(CodeGeneratorContext ctx, List<AggregateCall> aggCalls, List<RexLiteral> constants, RowType aggInputType, RowType inputType, int rowTimeIdx, boolean isRowsClause, long precedingOffset, ExecNodeConfig config, RelBuilder relBuilder) {
boolean[] aggCallNeedRetractions = new boolean[aggCalls.size()];
Arrays.fill(aggCallNeedRetractions, true);
AggregateInfoList aggInfoList = AggregateUtil.transformToStreamAggregateInfoList(// inputSchema.relDataType
aggInputType, JavaScalaConversionUtil.toScala(aggCalls), aggCallNeedRetractions, // needInputCount,
true, // isStateBackendDataViews
true, // needDistinctInfo
true);
LogicalType[] fieldTypes = inputType.getChildren().toArray(new LogicalType[0]);
AggsHandlerCodeGenerator generator = new AggsHandlerCodeGenerator(ctx, relBuilder, JavaScalaConversionUtil.toScala(Arrays.asList(fieldTypes)), // copyInputField
false);
GeneratedAggsHandleFunction genAggsHandler = generator.needRetract().needAccumulate().withConstants(JavaScalaConversionUtil.toScala(constants)).generateAggsHandler("BoundedOverAggregateHelper", aggInfoList);
LogicalType[] flattenAccTypes = Arrays.stream(aggInfoList.getAccTypes()).map(LogicalTypeDataTypeConverter::fromDataTypeToLogicalType).toArray(LogicalType[]::new);
if (rowTimeIdx >= 0) {
if (isRowsClause) {
return new RowTimeRowsBoundedPrecedingFunction<>(config.getStateRetentionTime(), config.getMaxIdleStateRetentionTime(), genAggsHandler, flattenAccTypes, fieldTypes, precedingOffset, rowTimeIdx);
} else {
return new RowTimeRangeBoundedPrecedingFunction<>(genAggsHandler, flattenAccTypes, fieldTypes, precedingOffset, rowTimeIdx);
}
} else {
if (isRowsClause) {
return new ProcTimeRowsBoundedPrecedingFunction<>(config.getStateRetentionTime(), config.getMaxIdleStateRetentionTime(), genAggsHandler, flattenAccTypes, fieldTypes, precedingOffset);
} else {
return new ProcTimeRangeBoundedPrecedingFunction<>(genAggsHandler, flattenAccTypes, fieldTypes, precedingOffset);
}
}
}
Aggregations