Search in sources :

Example 1 with OuterJoinPaddingUtil

use of org.apache.flink.table.runtime.operators.join.OuterJoinPaddingUtil in project flink by apache.

the class StreamExecIntervalJoin method createNegativeWindowSizeJoin.

private Transformation<RowData> createNegativeWindowSizeJoin(JoinSpec joinSpec, Transformation<RowData> leftInputTransform, Transformation<RowData> rightInputTransform, int leftArity, int rightArity, InternalTypeInfo<RowData> returnTypeInfo, ReadableConfig config) {
    // We filter all records instead of adding an empty source to preserve the watermarks.
    FilterAllFlatMapFunction allFilter = new FilterAllFlatMapFunction(returnTypeInfo);
    OuterJoinPaddingUtil paddingUtil = new OuterJoinPaddingUtil(leftArity, rightArity);
    PaddingLeftMapFunction leftPadder = new PaddingLeftMapFunction(paddingUtil, returnTypeInfo);
    PaddingRightMapFunction rightPadder = new PaddingRightMapFunction(paddingUtil, returnTypeInfo);
    int leftParallelism = leftInputTransform.getParallelism();
    int rightParallelism = rightInputTransform.getParallelism();
    OneInputTransformation<RowData, RowData> filterAllLeftStream = new OneInputTransformation<>(leftInputTransform, "FilterLeft", new StreamFlatMap<>(allFilter), returnTypeInfo, leftParallelism);
    filterAllLeftStream.setUid(createTransformationUid(FILTER_LEFT_TRANSFORMATION));
    filterAllLeftStream.setDescription(createFormattedTransformationDescription("filter all left input transformation", config));
    filterAllLeftStream.setName(createFormattedTransformationName(filterAllLeftStream.getDescription(), "FilterLeft", config));
    OneInputTransformation<RowData, RowData> filterAllRightStream = new OneInputTransformation<>(rightInputTransform, "FilterRight", new StreamFlatMap<>(allFilter), returnTypeInfo, rightParallelism);
    filterAllRightStream.setUid(createTransformationUid(FILTER_RIGHT_TRANSFORMATION));
    filterAllRightStream.setDescription(createFormattedTransformationDescription("filter all right input transformation", config));
    filterAllRightStream.setName(createFormattedTransformationName(filterAllRightStream.getDescription(), "FilterRight", config));
    OneInputTransformation<RowData, RowData> padLeftStream = new OneInputTransformation<>(leftInputTransform, "PadLeft", new StreamMap<>(leftPadder), returnTypeInfo, leftParallelism);
    padLeftStream.setUid(createTransformationUid(PAD_LEFT_TRANSFORMATION));
    padLeftStream.setDescription(createFormattedTransformationDescription("pad left input transformation", config));
    padLeftStream.setName(createFormattedTransformationName(padLeftStream.getDescription(), "PadLeft", config));
    OneInputTransformation<RowData, RowData> padRightStream = new OneInputTransformation<>(rightInputTransform, "PadRight", new StreamMap<>(rightPadder), returnTypeInfo, rightParallelism);
    padRightStream.setUid(createTransformationUid(PAD_RIGHT_TRANSFORMATION));
    padRightStream.setDescription(createFormattedTransformationDescription("pad right input transformation", config));
    padRightStream.setName(createFormattedTransformationName(padRightStream.getDescription(), "PadRight", config));
    switch(joinSpec.getJoinType()) {
        case INNER:
            return new UnionTransformation<>(Lists.newArrayList(filterAllLeftStream, filterAllRightStream));
        case LEFT:
            return new UnionTransformation<>(Lists.newArrayList(padLeftStream, filterAllRightStream));
        case RIGHT:
            return new UnionTransformation<>(Lists.newArrayList(filterAllLeftStream, padRightStream));
        case FULL:
            return new UnionTransformation<>(Lists.newArrayList(padLeftStream, padRightStream));
        default:
            throw new TableException("should no reach here");
    }
}
Also used : FilterAllFlatMapFunction(org.apache.flink.table.runtime.operators.join.interval.FilterAllFlatMapFunction) RowData(org.apache.flink.table.data.RowData) TableException(org.apache.flink.table.api.TableException) PaddingLeftMapFunction(org.apache.flink.table.runtime.operators.join.interval.PaddingLeftMapFunction) UnionTransformation(org.apache.flink.streaming.api.transformations.UnionTransformation) PaddingRightMapFunction(org.apache.flink.table.runtime.operators.join.interval.PaddingRightMapFunction) OneInputTransformation(org.apache.flink.streaming.api.transformations.OneInputTransformation) OuterJoinPaddingUtil(org.apache.flink.table.runtime.operators.join.OuterJoinPaddingUtil)

Example 2 with OuterJoinPaddingUtil

use of org.apache.flink.table.runtime.operators.join.OuterJoinPaddingUtil in project flink by apache.

the class TimeIntervalJoin method open.

@Override
public void open(Configuration parameters) throws Exception {
    joinFunction.setRuntimeContext(getRuntimeContext());
    joinFunction.open(parameters);
    joinCollector = new EmitAwareCollector();
    // Initialize the data caches.
    ListTypeInfo<Tuple2<RowData, Boolean>> leftRowListTypeInfo = new ListTypeInfo<>(new TupleTypeInfo<>(leftType, BasicTypeInfo.BOOLEAN_TYPE_INFO));
    MapStateDescriptor<Long, List<Tuple2<RowData, Boolean>>> leftMapStateDescriptor = new MapStateDescriptor<>("IntervalJoinLeftCache", BasicTypeInfo.LONG_TYPE_INFO, leftRowListTypeInfo);
    leftCache = getRuntimeContext().getMapState(leftMapStateDescriptor);
    ListTypeInfo<Tuple2<RowData, Boolean>> rightRowListTypeInfo = new ListTypeInfo<>(new TupleTypeInfo<>(rightType, BasicTypeInfo.BOOLEAN_TYPE_INFO));
    MapStateDescriptor<Long, List<Tuple2<RowData, Boolean>>> rightMapStateDescriptor = new MapStateDescriptor<>("IntervalJoinRightCache", BasicTypeInfo.LONG_TYPE_INFO, rightRowListTypeInfo);
    rightCache = getRuntimeContext().getMapState(rightMapStateDescriptor);
    // Initialize the timer states.
    ValueStateDescriptor<Long> leftValueStateDescriptor = new ValueStateDescriptor<>("IntervalJoinLeftTimerState", Long.class);
    leftTimerState = getRuntimeContext().getState(leftValueStateDescriptor);
    ValueStateDescriptor<Long> rightValueStateDescriptor = new ValueStateDescriptor<>("IntervalJoinRightTimerState", Long.class);
    rightTimerState = getRuntimeContext().getState(rightValueStateDescriptor);
    paddingUtil = new OuterJoinPaddingUtil(leftType.toRowSize(), rightType.toRowSize());
}
Also used : MapStateDescriptor(org.apache.flink.api.common.state.MapStateDescriptor) OuterJoinPaddingUtil(org.apache.flink.table.runtime.operators.join.OuterJoinPaddingUtil) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) RowData(org.apache.flink.table.data.RowData) Tuple2(org.apache.flink.api.java.tuple.Tuple2) ListTypeInfo(org.apache.flink.api.java.typeutils.ListTypeInfo) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

RowData (org.apache.flink.table.data.RowData)2 OuterJoinPaddingUtil (org.apache.flink.table.runtime.operators.join.OuterJoinPaddingUtil)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MapStateDescriptor (org.apache.flink.api.common.state.MapStateDescriptor)1 ValueStateDescriptor (org.apache.flink.api.common.state.ValueStateDescriptor)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 ListTypeInfo (org.apache.flink.api.java.typeutils.ListTypeInfo)1 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)1 UnionTransformation (org.apache.flink.streaming.api.transformations.UnionTransformation)1 TableException (org.apache.flink.table.api.TableException)1 FilterAllFlatMapFunction (org.apache.flink.table.runtime.operators.join.interval.FilterAllFlatMapFunction)1 PaddingLeftMapFunction (org.apache.flink.table.runtime.operators.join.interval.PaddingLeftMapFunction)1 PaddingRightMapFunction (org.apache.flink.table.runtime.operators.join.interval.PaddingRightMapFunction)1