Search in sources :

Example 6 with ResettableExternalBuffer

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);
    }
}
Also used : GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) ResettableExternalBuffer(org.apache.flink.table.runtime.util.ResettableExternalBuffer) MutableObjectIterator(org.apache.flink.util.MutableObjectIterator)

Aggregations

ResettableExternalBuffer (org.apache.flink.table.runtime.util.ResettableExternalBuffer)6 RowData (org.apache.flink.table.data.RowData)5 BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)5 LazyMemorySegmentPool (org.apache.flink.table.runtime.util.LazyMemorySegmentPool)4 JoinedRowData (org.apache.flink.table.data.utils.JoinedRowData)3 MyProjection (org.apache.flink.table.runtime.operators.join.Int2HashJoinOperatorTest.MyProjection)3 IntRecordComparator (org.apache.flink.table.runtime.operators.sort.IntRecordComparator)3 BinaryRowDataSerializer (org.apache.flink.table.runtime.typeutils.BinaryRowDataSerializer)3 MutableObjectIterator (org.apache.flink.util.MutableObjectIterator)3 GenericRowData (org.apache.flink.table.data.GenericRowData)2 BitSet (java.util.BitSet)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 MemoryManager (org.apache.flink.runtime.memory.MemoryManager)1 ExecutionContextImpl (org.apache.flink.table.runtime.context.ExecutionContextImpl)1