Search in sources :

Example 1 with MiniBatchIncrementalGroupAggFunction

use of org.apache.flink.table.runtime.operators.aggregate.MiniBatchIncrementalGroupAggFunction in project flink by apache.

the class StreamExecIncrementalGroupAggregate 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 AggregateInfoList partialLocalAggInfoList = AggregateUtil.createPartialAggInfoList(partialLocalAggInputType, JavaScalaConversionUtil.toScala(Arrays.asList(partialOriginalAggCalls)), partialAggCallNeedRetractions, partialAggNeedRetraction, false);
    final GeneratedAggsHandleFunction partialAggsHandler = generateAggsHandler("PartialGroupAggsHandler", partialLocalAggInfoList, partialAggGrouping.length, partialLocalAggInfoList.getAccTypes(), config, planner.getRelBuilder(), // the partial aggregate accumulators will be buffered, so need copy
    true);
    final AggregateInfoList incrementalAggInfo = AggregateUtil.createIncrementalAggInfoList(partialLocalAggInputType, JavaScalaConversionUtil.toScala(Arrays.asList(partialOriginalAggCalls)), partialAggCallNeedRetractions, partialAggNeedRetraction);
    final GeneratedAggsHandleFunction finalAggsHandler = generateAggsHandler("FinalGroupAggsHandler", incrementalAggInfo, 0, partialLocalAggInfoList.getAccTypes(), config, planner.getRelBuilder(), // the final aggregate accumulators is not buffered
    false);
    final RowDataKeySelector partialKeySelector = KeySelectorUtil.getRowDataSelector(partialAggGrouping, InternalTypeInfo.of(inputEdge.getOutputType()));
    final RowDataKeySelector finalKeySelector = KeySelectorUtil.getRowDataSelector(finalAggGrouping, partialKeySelector.getProducedType());
    final MiniBatchIncrementalGroupAggFunction aggFunction = new MiniBatchIncrementalGroupAggFunction(partialAggsHandler, finalAggsHandler, finalKeySelector, config.getStateRetentionTime());
    final OneInputStreamOperator<RowData, RowData> operator = new KeyedMapBundleOperator<>(aggFunction, AggregateUtil.createMiniBatchTrigger(config));
    // partitioned aggregation
    final OneInputTransformation<RowData, RowData> transform = ExecNodeUtil.createOneInputTransformation(inputTransform, createTransformationMeta(INCREMENTAL_GROUP_AGGREGATE_TRANSFORMATION, config), operator, InternalTypeInfo.of(getOutputType()), inputTransform.getParallelism());
    // set KeyType and Selector for state
    transform.setStateKeySelector(partialKeySelector);
    transform.setStateKeyType(partialKeySelector.getProducedType());
    return transform;
}
Also used : RowData(org.apache.flink.table.data.RowData) OneInputTransformation(org.apache.flink.streaming.api.transformations.OneInputTransformation) 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) MiniBatchIncrementalGroupAggFunction(org.apache.flink.table.runtime.operators.aggregate.MiniBatchIncrementalGroupAggFunction) RowDataKeySelector(org.apache.flink.table.runtime.keyselector.RowDataKeySelector) GeneratedAggsHandleFunction(org.apache.flink.table.runtime.generated.GeneratedAggsHandleFunction) KeyedMapBundleOperator(org.apache.flink.table.runtime.operators.bundle.KeyedMapBundleOperator)

Aggregations

Transformation (org.apache.flink.api.dag.Transformation)1 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)1 RowData (org.apache.flink.table.data.RowData)1 ExecEdge (org.apache.flink.table.planner.plan.nodes.exec.ExecEdge)1 AggregateInfoList (org.apache.flink.table.planner.plan.utils.AggregateInfoList)1 GeneratedAggsHandleFunction (org.apache.flink.table.runtime.generated.GeneratedAggsHandleFunction)1 RowDataKeySelector (org.apache.flink.table.runtime.keyselector.RowDataKeySelector)1 MiniBatchIncrementalGroupAggFunction (org.apache.flink.table.runtime.operators.aggregate.MiniBatchIncrementalGroupAggFunction)1 KeyedMapBundleOperator (org.apache.flink.table.runtime.operators.bundle.KeyedMapBundleOperator)1