Search in sources :

Example 1 with ExecNodeConfig

use of org.apache.flink.table.planner.plan.nodes.exec.ExecNodeConfig 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)

Example 2 with ExecNodeConfig

use of org.apache.flink.table.planner.plan.nodes.exec.ExecNodeConfig in project flink by apache.

the class StreamExecLegacyTableSourceScan method createConversionTransformationIfNeeded.

@SuppressWarnings("unchecked")
@Override
protected Transformation<RowData> createConversionTransformationIfNeeded(StreamExecutionEnvironment streamExecEnv, ExecNodeConfig config, Transformation<?> sourceTransform, @Nullable RexNode rowtimeExpression) {
    final RowType outputType = (RowType) getOutputType();
    final Transformation<RowData> transformation;
    final int[] fieldIndexes = computeIndexMapping(true);
    if (needInternalConversion(fieldIndexes)) {
        final String extractElement, resetElement;
        if (ScanUtil.hasTimeAttributeField(fieldIndexes)) {
            String elementTerm = OperatorCodeGenerator.ELEMENT();
            extractElement = String.format("ctx.%s = %s;", elementTerm, elementTerm);
            resetElement = String.format("ctx.%s = null;", elementTerm);
        } else {
            extractElement = "";
            resetElement = "";
        }
        final CodeGeneratorContext ctx = new CodeGeneratorContext(config.getTableConfig()).setOperatorBaseClass(TableStreamOperator.class);
        // the produced type may not carry the correct precision user defined in DDL, because
        // it may be converted from legacy type. Fix precision using logical schema from DDL.
        // Code generation requires the correct precision of input fields.
        final DataType fixedProducedDataType = TableSourceUtil.fixPrecisionForProducedDataType(tableSource, outputType);
        transformation = ScanUtil.convertToInternalRow(ctx, (Transformation<Object>) sourceTransform, fieldIndexes, fixedProducedDataType, outputType, qualifiedName, (detailName, simplifyName) -> createFormattedTransformationName(detailName, simplifyName, config), (description) -> createFormattedTransformationDescription(description, config), JavaScalaConversionUtil.toScala(Optional.ofNullable(rowtimeExpression)), extractElement, resetElement);
    } else {
        transformation = (Transformation<RowData>) sourceTransform;
    }
    final RelDataType relDataType = FlinkTypeFactory.INSTANCE().buildRelNodeRowType(outputType);
    final DataStream<RowData> ingestedTable = new DataStream<>(streamExecEnv, transformation);
    final Optional<RowtimeAttributeDescriptor> rowtimeDesc = JavaScalaConversionUtil.toJava(TableSourceUtil.getRowtimeAttributeDescriptor(tableSource, relDataType));
    final DataStream<RowData> withWatermarks = rowtimeDesc.map(desc -> {
        int rowtimeFieldIdx = relDataType.getFieldNames().indexOf(desc.getAttributeName());
        WatermarkStrategy strategy = desc.getWatermarkStrategy();
        if (strategy instanceof PeriodicWatermarkAssigner) {
            PeriodicWatermarkAssignerWrapper watermarkGenerator = new PeriodicWatermarkAssignerWrapper((PeriodicWatermarkAssigner) strategy, rowtimeFieldIdx);
            return ingestedTable.assignTimestampsAndWatermarks(watermarkGenerator);
        } else if (strategy instanceof PunctuatedWatermarkAssigner) {
            PunctuatedWatermarkAssignerWrapper watermarkGenerator = new PunctuatedWatermarkAssignerWrapper((PunctuatedWatermarkAssigner) strategy, rowtimeFieldIdx, tableSource.getProducedDataType());
            return ingestedTable.assignTimestampsAndWatermarks(watermarkGenerator);
        } else {
            // underlying DataStream.
            return ingestedTable;
        }
    }).orElse(// No need to generate watermarks if no rowtime
    ingestedTable);
    // attribute is specified.
    return withWatermarks.getTransformation();
}
Also used : TableStreamOperator(org.apache.flink.table.runtime.operators.TableStreamOperator) DataType(org.apache.flink.table.types.DataType) TableSourceUtil(org.apache.flink.table.planner.sources.TableSourceUtil) RowtimeAttributeDescriptor(org.apache.flink.table.sources.RowtimeAttributeDescriptor) TableSource(org.apache.flink.table.sources.TableSource) PeriodicWatermarkAssigner(org.apache.flink.table.sources.wmstrategies.PeriodicWatermarkAssigner) FlinkTypeFactory(org.apache.flink.table.planner.calcite.FlinkTypeFactory) RowType(org.apache.flink.table.types.logical.RowType) ExecNode(org.apache.flink.table.planner.plan.nodes.exec.ExecNode) ScanUtil(org.apache.flink.table.planner.plan.utils.ScanUtil) RexNode(org.apache.calcite.rex.RexNode) InputFormat(org.apache.flink.api.common.io.InputFormat) TypeInformation(org.apache.flink.api.common.typeinfo.TypeInformation) CodeGeneratorContext(org.apache.flink.table.planner.codegen.CodeGeneratorContext) Nullable(javax.annotation.Nullable) RelDataType(org.apache.calcite.rel.type.RelDataType) ExecNodeContext(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeContext) RowData(org.apache.flink.table.data.RowData) InputSplit(org.apache.flink.core.io.InputSplit) ExecNodeConfig(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeConfig) WatermarkStrategy(org.apache.flink.table.sources.wmstrategies.WatermarkStrategy) PunctuatedWatermarkAssigner(org.apache.flink.table.sources.wmstrategies.PunctuatedWatermarkAssigner) StreamTableSource(org.apache.flink.table.sources.StreamTableSource) DataStream(org.apache.flink.streaming.api.datastream.DataStream) OperatorCodeGenerator(org.apache.flink.table.planner.codegen.OperatorCodeGenerator) CommonExecLegacyTableSourceScan(org.apache.flink.table.planner.plan.nodes.exec.common.CommonExecLegacyTableSourceScan) List(java.util.List) PunctuatedWatermarkAssignerWrapper(org.apache.flink.table.runtime.operators.wmassigners.PunctuatedWatermarkAssignerWrapper) JavaScalaConversionUtil(org.apache.flink.table.planner.utils.JavaScalaConversionUtil) Optional(java.util.Optional) Transformation(org.apache.flink.api.dag.Transformation) PeriodicWatermarkAssignerWrapper(org.apache.flink.table.runtime.operators.wmassigners.PeriodicWatermarkAssignerWrapper) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Transformation(org.apache.flink.api.dag.Transformation) CodeGeneratorContext(org.apache.flink.table.planner.codegen.CodeGeneratorContext) DataStream(org.apache.flink.streaming.api.datastream.DataStream) RowType(org.apache.flink.table.types.logical.RowType) RelDataType(org.apache.calcite.rel.type.RelDataType) PeriodicWatermarkAssigner(org.apache.flink.table.sources.wmstrategies.PeriodicWatermarkAssigner) RowData(org.apache.flink.table.data.RowData) PunctuatedWatermarkAssignerWrapper(org.apache.flink.table.runtime.operators.wmassigners.PunctuatedWatermarkAssignerWrapper) RowtimeAttributeDescriptor(org.apache.flink.table.sources.RowtimeAttributeDescriptor) PunctuatedWatermarkAssigner(org.apache.flink.table.sources.wmstrategies.PunctuatedWatermarkAssigner) DataType(org.apache.flink.table.types.DataType) RelDataType(org.apache.calcite.rel.type.RelDataType) WatermarkStrategy(org.apache.flink.table.sources.wmstrategies.WatermarkStrategy) PeriodicWatermarkAssignerWrapper(org.apache.flink.table.runtime.operators.wmassigners.PeriodicWatermarkAssignerWrapper)

Example 3 with ExecNodeConfig

use of org.apache.flink.table.planner.plan.nodes.exec.ExecNodeConfig in project flink by apache.

the class BatchExecPythonOverAggregate method getPythonOverWindowAggregateFunctionOperator.

@SuppressWarnings("unchecked")
private OneInputStreamOperator<RowData, RowData> getPythonOverWindowAggregateFunctionOperator(ExecNodeConfig config, Configuration pythonConfig, RowType inputRowType, RowType outputRowType, boolean[] isRangeWindows, int[] udafInputOffsets, PythonFunctionInfo[] pythonFunctionInfos) {
    Class<?> clazz = CommonPythonUtil.loadClass(ARROW_PYTHON_OVER_WINDOW_AGGREGATE_FUNCTION_OPERATOR_NAME);
    RowType udfInputType = (RowType) Projection.of(udafInputOffsets).project(inputRowType);
    RowType udfOutputType = (RowType) Projection.range(inputRowType.getFieldCount(), outputRowType.getFieldCount()).project(outputRowType);
    PartitionSpec partitionSpec = overSpec.getPartition();
    List<OverSpec.GroupSpec> groups = overSpec.getGroups();
    SortSpec sortSpec = groups.get(groups.size() - 1).getSort();
    try {
        Constructor<?> ctor = clazz.getConstructor(Configuration.class, PythonFunctionInfo[].class, RowType.class, RowType.class, RowType.class, long[].class, long[].class, boolean[].class, int[].class, int.class, boolean.class, GeneratedProjection.class, GeneratedProjection.class, GeneratedProjection.class);
        return (OneInputStreamOperator<RowData, RowData>) ctor.newInstance(pythonConfig, pythonFunctionInfos, inputRowType, udfInputType, udfOutputType, lowerBoundary.stream().mapToLong(i -> i).toArray(), upperBoundary.stream().mapToLong(i -> i).toArray(), isRangeWindows, aggWindowIndex.stream().mapToInt(i -> i).toArray(), sortSpec.getFieldIndices()[0], sortSpec.getAscendingOrders()[0], ProjectionCodeGenerator.generateProjection(CodeGeneratorContext.apply(config.getTableConfig()), "UdafInputProjection", inputRowType, udfInputType, udafInputOffsets), ProjectionCodeGenerator.generateProjection(CodeGeneratorContext.apply(config.getTableConfig()), "GroupKey", inputRowType, (RowType) Projection.of(partitionSpec.getFieldIndices()).project(inputRowType), partitionSpec.getFieldIndices()), ProjectionCodeGenerator.generateProjection(CodeGeneratorContext.apply(config.getTableConfig()), "GroupSet", inputRowType, (RowType) Projection.of(partitionSpec.getFieldIndices()).project(inputRowType), partitionSpec.getFieldIndices()));
    } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
        throw new TableException("Python BatchArrowPythonOverWindowAggregateFunctionOperator constructed failed.", e);
    }
}
Also used : OverAggregateUtil(org.apache.flink.table.planner.plan.utils.OverAggregateUtil) InputProperty(org.apache.flink.table.planner.plan.nodes.exec.InputProperty) Tuple2(org.apache.flink.api.java.tuple.Tuple2) RowType(org.apache.flink.table.types.logical.RowType) Constructor(java.lang.reflect.Constructor) ExecNode(org.apache.flink.table.planner.plan.nodes.exec.ExecNode) ArrayList(java.util.ArrayList) ExecNodeUtil(org.apache.flink.table.planner.plan.nodes.exec.utils.ExecNodeUtil) ManagedMemoryUseCase(org.apache.flink.core.memory.ManagedMemoryUseCase) PartitionSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.PartitionSpec) CodeGeneratorContext(org.apache.flink.table.planner.codegen.CodeGeneratorContext) Projection(org.apache.flink.table.connector.Projection) ProjectionCodeGenerator(org.apache.flink.table.planner.codegen.ProjectionCodeGenerator) ExecNodeContext(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeContext) RowData(org.apache.flink.table.data.RowData) PlannerBase(org.apache.flink.table.planner.delegation.PlannerBase) CommonPythonUtil(org.apache.flink.table.planner.plan.nodes.exec.utils.CommonPythonUtil) ExecNodeConfig(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeConfig) Configuration(org.apache.flink.configuration.Configuration) TableException(org.apache.flink.table.api.TableException) PythonFunctionInfo(org.apache.flink.table.functions.python.PythonFunctionInfo) OverSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.OverSpec) OneInputTransformation(org.apache.flink.streaming.api.transformations.OneInputTransformation) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) InternalTypeInfo(org.apache.flink.table.runtime.typeutils.InternalTypeInfo) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) AggregateCall(org.apache.calcite.rel.core.AggregateCall) GeneratedProjection(org.apache.flink.table.runtime.generated.GeneratedProjection) Transformation(org.apache.flink.api.dag.Transformation) OneInputStreamOperator(org.apache.flink.streaming.api.operators.OneInputStreamOperator) SortSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.SortSpec) PythonFunctionInfo(org.apache.flink.table.functions.python.PythonFunctionInfo) TableException(org.apache.flink.table.api.TableException) RowType(org.apache.flink.table.types.logical.RowType) PartitionSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.PartitionSpec) InvocationTargetException(java.lang.reflect.InvocationTargetException) OneInputStreamOperator(org.apache.flink.streaming.api.operators.OneInputStreamOperator) SortSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.SortSpec)

Example 4 with ExecNodeConfig

use of org.apache.flink.table.planner.plan.nodes.exec.ExecNodeConfig in project flink by apache.

the class BatchExecMultipleInput method translateToPlanInternal.

@Override
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
    final List<Transformation<?>> inputTransforms = new ArrayList<>();
    for (ExecEdge inputEdge : getInputEdges()) {
        inputTransforms.add(inputEdge.translateToPlan(planner));
    }
    final Transformation<?> outputTransform = rootNode.translateToPlan(planner);
    final int[] readOrders = getInputProperties().stream().map(InputProperty::getPriority).mapToInt(i -> i).toArray();
    final TableOperatorWrapperGenerator generator = new TableOperatorWrapperGenerator(inputTransforms, outputTransform, readOrders);
    generator.generate();
    final List<Pair<Transformation<?>, InputSpec>> inputTransformAndInputSpecPairs = generator.getInputTransformAndInputSpecPairs();
    final MultipleInputTransformation<RowData> multipleInputTransform = new MultipleInputTransformation<>(createTransformationName(config), new BatchMultipleInputStreamOperatorFactory(inputTransformAndInputSpecPairs.stream().map(Pair::getValue).collect(Collectors.toList()), generator.getHeadWrappers(), generator.getTailWrapper()), InternalTypeInfo.of(getOutputType()), generator.getParallelism());
    multipleInputTransform.setDescription(createTransformationDescription(config));
    inputTransformAndInputSpecPairs.forEach(input -> multipleInputTransform.addInput(input.getKey()));
    if (generator.getMaxParallelism() > 0) {
        multipleInputTransform.setMaxParallelism(generator.getMaxParallelism());
    }
    // set resources
    multipleInputTransform.setResources(generator.getMinResources(), generator.getPreferredResources());
    final int memoryWeight = generator.getManagedMemoryWeight();
    final long memoryBytes = (long) memoryWeight << 20;
    ExecNodeUtil.setManagedMemoryWeight(multipleInputTransform, memoryBytes);
    // set chaining strategy for source chaining
    multipleInputTransform.setChainingStrategy(ChainingStrategy.HEAD_WITH_SOURCES);
    return multipleInputTransform;
}
Also used : MultipleInputTransformation(org.apache.flink.streaming.api.transformations.MultipleInputTransformation) ExecNodeContext(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeContext) RowData(org.apache.flink.table.data.RowData) PlannerBase(org.apache.flink.table.planner.delegation.PlannerBase) InputProperty(org.apache.flink.table.planner.plan.nodes.exec.InputProperty) SingleTransformationTranslator(org.apache.flink.table.planner.plan.nodes.exec.SingleTransformationTranslator) ExecNodeConfig(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeConfig) InputSpec(org.apache.flink.table.runtime.operators.multipleinput.input.InputSpec) Collectors(java.util.stream.Collectors) ExecNode(org.apache.flink.table.planner.plan.nodes.exec.ExecNode) BatchMultipleInputStreamOperatorFactory(org.apache.flink.table.runtime.operators.multipleinput.BatchMultipleInputStreamOperatorFactory) TableOperatorWrapperGenerator(org.apache.flink.table.runtime.operators.multipleinput.TableOperatorWrapperGenerator) ArrayList(java.util.ArrayList) ExecNodeUtil(org.apache.flink.table.planner.plan.nodes.exec.utils.ExecNodeUtil) List(java.util.List) InternalTypeInfo(org.apache.flink.table.runtime.typeutils.InternalTypeInfo) ChainingStrategy(org.apache.flink.streaming.api.operators.ChainingStrategy) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) Pair(org.apache.commons.lang3.tuple.Pair) Preconditions.checkArgument(org.apache.flink.util.Preconditions.checkArgument) ExecNodeBase(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeBase) Transformation(org.apache.flink.api.dag.Transformation) MultipleInputTransformation(org.apache.flink.streaming.api.transformations.MultipleInputTransformation) Transformation(org.apache.flink.api.dag.Transformation) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) InputProperty(org.apache.flink.table.planner.plan.nodes.exec.InputProperty) ArrayList(java.util.ArrayList) BatchMultipleInputStreamOperatorFactory(org.apache.flink.table.runtime.operators.multipleinput.BatchMultipleInputStreamOperatorFactory) TableOperatorWrapperGenerator(org.apache.flink.table.runtime.operators.multipleinput.TableOperatorWrapperGenerator) RowData(org.apache.flink.table.data.RowData) MultipleInputTransformation(org.apache.flink.streaming.api.transformations.MultipleInputTransformation) Pair(org.apache.commons.lang3.tuple.Pair)

Example 5 with ExecNodeConfig

use of org.apache.flink.table.planner.plan.nodes.exec.ExecNodeConfig in project flink by apache.

the class BatchExecPythonGroupWindowAggregate method createPythonOneInputTransformation.

private OneInputTransformation<RowData, RowData> createPythonOneInputTransformation(Transformation<RowData> inputTransform, RowType inputRowType, RowType outputRowType, int maxLimitSize, long windowSize, long slideSize, Configuration pythonConfig, ExecNodeConfig config) {
    int[] namePropertyTypeArray = Arrays.stream(namedWindowProperties).mapToInt(p -> {
        WindowProperty property = p.getProperty();
        if (property instanceof WindowStart) {
            return 0;
        }
        if (property instanceof WindowEnd) {
            return 1;
        }
        if (property instanceof RowtimeAttribute) {
            return 2;
        }
        throw new TableException("Unexpected property " + property);
    }).toArray();
    Tuple2<int[], PythonFunctionInfo[]> aggInfos = CommonPythonUtil.extractPythonAggregateFunctionInfosFromAggregateCall(aggCalls);
    int[] pythonUdafInputOffsets = aggInfos.f0;
    PythonFunctionInfo[] pythonFunctionInfos = aggInfos.f1;
    OneInputStreamOperator<RowData, RowData> pythonOperator = getPythonGroupWindowAggregateFunctionOperator(config, pythonConfig, inputRowType, outputRowType, maxLimitSize, windowSize, slideSize, namePropertyTypeArray, pythonUdafInputOffsets, pythonFunctionInfos);
    return ExecNodeUtil.createOneInputTransformation(inputTransform, createTransformationName(config), createTransformationDescription(config), pythonOperator, InternalTypeInfo.of(outputRowType), inputTransform.getParallelism());
}
Also used : Arrays(java.util.Arrays) InputProperty(org.apache.flink.table.planner.plan.nodes.exec.InputProperty) Tuple2(org.apache.flink.api.java.tuple.Tuple2) RowtimeAttribute(org.apache.flink.table.runtime.groupwindow.RowtimeAttribute) RowType(org.apache.flink.table.types.logical.RowType) Constructor(java.lang.reflect.Constructor) ExecNode(org.apache.flink.table.planner.plan.nodes.exec.ExecNode) ExecNodeUtil(org.apache.flink.table.planner.plan.nodes.exec.utils.ExecNodeUtil) WindowEnd(org.apache.flink.table.runtime.groupwindow.WindowEnd) ManagedMemoryUseCase(org.apache.flink.core.memory.ManagedMemoryUseCase) CodeGeneratorContext(org.apache.flink.table.planner.codegen.CodeGeneratorContext) Projection(org.apache.flink.table.connector.Projection) ProjectionCodeGenerator(org.apache.flink.table.planner.codegen.ProjectionCodeGenerator) WindowCodeGenerator(org.apache.flink.table.planner.codegen.agg.batch.WindowCodeGenerator) ExecNodeContext(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeContext) WindowStart(org.apache.flink.table.runtime.groupwindow.WindowStart) RowData(org.apache.flink.table.data.RowData) PlannerBase(org.apache.flink.table.planner.delegation.PlannerBase) CommonPythonUtil(org.apache.flink.table.planner.plan.nodes.exec.utils.CommonPythonUtil) SingleTransformationTranslator(org.apache.flink.table.planner.plan.nodes.exec.SingleTransformationTranslator) ExecNodeConfig(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeConfig) Configuration(org.apache.flink.configuration.Configuration) TableException(org.apache.flink.table.api.TableException) PythonFunctionInfo(org.apache.flink.table.functions.python.PythonFunctionInfo) OneInputTransformation(org.apache.flink.streaming.api.transformations.OneInputTransformation) InvocationTargetException(java.lang.reflect.InvocationTargetException) InternalTypeInfo(org.apache.flink.table.runtime.typeutils.InternalTypeInfo) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) LogicalWindow(org.apache.flink.table.planner.plan.logical.LogicalWindow) AggregateCall(org.apache.calcite.rel.core.AggregateCall) ExecNodeBase(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeBase) GeneratedProjection(org.apache.flink.table.runtime.generated.GeneratedProjection) Transformation(org.apache.flink.api.dag.Transformation) OneInputStreamOperator(org.apache.flink.streaming.api.operators.OneInputStreamOperator) ExecutionConfigOptions(org.apache.flink.table.api.config.ExecutionConfigOptions) WindowProperty(org.apache.flink.table.runtime.groupwindow.WindowProperty) Collections(java.util.Collections) NamedWindowProperty(org.apache.flink.table.runtime.groupwindow.NamedWindowProperty) RowtimeAttribute(org.apache.flink.table.runtime.groupwindow.RowtimeAttribute) PythonFunctionInfo(org.apache.flink.table.functions.python.PythonFunctionInfo) WindowProperty(org.apache.flink.table.runtime.groupwindow.WindowProperty) NamedWindowProperty(org.apache.flink.table.runtime.groupwindow.NamedWindowProperty) TableException(org.apache.flink.table.api.TableException) RowData(org.apache.flink.table.data.RowData) WindowStart(org.apache.flink.table.runtime.groupwindow.WindowStart) WindowEnd(org.apache.flink.table.runtime.groupwindow.WindowEnd)

Aggregations

Transformation (org.apache.flink.api.dag.Transformation)7 RowData (org.apache.flink.table.data.RowData)7 ExecNode (org.apache.flink.table.planner.plan.nodes.exec.ExecNode)7 ExecNodeConfig (org.apache.flink.table.planner.plan.nodes.exec.ExecNodeConfig)7 ExecNodeContext (org.apache.flink.table.planner.plan.nodes.exec.ExecNodeContext)7 List (java.util.List)6 PlannerBase (org.apache.flink.table.planner.delegation.PlannerBase)6 RowType (org.apache.flink.table.types.logical.RowType)6 CodeGeneratorContext (org.apache.flink.table.planner.codegen.CodeGeneratorContext)5 ExecEdge (org.apache.flink.table.planner.plan.nodes.exec.ExecEdge)5 InputProperty (org.apache.flink.table.planner.plan.nodes.exec.InputProperty)5 Collections (java.util.Collections)4 TableException (org.apache.flink.table.api.TableException)4 ExecNodeUtil (org.apache.flink.table.planner.plan.nodes.exec.utils.ExecNodeUtil)4 InternalTypeInfo (org.apache.flink.table.runtime.typeutils.InternalTypeInfo)4 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 Collectors (java.util.stream.Collectors)3 AggregateCall (org.apache.calcite.rel.core.AggregateCall)3 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)3