Search in sources :

Example 1 with GeneratedClass

use of org.apache.flink.table.runtime.generated.GeneratedClass in project flink by apache.

the class StreamExecGroupWindowAggregate method translateToPlanInternal.

@SuppressWarnings("unchecked")
@Override
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
    final boolean isCountWindow;
    if (window instanceof TumblingGroupWindow) {
        isCountWindow = hasRowIntervalType(((TumblingGroupWindow) window).size());
    } else if (window instanceof SlidingGroupWindow) {
        isCountWindow = hasRowIntervalType(((SlidingGroupWindow) window).size());
    } else {
        isCountWindow = false;
    }
    if (isCountWindow && grouping.length > 0 && config.getStateRetentionTime() < 0) {
        LOGGER.warn("No state retention interval configured for a query which accumulates state. " + "Please provide a query configuration with valid retention interval to prevent " + "excessive state size. You may specify a retention time of 0 to not clean up the state.");
    }
    final ExecEdge inputEdge = getInputEdges().get(0);
    final Transformation<RowData> inputTransform = (Transformation<RowData>) inputEdge.translateToPlan(planner);
    final RowType inputRowType = (RowType) inputEdge.getOutputType();
    final int inputTimeFieldIndex;
    if (isRowtimeAttribute(window.timeAttribute())) {
        inputTimeFieldIndex = timeFieldIndex(FlinkTypeFactory.INSTANCE().buildRelNodeRowType(inputRowType), planner.getRelBuilder(), window.timeAttribute());
        if (inputTimeFieldIndex < 0) {
            throw new TableException("Group window must defined on a time attribute, " + "but the time attribute can't be found.\n" + "This should never happen. Please file an issue.");
        }
    } else {
        inputTimeFieldIndex = -1;
    }
    final ZoneId shiftTimeZone = TimeWindowUtil.getShiftTimeZone(window.timeAttribute().getOutputDataType().getLogicalType(), config.getLocalTimeZone());
    final boolean[] aggCallNeedRetractions = new boolean[aggCalls.length];
    Arrays.fill(aggCallNeedRetractions, needRetraction);
    final AggregateInfoList aggInfoList = transformToStreamAggregateInfoList(inputRowType, JavaScalaConversionUtil.toScala(Arrays.asList(aggCalls)), aggCallNeedRetractions, needRetraction, // isStateBackendDataViews
    true, // needDistinctInfo
    true);
    final GeneratedClass<?> aggCodeGenerator = createAggsHandler(aggInfoList, config, planner.getRelBuilder(), inputRowType.getChildren(), shiftTimeZone);
    final LogicalType[] aggResultTypes = extractLogicalTypes(aggInfoList.getActualValueTypes());
    final LogicalType[] windowPropertyTypes = Arrays.stream(namedWindowProperties).map(p -> p.getProperty().getResultType()).toArray(LogicalType[]::new);
    final EqualiserCodeGenerator generator = new EqualiserCodeGenerator(ArrayUtils.addAll(aggResultTypes, windowPropertyTypes));
    final GeneratedRecordEqualiser equaliser = generator.generateRecordEqualiser("WindowValueEqualiser");
    final LogicalType[] aggValueTypes = extractLogicalTypes(aggInfoList.getActualValueTypes());
    final LogicalType[] accTypes = extractLogicalTypes(aggInfoList.getAccTypes());
    final int inputCountIndex = aggInfoList.getIndexOfCountStar();
    final WindowOperator<?, ?> operator = createWindowOperator(config, aggCodeGenerator, equaliser, accTypes, windowPropertyTypes, aggValueTypes, inputRowType.getChildren().toArray(new LogicalType[0]), inputTimeFieldIndex, shiftTimeZone, inputCountIndex);
    final OneInputTransformation<RowData, RowData> transform = ExecNodeUtil.createOneInputTransformation(inputTransform, createTransformationMeta(GROUP_WINDOW_AGGREGATE_TRANSFORMATION, config), operator, InternalTypeInfo.of(getOutputType()), inputTransform.getParallelism());
    // set KeyType and Selector for state
    final RowDataKeySelector selector = KeySelectorUtil.getRowDataSelector(grouping, InternalTypeInfo.of(inputRowType));
    transform.setStateKeySelector(selector);
    transform.setStateKeyType(selector.getProducedType());
    return transform;
}
Also used : AggregateUtil.isProctimeAttribute(org.apache.flink.table.planner.plan.utils.AggregateUtil.isProctimeAttribute) DataType(org.apache.flink.table.types.DataType) Arrays(java.util.Arrays) InputProperty(org.apache.flink.table.planner.plan.nodes.exec.InputProperty) JsonCreator(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator) LoggerFactory(org.slf4j.LoggerFactory) TumblingGroupWindow(org.apache.flink.table.planner.plan.logical.TumblingGroupWindow) FlinkTypeFactory(org.apache.flink.table.planner.calcite.FlinkTypeFactory) AggsHandlerCodeGenerator(org.apache.flink.table.planner.codegen.agg.AggsHandlerCodeGenerator) ExecNode(org.apache.flink.table.planner.plan.nodes.exec.ExecNode) SessionGroupWindow(org.apache.flink.table.planner.plan.logical.SessionGroupWindow) RelBuilder(org.apache.calcite.tools.RelBuilder) KeySelectorUtil(org.apache.flink.table.planner.plan.utils.KeySelectorUtil) Duration(java.time.Duration) AggregateUtil.toDuration(org.apache.flink.table.planner.plan.utils.AggregateUtil.toDuration) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) CodeGeneratorContext(org.apache.flink.table.planner.codegen.CodeGeneratorContext) SlidingGroupWindow(org.apache.flink.table.planner.plan.logical.SlidingGroupWindow) PlannerBase(org.apache.flink.table.planner.delegation.PlannerBase) GeneratedNamespaceTableAggsHandleFunction(org.apache.flink.table.runtime.generated.GeneratedNamespaceTableAggsHandleFunction) GeneratedNamespaceAggsHandleFunction(org.apache.flink.table.runtime.generated.GeneratedNamespaceAggsHandleFunction) ExecNodeConfig(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeConfig) RowDataKeySelector(org.apache.flink.table.runtime.keyselector.RowDataKeySelector) AggregateInfoList(org.apache.flink.table.planner.plan.utils.AggregateInfoList) WindowOperatorBuilder(org.apache.flink.table.runtime.operators.window.WindowOperatorBuilder) CountWindow(org.apache.flink.table.runtime.operators.window.CountWindow) JsonProperty(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty) ZoneId(java.time.ZoneId) List(java.util.List) InternalTypeInfo(org.apache.flink.table.runtime.typeutils.InternalTypeInfo) LogicalType(org.apache.flink.table.types.logical.LogicalType) Preconditions.checkArgument(org.apache.flink.util.Preconditions.checkArgument) AggregateUtil.transformToStreamAggregateInfoList(org.apache.flink.table.planner.plan.utils.AggregateUtil.transformToStreamAggregateInfoList) LogicalWindow(org.apache.flink.table.planner.plan.logical.LogicalWindow) TimeWindowUtil(org.apache.flink.table.runtime.util.TimeWindowUtil) WindowEmitStrategy(org.apache.flink.table.planner.plan.utils.WindowEmitStrategy) NamedWindowProperty(org.apache.flink.table.runtime.groupwindow.NamedWindowProperty) GeneratedClass(org.apache.flink.table.runtime.generated.GeneratedClass) AggregateUtil.hasTimeIntervalType(org.apache.flink.table.planner.plan.utils.AggregateUtil.hasTimeIntervalType) LogicalTypeDataTypeConverter(org.apache.flink.table.runtime.types.LogicalTypeDataTypeConverter) WindowOperator(org.apache.flink.table.runtime.operators.window.WindowOperator) AggregateUtil.isRowtimeAttribute(org.apache.flink.table.planner.plan.utils.AggregateUtil.isRowtimeAttribute) ArrayUtils(org.apache.commons.lang3.ArrayUtils) RowType(org.apache.flink.table.types.logical.RowType) ExecNodeUtil(org.apache.flink.table.planner.plan.nodes.exec.utils.ExecNodeUtil) AggregateUtil.isTableAggregate(org.apache.flink.table.planner.plan.utils.AggregateUtil.isTableAggregate) ReadableConfig(org.apache.flink.configuration.ReadableConfig) FieldReferenceExpression(org.apache.flink.table.expressions.FieldReferenceExpression) FlinkVersion(org.apache.flink.FlinkVersion) TimeWindow(org.apache.flink.table.runtime.operators.window.TimeWindow) ExecNodeContext(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeContext) RowData(org.apache.flink.table.data.RowData) Logger(org.slf4j.Logger) ExecNodeMetadata(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeMetadata) TableException(org.apache.flink.table.api.TableException) AggregateUtil.timeFieldIndex(org.apache.flink.table.planner.plan.utils.AggregateUtil.timeFieldIndex) ValueLiteralExpression(org.apache.flink.table.expressions.ValueLiteralExpression) OneInputTransformation(org.apache.flink.streaming.api.transformations.OneInputTransformation) EqualiserCodeGenerator(org.apache.flink.table.planner.codegen.EqualiserCodeGenerator) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) AggregateUtil.hasRowIntervalType(org.apache.flink.table.planner.plan.utils.AggregateUtil.hasRowIntervalType) JavaScalaConversionUtil(org.apache.flink.table.planner.utils.JavaScalaConversionUtil) GeneratedRecordEqualiser(org.apache.flink.table.runtime.generated.GeneratedRecordEqualiser) AggregateCall(org.apache.calcite.rel.core.AggregateCall) AggregateUtil.toLong(org.apache.flink.table.planner.plan.utils.AggregateUtil.toLong) Transformation(org.apache.flink.api.dag.Transformation) WindowProperty(org.apache.flink.table.runtime.groupwindow.WindowProperty) Collections(java.util.Collections) OneInputTransformation(org.apache.flink.streaming.api.transformations.OneInputTransformation) Transformation(org.apache.flink.api.dag.Transformation) TableException(org.apache.flink.table.api.TableException) AggregateInfoList(org.apache.flink.table.planner.plan.utils.AggregateInfoList) AggregateUtil.transformToStreamAggregateInfoList(org.apache.flink.table.planner.plan.utils.AggregateUtil.transformToStreamAggregateInfoList) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) ZoneId(java.time.ZoneId) RowType(org.apache.flink.table.types.logical.RowType) LogicalType(org.apache.flink.table.types.logical.LogicalType) EqualiserCodeGenerator(org.apache.flink.table.planner.codegen.EqualiserCodeGenerator) GeneratedRecordEqualiser(org.apache.flink.table.runtime.generated.GeneratedRecordEqualiser) RowData(org.apache.flink.table.data.RowData) TumblingGroupWindow(org.apache.flink.table.planner.plan.logical.TumblingGroupWindow) RowDataKeySelector(org.apache.flink.table.runtime.keyselector.RowDataKeySelector) SlidingGroupWindow(org.apache.flink.table.planner.plan.logical.SlidingGroupWindow)

Aggregations

Duration (java.time.Duration)1 ZoneId (java.time.ZoneId)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 AggregateCall (org.apache.calcite.rel.core.AggregateCall)1 RelBuilder (org.apache.calcite.tools.RelBuilder)1 ArrayUtils (org.apache.commons.lang3.ArrayUtils)1 FlinkVersion (org.apache.flink.FlinkVersion)1 Transformation (org.apache.flink.api.dag.Transformation)1 ReadableConfig (org.apache.flink.configuration.ReadableConfig)1 JsonCreator (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator)1 JsonProperty (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty)1 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)1 TableException (org.apache.flink.table.api.TableException)1 RowData (org.apache.flink.table.data.RowData)1 FieldReferenceExpression (org.apache.flink.table.expressions.FieldReferenceExpression)1 ValueLiteralExpression (org.apache.flink.table.expressions.ValueLiteralExpression)1 FlinkTypeFactory (org.apache.flink.table.planner.calcite.FlinkTypeFactory)1 CodeGeneratorContext (org.apache.flink.table.planner.codegen.CodeGeneratorContext)1