Search in sources :

Example 1 with ProcTimeUnboundedPrecedingFunction

use of org.apache.flink.table.runtime.operators.over.ProcTimeUnboundedPrecedingFunction 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);
    }
}
Also used : RowTimeRangeUnboundedPrecedingFunction(org.apache.flink.table.runtime.operators.over.RowTimeRangeUnboundedPrecedingFunction) AggregateInfoList(org.apache.flink.table.planner.plan.utils.AggregateInfoList) LogicalType(org.apache.flink.table.types.logical.LogicalType) AggsHandlerCodeGenerator(org.apache.flink.table.planner.codegen.agg.AggsHandlerCodeGenerator) GeneratedAggsHandleFunction(org.apache.flink.table.runtime.generated.GeneratedAggsHandleFunction) RowTimeRowsUnboundedPrecedingFunction(org.apache.flink.table.runtime.operators.over.RowTimeRowsUnboundedPrecedingFunction) ProcTimeUnboundedPrecedingFunction(org.apache.flink.table.runtime.operators.over.ProcTimeUnboundedPrecedingFunction)

Aggregations

AggsHandlerCodeGenerator (org.apache.flink.table.planner.codegen.agg.AggsHandlerCodeGenerator)1 AggregateInfoList (org.apache.flink.table.planner.plan.utils.AggregateInfoList)1 GeneratedAggsHandleFunction (org.apache.flink.table.runtime.generated.GeneratedAggsHandleFunction)1 ProcTimeUnboundedPrecedingFunction (org.apache.flink.table.runtime.operators.over.ProcTimeUnboundedPrecedingFunction)1 RowTimeRangeUnboundedPrecedingFunction (org.apache.flink.table.runtime.operators.over.RowTimeRangeUnboundedPrecedingFunction)1 RowTimeRowsUnboundedPrecedingFunction (org.apache.flink.table.runtime.operators.over.RowTimeRowsUnboundedPrecedingFunction)1 LogicalType (org.apache.flink.table.types.logical.LogicalType)1