Search in sources :

Example 61 with ExecEdge

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

the class StreamExecIntervalJoin method translateToPlanInternal.

@Override
@SuppressWarnings("unchecked")
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
    ExecEdge leftInputEdge = getInputEdges().get(0);
    ExecEdge rightInputEdge = getInputEdges().get(1);
    RowType leftRowType = (RowType) leftInputEdge.getOutputType();
    RowType rightRowType = (RowType) rightInputEdge.getOutputType();
    Transformation<RowData> leftInputTransform = (Transformation<RowData>) leftInputEdge.translateToPlan(planner);
    Transformation<RowData> rightInputTransform = (Transformation<RowData>) rightInputEdge.translateToPlan(planner);
    RowType returnType = (RowType) getOutputType();
    InternalTypeInfo<RowData> returnTypeInfo = InternalTypeInfo.of(returnType);
    JoinSpec joinSpec = intervalJoinSpec.getJoinSpec();
    IntervalJoinSpec.WindowBounds windowBounds = intervalJoinSpec.getWindowBounds();
    switch(joinSpec.getJoinType()) {
        case INNER:
        case LEFT:
        case RIGHT:
        case FULL:
            long relativeWindowSize = windowBounds.getLeftUpperBound() - windowBounds.getLeftLowerBound();
            if (relativeWindowSize < 0) {
                LOGGER.warn("The relative time interval size " + relativeWindowSize + "is negative, please check the join conditions.");
                return createNegativeWindowSizeJoin(joinSpec, leftInputTransform, rightInputTransform, leftRowType.getFieldCount(), rightRowType.getFieldCount(), returnTypeInfo, config);
            } else {
                GeneratedJoinCondition joinCondition = JoinUtil.generateConditionFunction(config.getTableConfig(), joinSpec, leftRowType, rightRowType);
                IntervalJoinFunction joinFunction = new IntervalJoinFunction(joinCondition, returnTypeInfo, joinSpec.getFilterNulls());
                TwoInputTransformation<RowData, RowData, RowData> transform;
                if (windowBounds.isEventTime()) {
                    transform = createRowTimeJoin(leftInputTransform, rightInputTransform, returnTypeInfo, joinFunction, joinSpec, windowBounds, config);
                } else {
                    transform = createProcTimeJoin(leftInputTransform, rightInputTransform, returnTypeInfo, joinFunction, joinSpec, windowBounds, config);
                }
                if (inputsContainSingleton()) {
                    transform.setParallelism(1);
                    transform.setMaxParallelism(1);
                }
                // set KeyType and Selector for state
                RowDataKeySelector leftSelect = KeySelectorUtil.getRowDataSelector(joinSpec.getLeftKeys(), InternalTypeInfo.of(leftRowType));
                RowDataKeySelector rightSelect = KeySelectorUtil.getRowDataSelector(joinSpec.getRightKeys(), InternalTypeInfo.of(rightRowType));
                transform.setStateKeySelectors(leftSelect, rightSelect);
                transform.setStateKeyType(leftSelect.getProducedType());
                return transform;
            }
        default:
            throw new TableException("Interval Join: " + joinSpec.getJoinType() + " Join between stream " + "and stream is not supported yet.\nplease re-check " + "interval join statement according to description above.");
    }
}
Also used : TwoInputTransformation(org.apache.flink.streaming.api.transformations.TwoInputTransformation) UnionTransformation(org.apache.flink.streaming.api.transformations.UnionTransformation) OneInputTransformation(org.apache.flink.streaming.api.transformations.OneInputTransformation) Transformation(org.apache.flink.api.dag.Transformation) TableException(org.apache.flink.table.api.TableException) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) JoinSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.JoinSpec) IntervalJoinSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.IntervalJoinSpec) RowType(org.apache.flink.table.types.logical.RowType) IntervalJoinFunction(org.apache.flink.table.runtime.operators.join.interval.IntervalJoinFunction) RowData(org.apache.flink.table.data.RowData) GeneratedJoinCondition(org.apache.flink.table.runtime.generated.GeneratedJoinCondition) RowDataKeySelector(org.apache.flink.table.runtime.keyselector.RowDataKeySelector) IntervalJoinSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.IntervalJoinSpec)

Example 62 with ExecEdge

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

the class StreamExecJoin method translateToPlanInternal.

@Override
@SuppressWarnings("unchecked")
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
    final ExecEdge leftInputEdge = getInputEdges().get(0);
    final ExecEdge rightInputEdge = getInputEdges().get(1);
    final Transformation<RowData> leftTransform = (Transformation<RowData>) leftInputEdge.translateToPlan(planner);
    final Transformation<RowData> rightTransform = (Transformation<RowData>) rightInputEdge.translateToPlan(planner);
    final RowType leftType = (RowType) leftInputEdge.getOutputType();
    final RowType rightType = (RowType) rightInputEdge.getOutputType();
    JoinUtil.validateJoinSpec(joinSpec, leftType, rightType, true);
    final int[] leftJoinKey = joinSpec.getLeftKeys();
    final int[] rightJoinKey = joinSpec.getRightKeys();
    final InternalTypeInfo<RowData> leftTypeInfo = InternalTypeInfo.of(leftType);
    final JoinInputSideSpec leftInputSpec = JoinUtil.analyzeJoinInput(leftTypeInfo, leftJoinKey, leftUniqueKeys);
    final InternalTypeInfo<RowData> rightTypeInfo = InternalTypeInfo.of(rightType);
    final JoinInputSideSpec rightInputSpec = JoinUtil.analyzeJoinInput(rightTypeInfo, rightJoinKey, rightUniqueKeys);
    GeneratedJoinCondition generatedCondition = JoinUtil.generateConditionFunction(config.getTableConfig(), joinSpec, leftType, rightType);
    long minRetentionTime = config.getStateRetentionTime();
    AbstractStreamingJoinOperator operator;
    FlinkJoinType joinType = joinSpec.getJoinType();
    if (joinType == FlinkJoinType.ANTI || joinType == FlinkJoinType.SEMI) {
        operator = new StreamingSemiAntiJoinOperator(joinType == FlinkJoinType.ANTI, leftTypeInfo, rightTypeInfo, generatedCondition, leftInputSpec, rightInputSpec, joinSpec.getFilterNulls(), minRetentionTime);
    } else {
        boolean leftIsOuter = joinType == FlinkJoinType.LEFT || joinType == FlinkJoinType.FULL;
        boolean rightIsOuter = joinType == FlinkJoinType.RIGHT || joinType == FlinkJoinType.FULL;
        operator = new StreamingJoinOperator(leftTypeInfo, rightTypeInfo, generatedCondition, leftInputSpec, rightInputSpec, leftIsOuter, rightIsOuter, joinSpec.getFilterNulls(), minRetentionTime);
    }
    final RowType returnType = (RowType) getOutputType();
    final TwoInputTransformation<RowData, RowData, RowData> transform = ExecNodeUtil.createTwoInputTransformation(leftTransform, rightTransform, createTransformationMeta(JOIN_TRANSFORMATION, config), operator, InternalTypeInfo.of(returnType), leftTransform.getParallelism());
    // set KeyType and Selector for state
    RowDataKeySelector leftSelect = KeySelectorUtil.getRowDataSelector(leftJoinKey, leftTypeInfo);
    RowDataKeySelector rightSelect = KeySelectorUtil.getRowDataSelector(rightJoinKey, rightTypeInfo);
    transform.setStateKeySelectors(leftSelect, rightSelect);
    transform.setStateKeyType(leftSelect.getProducedType());
    return transform;
}
Also used : TwoInputTransformation(org.apache.flink.streaming.api.transformations.TwoInputTransformation) Transformation(org.apache.flink.api.dag.Transformation) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) RowType(org.apache.flink.table.types.logical.RowType) FlinkJoinType(org.apache.flink.table.runtime.operators.join.FlinkJoinType) JoinInputSideSpec(org.apache.flink.table.runtime.operators.join.stream.state.JoinInputSideSpec) RowData(org.apache.flink.table.data.RowData) GeneratedJoinCondition(org.apache.flink.table.runtime.generated.GeneratedJoinCondition) AbstractStreamingJoinOperator(org.apache.flink.table.runtime.operators.join.stream.AbstractStreamingJoinOperator) StreamingJoinOperator(org.apache.flink.table.runtime.operators.join.stream.StreamingJoinOperator) RowDataKeySelector(org.apache.flink.table.runtime.keyselector.RowDataKeySelector) AbstractStreamingJoinOperator(org.apache.flink.table.runtime.operators.join.stream.AbstractStreamingJoinOperator) StreamingSemiAntiJoinOperator(org.apache.flink.table.runtime.operators.join.stream.StreamingSemiAntiJoinOperator)

Example 63 with ExecEdge

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

Example 64 with ExecEdge

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

the class StreamExecSink method translateToPlanInternal.

@SuppressWarnings("unchecked")
@Override
protected Transformation<Object> 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 DynamicTableSink tableSink = tableSinkSpec.getTableSink(planner.getFlinkContext());
    final boolean isCollectSink = tableSink instanceof CollectDynamicSink;
    final List<Integer> rowtimeFieldIndices = new ArrayList<>();
    for (int i = 0; i < inputRowType.getFieldCount(); ++i) {
        if (TypeCheckUtils.isRowTime(inputRowType.getTypeAt(i))) {
            rowtimeFieldIndices.add(i);
        }
    }
    final int rowtimeFieldIndex;
    if (rowtimeFieldIndices.size() > 1 && !isCollectSink) {
        throw new TableException(String.format("The query contains more than one rowtime attribute column [%s] for writing into table '%s'.\n" + "Please select the column that should be used as the event-time timestamp " + "for the table sink by casting all other columns to regular TIMESTAMP or TIMESTAMP_LTZ.", rowtimeFieldIndices.stream().map(i -> inputRowType.getFieldNames().get(i)).collect(Collectors.joining(", ")), tableSinkSpec.getContextResolvedTable().getIdentifier().asSummaryString()));
    } else if (rowtimeFieldIndices.size() == 1) {
        rowtimeFieldIndex = rowtimeFieldIndices.get(0);
    } else {
        rowtimeFieldIndex = -1;
    }
    return createSinkTransformation(planner.getExecEnv(), config, inputTransform, tableSink, rowtimeFieldIndex, upsertMaterialize);
}
Also used : InputProperty(org.apache.flink.table.planner.plan.nodes.exec.InputProperty) JsonCreator(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator) ChangelogMode(org.apache.flink.table.connector.ChangelogMode) CollectDynamicSink(org.apache.flink.table.planner.connectors.CollectDynamicSink) RowType(org.apache.flink.table.types.logical.RowType) JsonInclude(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonInclude) ExecNode(org.apache.flink.table.planner.plan.nodes.exec.ExecNode) ArrayList(java.util.ArrayList) DynamicTableSinkSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.DynamicTableSinkSpec) FlinkVersion(org.apache.flink.FlinkVersion) TypeCheckUtils(org.apache.flink.table.runtime.typeutils.TypeCheckUtils) ExecNodeContext(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeContext) RowData(org.apache.flink.table.data.RowData) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) PlannerBase(org.apache.flink.table.planner.delegation.PlannerBase) ExecNodeMetadata(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeMetadata) ExecNodeConfig(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeConfig) TableException(org.apache.flink.table.api.TableException) CommonExecSink(org.apache.flink.table.planner.plan.nodes.exec.common.CommonExecSink) Collectors(java.util.stream.Collectors) JsonProperty(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty) List(java.util.List) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) LogicalType(org.apache.flink.table.types.logical.LogicalType) Transformation(org.apache.flink.api.dag.Transformation) Collections(java.util.Collections) Transformation(org.apache.flink.api.dag.Transformation) TableException(org.apache.flink.table.api.TableException) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) ArrayList(java.util.ArrayList) RowType(org.apache.flink.table.types.logical.RowType) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) CollectDynamicSink(org.apache.flink.table.planner.connectors.CollectDynamicSink) RowData(org.apache.flink.table.data.RowData)

Example 65 with ExecEdge

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

the class StreamExecTemporalJoin method translateToPlanInternal.

@Override
@SuppressWarnings("unchecked")
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
    ExecEdge leftInputEdge = getInputEdges().get(0);
    ExecEdge rightInputEdge = getInputEdges().get(1);
    RowType leftInputType = (RowType) leftInputEdge.getOutputType();
    RowType rightInputType = (RowType) rightInputEdge.getOutputType();
    JoinUtil.validateJoinSpec(joinSpec, leftInputType, rightInputType, true);
    FlinkJoinType joinType = joinSpec.getJoinType();
    if (isTemporalFunctionJoin) {
        if (joinType != FlinkJoinType.INNER) {
            throw new ValidationException("Temporal table function join currently only support INNER JOIN, " + "but was " + joinType + " JOIN.");
        }
    } else {
        if (joinType != FlinkJoinType.LEFT && joinType != FlinkJoinType.INNER) {
            throw new TableException("Temporal table join currently only support INNER JOIN and LEFT JOIN, " + "but was " + joinType + " JOIN.");
        }
    }
    RowType returnType = (RowType) getOutputType();
    TwoInputStreamOperator<RowData, RowData, RowData> joinOperator = getJoinOperator(config, leftInputType, rightInputType);
    Transformation<RowData> leftTransform = (Transformation<RowData>) leftInputEdge.translateToPlan(planner);
    Transformation<RowData> rightTransform = (Transformation<RowData>) rightInputEdge.translateToPlan(planner);
    TwoInputTransformation<RowData, RowData, RowData> ret = ExecNodeUtil.createTwoInputTransformation(leftTransform, rightTransform, createTransformationMeta(TEMPORAL_JOIN_TRANSFORMATION, config), joinOperator, InternalTypeInfo.of(returnType), leftTransform.getParallelism());
    // set KeyType and Selector for state
    RowDataKeySelector leftKeySelector = getLeftKeySelector(leftInputType);
    RowDataKeySelector rightKeySelector = getRightKeySelector(rightInputType);
    ret.setStateKeySelectors(leftKeySelector, rightKeySelector);
    ret.setStateKeyType(leftKeySelector.getProducedType());
    return ret;
}
Also used : TableException(org.apache.flink.table.api.TableException) RowData(org.apache.flink.table.data.RowData) TwoInputTransformation(org.apache.flink.streaming.api.transformations.TwoInputTransformation) Transformation(org.apache.flink.api.dag.Transformation) ValidationException(org.apache.flink.table.api.ValidationException) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) RowDataKeySelector(org.apache.flink.table.runtime.keyselector.RowDataKeySelector) RowType(org.apache.flink.table.types.logical.RowType) FlinkJoinType(org.apache.flink.table.runtime.operators.join.FlinkJoinType)

Aggregations

ExecEdge (org.apache.flink.table.planner.plan.nodes.exec.ExecEdge)65 Transformation (org.apache.flink.api.dag.Transformation)52 RowData (org.apache.flink.table.data.RowData)52 RowType (org.apache.flink.table.types.logical.RowType)42 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)25 RowDataKeySelector (org.apache.flink.table.runtime.keyselector.RowDataKeySelector)24 TableException (org.apache.flink.table.api.TableException)21 CodeGeneratorContext (org.apache.flink.table.planner.codegen.CodeGeneratorContext)18 AggregateInfoList (org.apache.flink.table.planner.plan.utils.AggregateInfoList)17 LogicalType (org.apache.flink.table.types.logical.LogicalType)14 ArrayList (java.util.ArrayList)12 InputProperty (org.apache.flink.table.planner.plan.nodes.exec.InputProperty)11 Configuration (org.apache.flink.configuration.Configuration)10 ExecNode (org.apache.flink.table.planner.plan.nodes.exec.ExecNode)10 ZoneId (java.time.ZoneId)9 List (java.util.List)5 EqualiserCodeGenerator (org.apache.flink.table.planner.codegen.EqualiserCodeGenerator)5 AggsHandlerCodeGenerator (org.apache.flink.table.planner.codegen.agg.AggsHandlerCodeGenerator)5 GeneratedAggsHandleFunction (org.apache.flink.table.runtime.generated.GeneratedAggsHandleFunction)5 GeneratedJoinCondition (org.apache.flink.table.runtime.generated.GeneratedJoinCondition)5