use of org.apache.flink.table.planner.codegen.agg.AggsHandlerCodeGenerator in project flink by apache.
the class StreamExecGlobalWindowAggregate method createAggsHandler.
private GeneratedNamespaceAggsHandleFunction<Long> createAggsHandler(String name, SliceAssigner sliceAssigner, AggregateInfoList aggInfoList, int mergedAccOffset, boolean mergedAccIsOnHeap, DataType[] mergedAccExternalTypes, ExecNodeConfig config, RelBuilder relBuilder, ZoneId shifTimeZone) {
final AggsHandlerCodeGenerator generator = new AggsHandlerCodeGenerator(new CodeGeneratorContext(config.getTableConfig()), relBuilder, JavaScalaConversionUtil.toScala(localAggInputRowType.getChildren()), // copyInputField
true).needAccumulate().needMerge(mergedAccOffset, mergedAccIsOnHeap, mergedAccExternalTypes);
final List<WindowProperty> windowProperties = Arrays.asList(Arrays.stream(namedWindowProperties).map(NamedWindowProperty::getProperty).toArray(WindowProperty[]::new));
return generator.generateNamespaceAggsHandler(name, aggInfoList, JavaScalaConversionUtil.toScala(windowProperties), sliceAssigner, shifTimeZone);
}
use of org.apache.flink.table.planner.codegen.agg.AggsHandlerCodeGenerator 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);
}
}
use of org.apache.flink.table.planner.codegen.agg.AggsHandlerCodeGenerator 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);
}
}
}
use of org.apache.flink.table.planner.codegen.agg.AggsHandlerCodeGenerator in project flink by apache.
the class StreamExecLocalGroupAggregate method translateToPlanInternal.
@SuppressWarnings("unchecked")
@Override
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
final ExecEdge inputEdge = getInputEdges().get(0);
final Transformation<RowData> inputTransform = (Transformation<RowData>) inputEdge.translateToPlan(planner);
final RowType inputRowType = (RowType) inputEdge.getOutputType();
final AggsHandlerCodeGenerator generator = new AggsHandlerCodeGenerator(new CodeGeneratorContext(config.getTableConfig()), planner.getRelBuilder(), JavaScalaConversionUtil.toScala(inputRowType.getChildren()), // the local aggregate result will be buffered, so need copy
true);
generator.needAccumulate().needMerge(0, true, null);
if (needRetraction) {
generator.needRetract();
}
final AggregateInfoList aggInfoList = AggregateUtil.transformToStreamAggregateInfoList(inputRowType, JavaScalaConversionUtil.toScala(Arrays.asList(aggCalls)), aggCallNeedRetractions, needRetraction, // isStateBackendDataViews
false, // needDistinctInfo
true);
final GeneratedAggsHandleFunction aggsHandler = generator.generateAggsHandler("GroupAggsHandler", aggInfoList);
final MiniBatchLocalGroupAggFunction aggFunction = new MiniBatchLocalGroupAggFunction(aggsHandler);
final RowDataKeySelector selector = KeySelectorUtil.getRowDataSelector(grouping, (InternalTypeInfo<RowData>) inputTransform.getOutputType());
final MapBundleOperator<RowData, RowData, RowData, RowData> operator = new MapBundleOperator<>(aggFunction, AggregateUtil.createMiniBatchTrigger(config), selector);
return ExecNodeUtil.createOneInputTransformation(inputTransform, createTransformationMeta(LOCAL_GROUP_AGGREGATE_TRANSFORMATION, config), operator, InternalTypeInfo.of(getOutputType()), inputTransform.getParallelism());
}
use of org.apache.flink.table.planner.codegen.agg.AggsHandlerCodeGenerator in project flink by apache.
the class StreamExecWindowAggregate method createAggsHandler.
private GeneratedNamespaceAggsHandleFunction<Long> createAggsHandler(SliceAssigner sliceAssigner, AggregateInfoList aggInfoList, ExecNodeConfig config, RelBuilder relBuilder, List<LogicalType> fieldTypes, ZoneId shiftTimeZone) {
final AggsHandlerCodeGenerator generator = new AggsHandlerCodeGenerator(new CodeGeneratorContext(config.getTableConfig()), relBuilder, JavaScalaConversionUtil.toScala(fieldTypes), // copyInputField
false).needAccumulate();
if (sliceAssigner instanceof SliceSharedAssigner) {
generator.needMerge(0, false, null);
}
final List<WindowProperty> windowProperties = Arrays.asList(Arrays.stream(namedWindowProperties).map(NamedWindowProperty::getProperty).toArray(WindowProperty[]::new));
return generator.generateNamespaceAggsHandler("WindowAggsHandler", aggInfoList, JavaScalaConversionUtil.toScala(windowProperties), sliceAssigner, shiftTimeZone);
}
Aggregations