Search in sources :

Example 1 with ResettableExternalBuffer

use of org.apache.flink.table.runtime.util.ResettableExternalBuffer in project flink by apache.

the class SortMergeJoinIteratorTest method oneSideOuter.

public void oneSideOuter(Tuple2<MutableObjectIterator<BinaryRowData>, MutableObjectIterator<BinaryRowData>> data, List<Tuple2<BinaryRowData, BinaryRowData>> compare) throws Exception {
    MutableObjectIterator input1 = data.f0;
    MutableObjectIterator input2 = data.f1;
    if (leftIsSmall) {
        input1 = data.f1;
        input2 = data.f0;
    }
    try (SortMergeOneSideOuterJoinIterator iterator = new SortMergeOneSideOuterJoinIterator(new BinaryRowDataSerializer(1), new BinaryRowDataSerializer(1), new MyProjection(), new MyProjection(), new IntRecordComparator(), input1, input2, new ResettableExternalBuffer(ioManager, new LazyMemorySegmentPool(this, memManager, BUFFER_MEMORY), serializer, false), new boolean[] { true })) {
        int id = 0;
        while (iterator.nextOuterJoin()) {
            RowData probe = iterator.getProbeRow();
            if (iterator.matchKey == null) {
                Tuple2<BinaryRowData, BinaryRowData> expected = compare.get(id++);
                if (leftIsSmall) {
                    assertEquals(expected, new Tuple2<>(null, probe));
                } else {
                    assertEquals(expected, new Tuple2<>(probe, null));
                }
            } else {
                ResettableExternalBuffer.BufferIterator iter = iterator.getMatchBuffer().newIterator();
                while (iter.advanceNext()) {
                    RowData row = iter.getRow();
                    Tuple2<BinaryRowData, BinaryRowData> expected = compare.get(id++);
                    assertEquals(expected, new Tuple2<>(row, probe));
                }
            }
        }
        assertEquals(compare.size(), id);
    }
}
Also used : ResettableExternalBuffer(org.apache.flink.table.runtime.util.ResettableExternalBuffer) MutableObjectIterator(org.apache.flink.util.MutableObjectIterator) IntRecordComparator(org.apache.flink.table.runtime.operators.sort.IntRecordComparator) LazyMemorySegmentPool(org.apache.flink.table.runtime.util.LazyMemorySegmentPool) RowData(org.apache.flink.table.data.RowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) MyProjection(org.apache.flink.table.runtime.operators.join.Int2HashJoinOperatorTest.MyProjection) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowDataSerializer(org.apache.flink.table.runtime.typeutils.BinaryRowDataSerializer)

Example 2 with ResettableExternalBuffer

use of org.apache.flink.table.runtime.util.ResettableExternalBuffer in project flink by apache.

the class SortMergeJoinIteratorTest method inner.

public void inner(Tuple2<MutableObjectIterator<BinaryRowData>, MutableObjectIterator<BinaryRowData>> data, List<Tuple2<BinaryRowData, BinaryRowData>> compare) throws Exception {
    MutableObjectIterator input1 = data.f0;
    MutableObjectIterator input2 = data.f1;
    if (leftIsSmall) {
        input1 = data.f1;
        input2 = data.f0;
    }
    try (SortMergeInnerJoinIterator iterator = new SortMergeInnerJoinIterator(new BinaryRowDataSerializer(1), new BinaryRowDataSerializer(1), new MyProjection(), new MyProjection(), new IntRecordComparator(), input1, input2, new ResettableExternalBuffer(ioManager, new LazyMemorySegmentPool(this, memManager, BUFFER_MEMORY), serializer, false), new boolean[] { true })) {
        int id = 0;
        while (iterator.nextInnerJoin()) {
            RowData probe = iterator.getProbeRow();
            ResettableExternalBuffer.BufferIterator iter = iterator.getMatchBuffer().newIterator();
            while (iter.advanceNext()) {
                RowData row = iter.getRow();
                Tuple2<BinaryRowData, BinaryRowData> expected = compare.get(id++);
                if (leftIsSmall) {
                    assertEquals(expected, new Tuple2<>(row, probe));
                } else {
                    assertEquals(expected, new Tuple2<>(probe, row));
                }
            }
        }
        assertEquals(compare.size(), id);
    }
}
Also used : ResettableExternalBuffer(org.apache.flink.table.runtime.util.ResettableExternalBuffer) MutableObjectIterator(org.apache.flink.util.MutableObjectIterator) IntRecordComparator(org.apache.flink.table.runtime.operators.sort.IntRecordComparator) LazyMemorySegmentPool(org.apache.flink.table.runtime.util.LazyMemorySegmentPool) RowData(org.apache.flink.table.data.RowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) MyProjection(org.apache.flink.table.runtime.operators.join.Int2HashJoinOperatorTest.MyProjection) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowDataSerializer(org.apache.flink.table.runtime.typeutils.BinaryRowDataSerializer)

Example 3 with ResettableExternalBuffer

use of org.apache.flink.table.runtime.util.ResettableExternalBuffer in project flink by apache.

the class SortMergeJoinIteratorTest method fullOuter.

public void fullOuter(Tuple2<MutableObjectIterator<BinaryRowData>, MutableObjectIterator<BinaryRowData>> data, List<Tuple2<BinaryRowData, BinaryRowData>> compare) throws Exception {
    MutableObjectIterator<BinaryRowData> input1 = data.f0;
    MutableObjectIterator<BinaryRowData> input2 = data.f1;
    try (SortMergeFullOuterJoinIterator iterator = new SortMergeFullOuterJoinIterator(new BinaryRowDataSerializer(1), new BinaryRowDataSerializer(1), new MyProjection(), new MyProjection(), new IntRecordComparator(), input1, input2, new ResettableExternalBuffer(ioManager, new LazyMemorySegmentPool(this, memManager, BUFFER_MEMORY), serializer, false), new ResettableExternalBuffer(ioManager, new LazyMemorySegmentPool(this, memManager, BUFFER_MEMORY), serializer, false), new boolean[] { true })) {
        int id = 0;
        while (iterator.nextOuterJoin()) {
            BinaryRowData matchKey = iterator.getMatchKey();
            ResettableExternalBuffer buffer1 = iterator.getBuffer1();
            ResettableExternalBuffer buffer2 = iterator.getBuffer2();
            if (matchKey == null && buffer1.size() > 0) {
                // left outer join.
                ResettableExternalBuffer.BufferIterator iter = buffer1.newIterator();
                while (iter.advanceNext()) {
                    RowData row = iter.getRow();
                    Tuple2<BinaryRowData, BinaryRowData> expected = compare.get(id++);
                    assertEquals(expected, new Tuple2<>(row, null));
                }
            } else if (matchKey == null && buffer2.size() > 0) {
                // right outer join.
                ResettableExternalBuffer.BufferIterator iter = buffer2.newIterator();
                while (iter.advanceNext()) {
                    RowData row = iter.getRow();
                    Tuple2<BinaryRowData, BinaryRowData> expected = compare.get(id++);
                    assertEquals(expected, new Tuple2<>(null, row));
                }
            } else if (matchKey != null) {
                // match join.
                ResettableExternalBuffer.BufferIterator iter1 = buffer1.newIterator();
                while (iter1.advanceNext()) {
                    RowData row1 = iter1.getRow();
                    ResettableExternalBuffer.BufferIterator iter2 = buffer2.newIterator();
                    while (iter2.advanceNext()) {
                        RowData row2 = iter2.getRow();
                        Tuple2<BinaryRowData, BinaryRowData> expected = compare.get(id++);
                        assertEquals(expected, new Tuple2<>(row1, row2));
                    }
                }
            } else {
                // bug...
                throw new RuntimeException("There is a bug.");
            }
        }
        assertEquals(compare.size(), id);
    }
}
Also used : ResettableExternalBuffer(org.apache.flink.table.runtime.util.ResettableExternalBuffer) IntRecordComparator(org.apache.flink.table.runtime.operators.sort.IntRecordComparator) LazyMemorySegmentPool(org.apache.flink.table.runtime.util.LazyMemorySegmentPool) RowData(org.apache.flink.table.data.RowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) MyProjection(org.apache.flink.table.runtime.operators.join.Int2HashJoinOperatorTest.MyProjection) Tuple2(org.apache.flink.api.java.tuple.Tuple2) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowDataSerializer(org.apache.flink.table.runtime.typeutils.BinaryRowDataSerializer)

Example 4 with ResettableExternalBuffer

use of org.apache.flink.table.runtime.util.ResettableExternalBuffer in project flink by apache.

the class BufferDataOverWindowOperator method open.

@Override
public void open() throws Exception {
    super.open();
    ClassLoader cl = getUserCodeClassloader();
    serializer = (AbstractRowDataSerializer) getOperatorConfig().getTypeSerializerIn1(cl);
    partitionComparator = genComparator.newInstance(cl);
    genComparator = null;
    MemoryManager memManager = getContainingTask().getEnvironment().getMemoryManager();
    LazyMemorySegmentPool pool = new LazyMemorySegmentPool(this, memManager, (int) (computeMemorySize() / memManager.getPageSize()));
    this.currentData = new ResettableExternalBuffer(getContainingTask().getEnvironment().getIOManager(), pool, serializer, isRowAllInFixedPart);
    collector = new StreamRecordCollector<>(output);
    joinedRows = new JoinedRowData[overWindowFrames.length];
    for (int i = 0; i < overWindowFrames.length; i++) {
        overWindowFrames[i].open(new ExecutionContextImpl(this, getRuntimeContext()));
        joinedRows[i] = new JoinedRowData();
    }
}
Also used : LazyMemorySegmentPool(org.apache.flink.table.runtime.util.LazyMemorySegmentPool) ResettableExternalBuffer(org.apache.flink.table.runtime.util.ResettableExternalBuffer) ExecutionContextImpl(org.apache.flink.table.runtime.context.ExecutionContextImpl) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) MemoryManager(org.apache.flink.runtime.memory.MemoryManager)

Example 5 with ResettableExternalBuffer

use of org.apache.flink.table.runtime.util.ResettableExternalBuffer in project flink by apache.

the class SortMergeJoinOperator method fullOuterJoin.

private void fullOuterJoin(SortMergeFullOuterJoinIterator iterator) throws Exception {
    BitSet bitSet = new BitSet();
    while (iterator.nextOuterJoin()) {
        bitSet.clear();
        BinaryRowData matchKey = iterator.getMatchKey();
        ResettableExternalBuffer buffer1 = iterator.getBuffer1();
        ResettableExternalBuffer buffer2 = iterator.getBuffer2();
        if (matchKey == null && buffer1.size() > 0) {
            // left outer join.
            ResettableExternalBuffer.BufferIterator iter = buffer1.newIterator();
            while (iter.advanceNext()) {
                RowData row1 = iter.getRow();
                collector.collect(joinedRow.replace(row1, rightNullRow));
            }
            iter.close();
        } else if (matchKey == null && buffer2.size() > 0) {
            // right outer join.
            ResettableExternalBuffer.BufferIterator iter = buffer2.newIterator();
            while (iter.advanceNext()) {
                RowData row2 = iter.getRow();
                collector.collect(joinedRow.replace(leftNullRow, row2));
            }
            iter.close();
        } else if (matchKey != null) {
            // match join.
            ResettableExternalBuffer.BufferIterator iter1 = buffer1.newIterator();
            while (iter1.advanceNext()) {
                RowData row1 = iter1.getRow();
                boolean found = false;
                int index = 0;
                ResettableExternalBuffer.BufferIterator iter2 = buffer2.newIterator();
                while (iter2.advanceNext()) {
                    RowData row2 = iter2.getRow();
                    if (condFunc.apply(row1, row2)) {
                        collector.collect(joinedRow.replace(row1, row2));
                        found = true;
                        bitSet.set(index);
                    }
                    index++;
                }
                iter2.close();
                if (!found) {
                    collector.collect(joinedRow.replace(row1, rightNullRow));
                }
            }
            iter1.close();
            // row2 outer
            int index = 0;
            ResettableExternalBuffer.BufferIterator iter2 = buffer2.newIterator();
            while (iter2.advanceNext()) {
                RowData row2 = iter2.getRow();
                if (!bitSet.get(index)) {
                    collector.collect(joinedRow.replace(leftNullRow, row2));
                }
                index++;
            }
            iter2.close();
        } else {
            // bug...
            throw new RuntimeException("There is a bug.");
        }
    }
}
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) BitSet(java.util.BitSet) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData)

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