Search in sources :

Example 1 with UniformBinaryRowGenerator

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

the class Int2SortMergeJoinOperatorTest method testSemiJoin.

@Test
public void testSemiJoin() throws Exception {
    int numKeys1 = 10;
    int numKeys2 = 9;
    int buildValsPerKey = 10;
    int probeValsPerKey = 3;
    MutableObjectIterator<BinaryRowData> buildInput = new UniformBinaryRowGenerator(numKeys1, buildValsPerKey, true);
    MutableObjectIterator<BinaryRowData> probeInput = new UniformBinaryRowGenerator(numKeys2, probeValsPerKey, true);
    StreamOperator operator = newOperator(FlinkJoinType.SEMI, false);
    joinAndAssert(operator, buildInput, probeInput, 90, 9, 45, true);
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) StreamOperator(org.apache.flink.streaming.api.operators.StreamOperator) UniformBinaryRowGenerator(org.apache.flink.table.runtime.util.UniformBinaryRowGenerator) Test(org.junit.Test)

Example 2 with UniformBinaryRowGenerator

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

the class Int2SortMergeJoinOperatorTest method testAntiJoin.

@Test
public void testAntiJoin() throws Exception {
    int numKeys1 = 10;
    int numKeys2 = 9;
    int buildValsPerKey = 10;
    int probeValsPerKey = 3;
    MutableObjectIterator<BinaryRowData> buildInput = new UniformBinaryRowGenerator(numKeys1, buildValsPerKey, true);
    MutableObjectIterator<BinaryRowData> probeInput = new UniformBinaryRowGenerator(numKeys2, probeValsPerKey, true);
    StreamOperator operator = newOperator(FlinkJoinType.ANTI, false);
    joinAndAssert(operator, buildInput, probeInput, 10, 1, 45, true);
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) StreamOperator(org.apache.flink.streaming.api.operators.StreamOperator) UniformBinaryRowGenerator(org.apache.flink.table.runtime.util.UniformBinaryRowGenerator) Test(org.junit.Test)

Example 3 with UniformBinaryRowGenerator

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

the class BinaryHashTableTest method testInMemoryMutableHashTable.

@Test
public void testInMemoryMutableHashTable() throws IOException {
    final int numKeys = 100000;
    final int buildValsPerKey = 3;
    final int probeValsPerKey = 10;
    // create a build input that gives 3 million pairs with 3 values sharing the same key
    MutableObjectIterator<BinaryRowData> buildInput = new UniformBinaryRowGenerator(numKeys, buildValsPerKey, false);
    // create a probe input that gives 10 million pairs with 10 values sharing a key
    MutableObjectIterator<BinaryRowData> probeInput = new UniformBinaryRowGenerator(numKeys, probeValsPerKey, true);
    MemoryManager memManager = MemoryManagerBuilder.newBuilder().setMemorySize(896 * PAGE_SIZE).build();
    // ----------------------------------------------------------------------------------------
    final BinaryHashTable table = newBinaryHashTable(this.buildSideSerializer, this.probeSideSerializer, new MyProjection(), new MyProjection(), memManager, 100 * PAGE_SIZE, ioManager);
    int numRecordsInJoinResult = join(table, buildInput, probeInput);
    Assert.assertEquals("Wrong number of records in join result.", numKeys * buildValsPerKey * probeValsPerKey, numRecordsInJoinResult);
    table.close();
    table.free();
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) UniformBinaryRowGenerator(org.apache.flink.table.runtime.util.UniformBinaryRowGenerator) Test(org.junit.Test)

Example 4 with UniformBinaryRowGenerator

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

the class BinaryHashTableTest method testSparseProbeSpilling.

/*
     * Spills build records, so that probe records are also spilled. But only so
     * few probe records are used that some partitions remain empty.
     */
@Test
public void testSparseProbeSpilling() throws IOException, MemoryAllocationException {
    final int numBuildKeys = 1000000;
    final int numBuildVals = 1;
    final int numProbeKeys = 20;
    final int numProbeVals = 1;
    MutableObjectIterator<BinaryRowData> buildInput = new UniformBinaryRowGenerator(numBuildKeys, numBuildVals, false);
    MemoryManager memManager = MemoryManagerBuilder.newBuilder().setMemorySize(128 * PAGE_SIZE).build();
    final BinaryHashTable table = newBinaryHashTable(this.buildSideSerializer, this.probeSideSerializer, new MyProjection(), new MyProjection(), memManager, 100 * PAGE_SIZE, ioManager);
    int expectedNumResults = (Math.min(numProbeKeys, numBuildKeys) * numBuildVals) * numProbeVals;
    int numRecordsInJoinResult = join(table, buildInput, new UniformBinaryRowGenerator(numProbeKeys, numProbeVals, true));
    Assert.assertEquals("Wrong number of records in join result.", expectedNumResults, numRecordsInJoinResult);
    table.close();
    table.free();
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) UniformBinaryRowGenerator(org.apache.flink.table.runtime.util.UniformBinaryRowGenerator) Test(org.junit.Test)

Example 5 with UniformBinaryRowGenerator

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

the class BinaryHashTableTest method testSpillingHashJoinOneRecursionValidity.

@Test
public void testSpillingHashJoinOneRecursionValidity() throws IOException {
    final int numKeys = 1000000;
    final int buildValsPerKey = 3;
    final int probeValsPerKey = 10;
    // create a build input that gives 3 million pairs with 3 values sharing the same key
    MutableObjectIterator<BinaryRowData> buildInput = new UniformBinaryRowGenerator(numKeys, buildValsPerKey, false);
    // create a probe input that gives 10 million pairs with 10 values sharing a key
    MutableObjectIterator<BinaryRowData> probeInput = new UniformBinaryRowGenerator(numKeys, probeValsPerKey, true);
    // create the map for validating the results
    HashMap<Integer, Long> map = new HashMap<>(numKeys);
    // ----------------------------------------------------------------------------------------
    MemoryManager memManager = MemoryManagerBuilder.newBuilder().setMemorySize(896 * PAGE_SIZE).build();
    final BinaryHashTable table = newBinaryHashTable(this.buildSideSerializer, this.probeSideSerializer, new MyProjection(), new MyProjection(), memManager, 100 * PAGE_SIZE, ioManager);
    final BinaryRowData recordReuse = new BinaryRowData(2);
    BinaryRowData buildRow = buildSideSerializer.createInstance();
    while ((buildRow = buildInput.next(buildRow)) != null) {
        table.putBuildRow(buildRow);
    }
    table.endBuild();
    BinaryRowData probeRow = probeSideSerializer.createInstance();
    while ((probeRow = probeInput.next(probeRow)) != null) {
        if (table.tryProbe(probeRow)) {
            testJoin(table, map);
        }
    }
    while (table.nextMatching()) {
        testJoin(table, map);
    }
    table.close();
    Assert.assertEquals("Wrong number of keys", numKeys, map.size());
    for (Map.Entry<Integer, Long> entry : map.entrySet()) {
        long val = entry.getValue();
        int key = entry.getKey();
        Assert.assertEquals("Wrong number of values in per-key cross product for key " + key, probeValsPerKey * buildValsPerKey, val);
    }
    // ----------------------------------------------------------------------------------------
    table.free();
}
Also used : HashMap(java.util.HashMap) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) HashMap(java.util.HashMap) Map(java.util.Map) UniformBinaryRowGenerator(org.apache.flink.table.runtime.util.UniformBinaryRowGenerator) Test(org.junit.Test)

Aggregations

BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)21 UniformBinaryRowGenerator (org.apache.flink.table.runtime.util.UniformBinaryRowGenerator)21 Test (org.junit.Test)21 MemoryManager (org.apache.flink.runtime.memory.MemoryManager)14 MutableObjectIterator (org.apache.flink.util.MutableObjectIterator)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ArrayList (java.util.ArrayList)5 UnionIterator (org.apache.flink.runtime.operators.testutils.UnionIterator)5 StreamOperator (org.apache.flink.streaming.api.operators.StreamOperator)2 BinaryRowWriter (org.apache.flink.table.data.writer.BinaryRowWriter)2 IOException (java.io.IOException)1 MemorySegment (org.apache.flink.core.memory.MemorySegment)1 MemoryAllocationException (org.apache.flink.runtime.memory.MemoryAllocationException)1