use of org.apache.flink.streaming.api.transformations.TwoInputTransformation in project flink by apache.
the class StreamExecWindowJoin method translateToPlanInternal.
@Override
@SuppressWarnings("unchecked")
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
int leftWindowEndIndex = ((WindowAttachedWindowingStrategy) leftWindowing).getWindowEnd();
int rightWindowEndIndex = ((WindowAttachedWindowingStrategy) rightWindowing).getWindowEnd();
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 InternalTypeInfo<RowData> rightTypeInfo = InternalTypeInfo.of(rightType);
GeneratedJoinCondition generatedCondition = JoinUtil.generateConditionFunction(config.getTableConfig(), joinSpec, leftType, rightType);
ZoneId shiftTimeZone = TimeWindowUtil.getShiftTimeZone(leftWindowing.getTimeAttributeType(), config.getLocalTimeZone());
WindowJoinOperator operator = WindowJoinOperatorBuilder.builder().leftSerializer(leftTypeInfo.toRowSerializer()).rightSerializer(rightTypeInfo.toRowSerializer()).generatedJoinCondition(generatedCondition).leftWindowEndIndex(leftWindowEndIndex).rightWindowEndIndex(rightWindowEndIndex).filterNullKeys(joinSpec.getFilterNulls()).joinType(joinSpec.getJoinType()).withShiftTimezone(shiftTimeZone).build();
final RowType returnType = (RowType) getOutputType();
final TwoInputTransformation<RowData, RowData, RowData> transform = ExecNodeUtil.createTwoInputTransformation(leftTransform, rightTransform, createTransformationMeta(WINDOW_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;
}
use of org.apache.flink.streaming.api.transformations.TwoInputTransformation 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.");
}
}
use of org.apache.flink.streaming.api.transformations.TwoInputTransformation 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;
}
use of org.apache.flink.streaming.api.transformations.TwoInputTransformation 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;
}
Aggregations