use of org.apache.flink.table.planner.plan.nodes.exec.spec.JoinSpec in project flink by apache.
the class JoinSpecJsonSerdeTest method testJoinSpecSerde.
@Test
public void testJoinSpecSerde() throws IOException {
JoinSpec joinSpec = new JoinSpec(FlinkJoinType.ANTI, new int[] { 1 }, new int[] { 1 }, new boolean[] { true }, null);
StringWriter writer = new StringWriter(100);
try (JsonGenerator gen = mapper.getFactory().createGenerator(writer)) {
gen.writeObject(joinSpec);
}
String json = writer.toString();
JoinSpec actual = mapper.readValue(json, JoinSpec.class);
assertEquals(joinSpec, actual);
}
use of org.apache.flink.table.planner.plan.nodes.exec.spec.JoinSpec in project flink by apache.
the class IntervalJoinSpecJsonSerdeTest method testIntervalJoinSpecSerde.
@Test
public void testIntervalJoinSpecSerde() throws IOException {
JoinSpec joinSpec = new JoinSpec(FlinkJoinType.ANTI, new int[] { 1 }, new int[] { 1 }, new boolean[] { true }, null);
IntervalJoinSpec.WindowBounds windowBounds = new IntervalJoinSpec.WindowBounds(true, 0L, 10L, 1, 2);
IntervalJoinSpec actual = new IntervalJoinSpec(joinSpec, windowBounds);
assertEquals(actual, mapper.readValue(mapper.writeValueAsString(actual), IntervalJoinSpec.class));
}
use of org.apache.flink.table.planner.plan.nodes.exec.spec.JoinSpec 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.");
}
}
Aggregations