Search in sources :

Example 21 with AggregateInfoList

use of org.apache.flink.table.planner.plan.utils.AggregateInfoList 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());
}
Also used : Transformation(org.apache.flink.api.dag.Transformation) AggregateInfoList(org.apache.flink.table.planner.plan.utils.AggregateInfoList) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) CodeGeneratorContext(org.apache.flink.table.planner.codegen.CodeGeneratorContext) RowType(org.apache.flink.table.types.logical.RowType) AggsHandlerCodeGenerator(org.apache.flink.table.planner.codegen.agg.AggsHandlerCodeGenerator) GeneratedAggsHandleFunction(org.apache.flink.table.runtime.generated.GeneratedAggsHandleFunction) RowData(org.apache.flink.table.data.RowData) MapBundleOperator(org.apache.flink.table.runtime.operators.bundle.MapBundleOperator) RowDataKeySelector(org.apache.flink.table.runtime.keyselector.RowDataKeySelector) MiniBatchLocalGroupAggFunction(org.apache.flink.table.runtime.operators.aggregate.MiniBatchLocalGroupAggFunction)

Aggregations

AggregateInfoList (org.apache.flink.table.planner.plan.utils.AggregateInfoList)21 Transformation (org.apache.flink.api.dag.Transformation)17 RowData (org.apache.flink.table.data.RowData)17 ExecEdge (org.apache.flink.table.planner.plan.nodes.exec.ExecEdge)17 RowType (org.apache.flink.table.types.logical.RowType)16 RowDataKeySelector (org.apache.flink.table.runtime.keyselector.RowDataKeySelector)12 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)10 CodeGeneratorContext (org.apache.flink.table.planner.codegen.CodeGeneratorContext)10 AggsHandlerCodeGenerator (org.apache.flink.table.planner.codegen.agg.AggsHandlerCodeGenerator)8 GeneratedAggsHandleFunction (org.apache.flink.table.runtime.generated.GeneratedAggsHandleFunction)8 LogicalType (org.apache.flink.table.types.logical.LogicalType)8 ZoneId (java.time.ZoneId)5 OneInputStreamOperator (org.apache.flink.streaming.api.operators.OneInputStreamOperator)4 TableException (org.apache.flink.table.api.TableException)4 Configuration (org.apache.flink.configuration.Configuration)3 EqualiserCodeGenerator (org.apache.flink.table.planner.codegen.EqualiserCodeGenerator)3 GeneratedRecordEqualiser (org.apache.flink.table.runtime.generated.GeneratedRecordEqualiser)3 ArrayList (java.util.ArrayList)2 AggregateCall (org.apache.calcite.rel.core.AggregateCall)2 FieldReferenceExpression (org.apache.flink.table.expressions.FieldReferenceExpression)2