use of org.apache.flink.table.runtime.util.ResettableExternalBuffer in project flink by apache.
the class SortMergeJoinOperator method doSortMergeJoin.
private void doSortMergeJoin() throws Exception {
MutableObjectIterator iterator1 = sorter1.getIterator();
MutableObjectIterator iterator2 = sorter2.getIterator();
if (type.equals(FlinkJoinType.INNER)) {
if (!leftIsSmaller) {
try (SortMergeInnerJoinIterator joinIterator = new SortMergeInnerJoinIterator(serializer1, serializer2, projection1, projection2, keyComparator, iterator1, iterator2, newBuffer(serializer2), filterNulls)) {
innerJoin(joinIterator, false);
}
} else {
try (SortMergeInnerJoinIterator joinIterator = new SortMergeInnerJoinIterator(serializer2, serializer1, projection2, projection1, keyComparator, iterator2, iterator1, newBuffer(serializer1), filterNulls)) {
innerJoin(joinIterator, true);
}
}
} else if (type.equals(FlinkJoinType.LEFT)) {
try (SortMergeOneSideOuterJoinIterator joinIterator = new SortMergeOneSideOuterJoinIterator(serializer1, serializer2, projection1, projection2, keyComparator, iterator1, iterator2, newBuffer(serializer2), filterNulls)) {
oneSideOuterJoin(joinIterator, false, rightNullRow);
}
} else if (type.equals(FlinkJoinType.RIGHT)) {
try (SortMergeOneSideOuterJoinIterator joinIterator = new SortMergeOneSideOuterJoinIterator(serializer2, serializer1, projection2, projection1, keyComparator, iterator2, iterator1, newBuffer(serializer1), filterNulls)) {
oneSideOuterJoin(joinIterator, true, leftNullRow);
}
} else if (type.equals(FlinkJoinType.FULL)) {
try (SortMergeFullOuterJoinIterator fullOuterJoinIterator = new SortMergeFullOuterJoinIterator(serializer1, serializer2, projection1, projection2, keyComparator, iterator1, iterator2, newBuffer(serializer1), newBuffer(serializer2), filterNulls)) {
fullOuterJoin(fullOuterJoinIterator);
}
} else if (type.equals(FlinkJoinType.SEMI)) {
try (SortMergeInnerJoinIterator joinIterator = new SortMergeInnerJoinIterator(serializer1, serializer2, projection1, projection2, keyComparator, iterator1, iterator2, newBuffer(serializer2), filterNulls)) {
while (joinIterator.nextInnerJoin()) {
RowData probeRow = joinIterator.getProbeRow();
boolean matched = false;
try (ResettableExternalBuffer.BufferIterator iter = joinIterator.getMatchBuffer().newIterator()) {
while (iter.advanceNext()) {
RowData row = iter.getRow();
if (condFunc.apply(probeRow, row)) {
matched = true;
break;
}
}
}
if (matched) {
collector.collect(probeRow);
}
}
}
} else if (type.equals(FlinkJoinType.ANTI)) {
try (SortMergeOneSideOuterJoinIterator joinIterator = new SortMergeOneSideOuterJoinIterator(serializer1, serializer2, projection1, projection2, keyComparator, iterator1, iterator2, newBuffer(serializer2), filterNulls)) {
while (joinIterator.nextOuterJoin()) {
RowData probeRow = joinIterator.getProbeRow();
ResettableExternalBuffer matchBuffer = joinIterator.getMatchBuffer();
boolean matched = false;
if (matchBuffer != null) {
try (ResettableExternalBuffer.BufferIterator iter = matchBuffer.newIterator()) {
while (iter.advanceNext()) {
RowData row = iter.getRow();
if (condFunc.apply(probeRow, row)) {
matched = true;
break;
}
}
}
}
if (!matched) {
collector.collect(probeRow);
}
}
}
} else {
throw new RuntimeException("Not support type: " + type);
}
}
Aggregations