Search in sources :

Example 1 with RowTimeRowsBoundedPrecedingFunction

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);
        }
    }
}
Also used : ProcTimeRowsBoundedPrecedingFunction(org.apache.flink.table.runtime.operators.over.ProcTimeRowsBoundedPrecedingFunction) AggregateInfoList(org.apache.flink.table.planner.plan.utils.AggregateInfoList) RowTimeRangeBoundedPrecedingFunction(org.apache.flink.table.runtime.operators.over.RowTimeRangeBoundedPrecedingFunction) ProcTimeRangeBoundedPrecedingFunction(org.apache.flink.table.runtime.operators.over.ProcTimeRangeBoundedPrecedingFunction) RowTimeRowsBoundedPrecedingFunction(org.apache.flink.table.runtime.operators.over.RowTimeRowsBoundedPrecedingFunction) 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)

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 ProcTimeRangeBoundedPrecedingFunction (org.apache.flink.table.runtime.operators.over.ProcTimeRangeBoundedPrecedingFunction)1 ProcTimeRowsBoundedPrecedingFunction (org.apache.flink.table.runtime.operators.over.ProcTimeRowsBoundedPrecedingFunction)1 RowTimeRangeBoundedPrecedingFunction (org.apache.flink.table.runtime.operators.over.RowTimeRangeBoundedPrecedingFunction)1 RowTimeRowsBoundedPrecedingFunction (org.apache.flink.table.runtime.operators.over.RowTimeRowsBoundedPrecedingFunction)1 LogicalType (org.apache.flink.table.types.logical.LogicalType)1