org.apache.flink.runtime.operators.testutils.Match Java Examples
The following examples show how to use
org.apache.flink.runtime.operators.testutils.Match.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RandomSortMergeInnerJoinTest.java From flink with Apache License 2.0 | 6 votes |
public static void match(Map<Integer, Collection<Match>> expectedMatchesMap, LinkedBlockingQueue<Object> values) { for (Object o : values) { BinaryRowData row = ((StreamRecord<BinaryRowData>) o).getValue(); final Integer key = row.getInt(0); final String value1 = row.isNullAt(1) ? null : row.getString(1).toString(); final String value2 = row.isNullAt(2) ? null : row.getString(2).toString(); Collection<Match> matches = expectedMatchesMap.get(key); if (matches == null) { Assert.fail("Match " + key + " - " + value1 + ":" + value2 + " is unexpected."); } boolean contained = matches.remove(new Match(value1, value2)); if (!contained) { Assert.fail("Produced match was not contained: " + key + " - " + value1 + ":" + value2 + ", now have: " + matches); } if (matches.isEmpty()) { expectedMatchesMap.remove(key); } } }
Example #2
Source File: RandomSortMergeInnerJoinTest.java From flink with Apache License 2.0 | 6 votes |
public static void match(Map<Integer, Collection<Match>> expectedMatchesMap, LinkedBlockingQueue<Object> values) { for (Object o : values) { BinaryRow row = ((StreamRecord<BinaryRow>) o).getValue(); final Integer key = row.getInt(0); final String value1 = row.isNullAt(1) ? null : row.getString(1).toString(); final String value2 = row.isNullAt(2) ? null : row.getString(2).toString(); Collection<Match> matches = expectedMatchesMap.get(key); if (matches == null) { Assert.fail("Match " + key + " - " + value1 + ":" + value2 + " is unexpected."); } boolean contained = matches.remove(new Match(value1, value2)); if (!contained) { Assert.fail("Produced match was not contained: " + key + " - " + value1 + ":" + value2 + ", now have: " + matches); } if (matches.isEmpty()) { expectedMatchesMap.remove(key); } } }
Example #3
Source File: RandomSortMergeInnerJoinTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void test() throws Exception { final TupleGenerator generator1 = new TupleGenerator(SEED1, 500, 4096, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TupleGenerator generator2 = new TupleGenerator(SEED2, 500, 2048, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TestData.TupleGeneratorIterator input1 = new TestData.TupleGeneratorIterator(generator1, INPUT_FIRST_SIZE); final TestData.TupleGeneratorIterator input2 = new TestData.TupleGeneratorIterator(generator2, INPUT_SECOND_SIZE); // collect expected data final Map<Integer, Collection<Match>> expectedMatchesMap = matchValues( collectData(input1), collectData(input2)); // reset the generators generator1.reset(); generator2.reset(); input1.reset(); input2.reset(); StreamOperator operator = getOperator(); match(expectedMatchesMap, transformToBinary(join(operator, input1, input2))); // assert that each expected match was seen for (Map.Entry<Integer, Collection<Match>> entry : expectedMatchesMap.entrySet()) { Assert.assertTrue("Collection for key " + entry.getKey() + " is not empty", entry.getValue().isEmpty()); } }
Example #4
Source File: ReusingSortMergeInnerJoinIteratorITCase.java From flink with Apache License 2.0 | 5 votes |
private Map<Integer, Collection<Match>> matchValues( Map<Integer, Collection<String>> leftMap, Map<Integer, Collection<String>> rightMap) { Map<Integer, Collection<Match>> map = new HashMap<Integer, Collection<Match>>(); for (Integer key : leftMap.keySet()) { Collection<String> leftValues = leftMap.get(key); Collection<String> rightValues = rightMap.get(key); if (rightValues == null) { continue; } if (!map.containsKey(key)) { map.put(key, new ArrayList<Match>()); } Collection<Match> matchedValues = map.get(key); for (String leftValue : leftValues) { for (String rightValue : rightValues) { matchedValues.add(new Match(leftValue, rightValue)); } } } return map; }
Example #5
Source File: NonReusingSortMergeInnerJoinIteratorITCase.java From flink with Apache License 2.0 | 5 votes |
private Map<Integer, Collection<Match>> matchValues( Map<Integer, Collection<String>> leftMap, Map<Integer, Collection<String>> rightMap) { Map<Integer, Collection<Match>> map = new HashMap<Integer, Collection<Match>>(); for (Integer key : leftMap.keySet()) { Collection<String> leftValues = leftMap.get(key); Collection<String> rightValues = rightMap.get(key); if (rightValues == null) { continue; } if (!map.containsKey(key)) { map.put(key, new ArrayList<Match>()); } Collection<Match> matchedValues = map.get(key); for (String leftValue : leftValues) { for (String rightValue : rightValues) { matchedValues.add(new Match(leftValue, rightValue)); } } } return map; }
Example #6
Source File: RandomSortMergeInnerJoinTest.java From flink with Apache License 2.0 | 5 votes |
public static Map<Integer, Collection<Match>> matchValues( Map<Integer, Collection<String>> leftMap, Map<Integer, Collection<String>> rightMap) { Map<Integer, Collection<Match>> map = new HashMap<>(); for (Integer key : leftMap.keySet()) { Collection<String> leftValues = leftMap.get(key); Collection<String> rightValues = rightMap.get(key); if (rightValues == null) { continue; } if (!map.containsKey(key)) { map.put(key, new ArrayList<>()); } Collection<Match> matchedValues = map.get(key); for (String leftValue : leftValues) { for (String rightValue : rightValues) { matchedValues.add(new Match(leftValue, rightValue)); } } } return map; }
Example #7
Source File: RandomSortMergeInnerJoinTest.java From flink with Apache License 2.0 | 5 votes |
public static Map<Integer, Collection<Match>> matchValues( Map<Integer, Collection<String>> leftMap, Map<Integer, Collection<String>> rightMap) { Map<Integer, Collection<Match>> map = new HashMap<>(); for (Integer key : leftMap.keySet()) { Collection<String> leftValues = leftMap.get(key); Collection<String> rightValues = rightMap.get(key); if (rightValues == null) { continue; } if (!map.containsKey(key)) { map.put(key, new ArrayList<>()); } Collection<Match> matchedValues = map.get(key); for (String leftValue : leftValues) { for (String rightValue : rightValues) { matchedValues.add(new Match(leftValue, rightValue)); } } } return map; }
Example #8
Source File: RandomSortMergeInnerJoinTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void test() throws Exception { final TupleGenerator generator1 = new TupleGenerator(SEED1, 500, 4096, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TupleGenerator generator2 = new TupleGenerator(SEED2, 500, 2048, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TestData.TupleGeneratorIterator input1 = new TestData.TupleGeneratorIterator(generator1, INPUT_FIRST_SIZE); final TestData.TupleGeneratorIterator input2 = new TestData.TupleGeneratorIterator(generator2, INPUT_SECOND_SIZE); // collect expected data final Map<Integer, Collection<Match>> expectedMatchesMap = matchValues( collectData(input1), collectData(input2)); // reset the generators generator1.reset(); generator2.reset(); input1.reset(); input2.reset(); StreamOperator operator = getOperator(); match(expectedMatchesMap, transformToBinary(join(operator, input1, input2))); // assert that each expected match was seen for (Map.Entry<Integer, Collection<Match>> entry : expectedMatchesMap.entrySet()) { Assert.assertTrue("Collection for key " + entry.getKey() + " is not empty", entry.getValue().isEmpty()); } }
Example #9
Source File: NonReusingSortMergeInnerJoinIteratorITCase.java From flink with Apache License 2.0 | 5 votes |
private Map<Integer, Collection<Match>> matchValues( Map<Integer, Collection<String>> leftMap, Map<Integer, Collection<String>> rightMap) { Map<Integer, Collection<Match>> map = new HashMap<Integer, Collection<Match>>(); for (Integer key : leftMap.keySet()) { Collection<String> leftValues = leftMap.get(key); Collection<String> rightValues = rightMap.get(key); if (rightValues == null) { continue; } if (!map.containsKey(key)) { map.put(key, new ArrayList<Match>()); } Collection<Match> matchedValues = map.get(key); for (String leftValue : leftValues) { for (String rightValue : rightValues) { matchedValues.add(new Match(leftValue, rightValue)); } } } return map; }
Example #10
Source File: ReusingSortMergeInnerJoinIteratorITCase.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private Map<Integer, Collection<Match>> matchValues( Map<Integer, Collection<String>> leftMap, Map<Integer, Collection<String>> rightMap) { Map<Integer, Collection<Match>> map = new HashMap<Integer, Collection<Match>>(); for (Integer key : leftMap.keySet()) { Collection<String> leftValues = leftMap.get(key); Collection<String> rightValues = rightMap.get(key); if (rightValues == null) { continue; } if (!map.containsKey(key)) { map.put(key, new ArrayList<Match>()); } Collection<Match> matchedValues = map.get(key); for (String leftValue : leftValues) { for (String rightValue : rightValues) { matchedValues.add(new Match(leftValue, rightValue)); } } } return map; }
Example #11
Source File: NonReusingSortMergeInnerJoinIteratorITCase.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private Map<Integer, Collection<Match>> matchValues( Map<Integer, Collection<String>> leftMap, Map<Integer, Collection<String>> rightMap) { Map<Integer, Collection<Match>> map = new HashMap<Integer, Collection<Match>>(); for (Integer key : leftMap.keySet()) { Collection<String> leftValues = leftMap.get(key); Collection<String> rightValues = rightMap.get(key); if (rightValues == null) { continue; } if (!map.containsKey(key)) { map.put(key, new ArrayList<Match>()); } Collection<Match> matchedValues = map.get(key); for (String leftValue : leftValues) { for (String rightValue : rightValues) { matchedValues.add(new Match(leftValue, rightValue)); } } } return map; }
Example #12
Source File: ReusingSortMergeInnerJoinIteratorITCase.java From flink with Apache License 2.0 | 5 votes |
private Map<Integer, Collection<Match>> matchValues( Map<Integer, Collection<String>> leftMap, Map<Integer, Collection<String>> rightMap) { Map<Integer, Collection<Match>> map = new HashMap<Integer, Collection<Match>>(); for (Integer key : leftMap.keySet()) { Collection<String> leftValues = leftMap.get(key); Collection<String> rightValues = rightMap.get(key); if (rightValues == null) { continue; } if (!map.containsKey(key)) { map.put(key, new ArrayList<Match>()); } Collection<Match> matchedValues = map.get(key); for (String leftValue : leftValues) { for (String rightValue : rightValues) { matchedValues.add(new Match(leftValue, rightValue)); } } } return map; }
Example #13
Source File: NonReusingSortMergeInnerJoinIteratorITCase.java From flink with Apache License 2.0 | 4 votes |
@Test public void testMergeWithHighNumberOfCommonKeys() { // the size of the left and right inputs final int INPUT_1_SIZE = 200; final int INPUT_2_SIZE = 100; final int INPUT_1_DUPLICATES = 10; final int INPUT_2_DUPLICATES = 4000; final int DUPLICATE_KEY = 13; try { final TupleGenerator generator1 = new TupleGenerator(SEED1, 500, 4096, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TupleGenerator generator2 = new TupleGenerator(SEED2, 500, 2048, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TestData.TupleGeneratorIterator gen1Iter = new TestData.TupleGeneratorIterator(generator1, INPUT_1_SIZE); final TestData.TupleGeneratorIterator gen2Iter = new TestData.TupleGeneratorIterator(generator2, INPUT_2_SIZE); final TestData.TupleConstantValueIterator const1Iter = new TestData.TupleConstantValueIterator(DUPLICATE_KEY, "LEFT String for Duplicate Keys", INPUT_1_DUPLICATES); final TestData.TupleConstantValueIterator const2Iter = new TestData.TupleConstantValueIterator(DUPLICATE_KEY, "RIGHT String for Duplicate Keys", INPUT_2_DUPLICATES); final List<MutableObjectIterator<Tuple2<Integer, String>>> inList1 = new ArrayList<MutableObjectIterator<Tuple2<Integer, String>>>(); inList1.add(gen1Iter); inList1.add(const1Iter); final List<MutableObjectIterator<Tuple2<Integer, String>>> inList2 = new ArrayList<MutableObjectIterator<Tuple2<Integer, String>>>(); inList2.add(gen2Iter); inList2.add(const2Iter); MutableObjectIterator<Tuple2<Integer, String>> input1 = new MergeIterator<Tuple2<Integer, String>>(inList1, comparator1.duplicate()); MutableObjectIterator<Tuple2<Integer, String>> input2 = new MergeIterator<Tuple2<Integer, String>>(inList2, comparator2.duplicate()); // collect expected data final Map<Integer, Collection<Match>> expectedMatchesMap = matchValues( collectData(input1), collectData(input2)); // re-create the whole thing for actual processing // reset the generators and iterators generator1.reset(); generator2.reset(); const1Iter.reset(); const2Iter.reset(); gen1Iter.reset(); gen2Iter.reset(); inList1.clear(); inList1.add(gen1Iter); inList1.add(const1Iter); inList2.clear(); inList2.add(gen2Iter); inList2.add(const2Iter); input1 = new MergeIterator<Tuple2<Integer, String>>(inList1, comparator1.duplicate()); input2 = new MergeIterator<Tuple2<Integer, String>>(inList2, comparator2.duplicate()); final FlatJoinFunction<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> joinFunction = new MatchRemovingJoiner(expectedMatchesMap); final Collector<Tuple2<Integer, String>> collector = new DiscardingOutputCollector<Tuple2<Integer, String>>(); // we create this sort-merge iterator with little memory for the block-nested-loops fall-back to make sure it // needs to spill for the duplicate keys NonReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> iterator = new NonReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>>( input1, input2, this.serializer1, this.comparator1, this.serializer2, this.comparator2, this.pairComparator, this.memoryManager, this.ioManager, PAGES_FOR_BNLJN, this.parentTask); iterator.open(); while (iterator.callWithNextKey(joinFunction, collector)); iterator.close(); // assert that each expected match was seen for (Entry<Integer, Collection<Match>> entry : expectedMatchesMap.entrySet()) { if (!entry.getValue().isEmpty()) { Assert.fail("Collection for key " + entry.getKey() + " is not empty"); } } } catch (Exception e) { e.printStackTrace(); Assert.fail("An exception occurred during the test: " + e.getMessage()); } }
Example #14
Source File: NonReusingSortMergeInnerJoinIteratorITCase.java From flink with Apache License 2.0 | 4 votes |
@Test public void testMerge() { try { final TupleGenerator generator1 = new TupleGenerator(SEED1, 500, 4096, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TupleGenerator generator2 = new TupleGenerator(SEED2, 500, 2048, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TestData.TupleGeneratorIterator input1 = new TestData.TupleGeneratorIterator(generator1, INPUT_1_SIZE); final TestData.TupleGeneratorIterator input2 = new TestData.TupleGeneratorIterator(generator2, INPUT_2_SIZE); // collect expected data final Map<Integer, Collection<Match>> expectedMatchesMap = matchValues( collectData(input1), collectData(input2)); final FlatJoinFunction<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> joinFunction = new MatchRemovingJoiner(expectedMatchesMap); final Collector<Tuple2<Integer, String>> collector = new DiscardingOutputCollector<Tuple2<Integer, String>>(); // reset the generators generator1.reset(); generator2.reset(); input1.reset(); input2.reset(); // compare with iterator values NonReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> iterator = new NonReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>>( input1, input2, this.serializer1, this.comparator1, this.serializer2, this.comparator2, this.pairComparator, this.memoryManager, this.ioManager, PAGES_FOR_BNLJN, this.parentTask); iterator.open(); while (iterator.callWithNextKey(joinFunction, collector)); iterator.close(); // assert that each expected match was seen for (Entry<Integer, Collection<Match>> entry : expectedMatchesMap.entrySet()) { Assert.assertTrue("Collection for key " + entry.getKey() + " is not empty", entry.getValue().isEmpty()); } } catch (Exception e) { e.printStackTrace(); Assert.fail("An exception occurred during the test: " + e.getMessage()); } }
Example #15
Source File: ReusingSortMergeInnerJoinIteratorITCase.java From flink with Apache License 2.0 | 4 votes |
@Test public void testMerge() { try { final TupleGenerator generator1 = new TupleGenerator(SEED1, 500, 4096, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TupleGenerator generator2 = new TupleGenerator(SEED2, 500, 2048, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TestData.TupleGeneratorIterator input1 = new TestData.TupleGeneratorIterator(generator1, INPUT_1_SIZE); final TestData.TupleGeneratorIterator input2 = new TestData.TupleGeneratorIterator(generator2, INPUT_2_SIZE); // collect expected data final Map<Integer, Collection<Match>> expectedMatchesMap = matchValues( collectData(input1), collectData(input2)); final FlatJoinFunction<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> joinFunction = new MatchRemovingJoiner(expectedMatchesMap); final Collector<Tuple2<Integer, String>> collector = new DiscardingOutputCollector<Tuple2<Integer, String>>(); // reset the generators generator1.reset(); generator2.reset(); input1.reset(); input2.reset(); // compare with iterator values ReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> iterator = new ReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>>( input1, input2, this.serializer1, this.comparator1, this.serializer2, this.comparator2, this.pairComparator, this.memoryManager, this.ioManager, PAGES_FOR_BNLJN, this.parentTask); iterator.open(); while (iterator.callWithNextKey(joinFunction, collector)); iterator.close(); // assert that each expected match was seen for (Entry<Integer, Collection<Match>> entry : expectedMatchesMap.entrySet()) { Assert.assertTrue("Collection for key " + entry.getKey() + " is not empty", entry.getValue().isEmpty()); } } catch (Exception e) { e.printStackTrace(); Assert.fail("An exception occurred during the test: " + e.getMessage()); } }
Example #16
Source File: ReusingSortMergeInnerJoinIteratorITCase.java From flink with Apache License 2.0 | 4 votes |
@Test public void testMergeWithHighNumberOfCommonKeys() { // the size of the left and right inputs final int INPUT_1_SIZE = 200; final int INPUT_2_SIZE = 100; final int INPUT_1_DUPLICATES = 10; final int INPUT_2_DUPLICATES = 4000; final int DUPLICATE_KEY = 13; try { final TupleGenerator generator1 = new TupleGenerator(SEED1, 500, 4096, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TupleGenerator generator2 = new TupleGenerator(SEED2, 500, 2048, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TestData.TupleGeneratorIterator gen1Iter = new TestData.TupleGeneratorIterator(generator1, INPUT_1_SIZE); final TestData.TupleGeneratorIterator gen2Iter = new TestData.TupleGeneratorIterator(generator2, INPUT_2_SIZE); final TestData.TupleConstantValueIterator const1Iter = new TestData.TupleConstantValueIterator(DUPLICATE_KEY, "LEFT String for Duplicate Keys", INPUT_1_DUPLICATES); final TestData.TupleConstantValueIterator const2Iter = new TestData.TupleConstantValueIterator(DUPLICATE_KEY, "RIGHT String for Duplicate Keys", INPUT_2_DUPLICATES); final List<MutableObjectIterator<Tuple2<Integer, String>>> inList1 = new ArrayList<MutableObjectIterator<Tuple2<Integer, String>>>(); inList1.add(gen1Iter); inList1.add(const1Iter); final List<MutableObjectIterator<Tuple2<Integer, String>>> inList2 = new ArrayList<MutableObjectIterator<Tuple2<Integer, String>>>(); inList2.add(gen2Iter); inList2.add(const2Iter); MutableObjectIterator<Tuple2<Integer, String>> input1 = new MergeIterator<Tuple2<Integer, String>>(inList1, comparator1.duplicate()); MutableObjectIterator<Tuple2<Integer, String>> input2 = new MergeIterator<Tuple2<Integer, String>>(inList2, comparator2.duplicate()); // collect expected data final Map<Integer, Collection<Match>> expectedMatchesMap = matchValues( collectData(input1), collectData(input2)); // re-create the whole thing for actual processing // reset the generators and iterators generator1.reset(); generator2.reset(); const1Iter.reset(); const2Iter.reset(); gen1Iter.reset(); gen2Iter.reset(); inList1.clear(); inList1.add(gen1Iter); inList1.add(const1Iter); inList2.clear(); inList2.add(gen2Iter); inList2.add(const2Iter); input1 = new MergeIterator<Tuple2<Integer, String>>(inList1, comparator1.duplicate()); input2 = new MergeIterator<Tuple2<Integer, String>>(inList2, comparator2.duplicate()); final FlatJoinFunction<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> matcher = new MatchRemovingJoiner(expectedMatchesMap); final Collector<Tuple2<Integer, String>> collector = new DiscardingOutputCollector<Tuple2<Integer, String>>(); // we create this sort-merge iterator with little memory for the block-nested-loops fall-back to make sure it // needs to spill for the duplicate keys ReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> iterator = new ReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>>( input1, input2, this.serializer1, this.comparator1, this.serializer2, this.comparator2, this.pairComparator, this.memoryManager, this.ioManager, PAGES_FOR_BNLJN, this.parentTask); iterator.open(); while (iterator.callWithNextKey(matcher, collector)); iterator.close(); // assert that each expected match was seen for (Entry<Integer, Collection<Match>> entry : expectedMatchesMap.entrySet()) { if (!entry.getValue().isEmpty()) { Assert.fail("Collection for key " + entry.getKey() + " is not empty"); } } } catch (Exception e) { e.printStackTrace(); Assert.fail("An exception occurred during the test: " + e.getMessage()); } }
Example #17
Source File: RandomSortMergeInnerJoinTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testMergeWithHighNumberOfCommonKeys() { // the size of the left and right inputs final int input1Size = 200; final int input2Size = 100; final int input1Duplicates = 10; final int input2Duplicates = 4000; final int duplicateKey = 13; try { final TupleGenerator generator1 = new TupleGenerator(SEED1, 500, 4096, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TupleGenerator generator2 = new TupleGenerator(SEED2, 500, 2048, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TestData.TupleGeneratorIterator gen1Iter = new TestData.TupleGeneratorIterator(generator1, input1Size); final TestData.TupleGeneratorIterator gen2Iter = new TestData.TupleGeneratorIterator(generator2, input2Size); final TestData.TupleConstantValueIterator const1Iter = new TestData.TupleConstantValueIterator(duplicateKey, "LEFT String for Duplicate Keys", input1Duplicates); final TestData.TupleConstantValueIterator const2Iter = new TestData.TupleConstantValueIterator(duplicateKey, "RIGHT String for Duplicate Keys", input2Duplicates); final List<MutableObjectIterator<Tuple2<Integer, String>>> inList1 = new ArrayList<>(); inList1.add(gen1Iter); inList1.add(const1Iter); final List<MutableObjectIterator<Tuple2<Integer, String>>> inList2 = new ArrayList<>(); inList2.add(gen2Iter); inList2.add(const2Iter); MutableObjectIterator<Tuple2<Integer, String>> input1 = new MergeIterator<>(inList1, comparator1.duplicate()); MutableObjectIterator<Tuple2<Integer, String>> input2 = new MergeIterator<>(inList2, comparator2.duplicate()); // collect expected data final Map<Integer, Collection<Match>> expectedMatchesMap = matchValues( collectData(input1), collectData(input2)); // re-create the whole thing for actual processing // reset the generators and iterators generator1.reset(); generator2.reset(); const1Iter.reset(); const2Iter.reset(); gen1Iter.reset(); gen2Iter.reset(); inList1.clear(); inList1.add(gen1Iter); inList1.add(const1Iter); inList2.clear(); inList2.add(gen2Iter); inList2.add(const2Iter); input1 = new MergeIterator<>(inList1, comparator1.duplicate()); input2 = new MergeIterator<>(inList2, comparator2.duplicate()); StreamOperator operator = getOperator(); match(expectedMatchesMap, transformToBinary(join(operator, input1, input2))); // assert that each expected match was seen for (Map.Entry<Integer, Collection<Match>> entry : expectedMatchesMap.entrySet()) { if (!entry.getValue().isEmpty()) { Assert.fail("Collection for key " + entry.getKey() + " is not empty"); } } } catch (Exception e) { e.printStackTrace(); Assert.fail("An exception occurred during the test: " + e.getMessage()); } }
Example #18
Source File: ReusingSortMergeInnerJoinIteratorITCase.java From flink with Apache License 2.0 | 4 votes |
@Test public void testMerge() { try { final TupleGenerator generator1 = new TupleGenerator(SEED1, 500, 4096, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TupleGenerator generator2 = new TupleGenerator(SEED2, 500, 2048, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TestData.TupleGeneratorIterator input1 = new TestData.TupleGeneratorIterator(generator1, INPUT_1_SIZE); final TestData.TupleGeneratorIterator input2 = new TestData.TupleGeneratorIterator(generator2, INPUT_2_SIZE); // collect expected data final Map<Integer, Collection<Match>> expectedMatchesMap = matchValues( collectData(input1), collectData(input2)); final FlatJoinFunction<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> joinFunction = new MatchRemovingJoiner(expectedMatchesMap); final Collector<Tuple2<Integer, String>> collector = new DiscardingOutputCollector<Tuple2<Integer, String>>(); // reset the generators generator1.reset(); generator2.reset(); input1.reset(); input2.reset(); // compare with iterator values ReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> iterator = new ReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>>( input1, input2, this.serializer1, this.comparator1, this.serializer2, this.comparator2, this.pairComparator, this.memoryManager, this.ioManager, PAGES_FOR_BNLJN, this.parentTask); iterator.open(); while (iterator.callWithNextKey(joinFunction, collector)); iterator.close(); // assert that each expected match was seen for (Entry<Integer, Collection<Match>> entry : expectedMatchesMap.entrySet()) { Assert.assertTrue("Collection for key " + entry.getKey() + " is not empty", entry.getValue().isEmpty()); } } catch (Exception e) { e.printStackTrace(); Assert.fail("An exception occurred during the test: " + e.getMessage()); } }
Example #19
Source File: RandomSortMergeOuterJoinTest.java From flink with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked, rawtypes") protected void testOuterJoinWithHighNumberOfCommonKeys( FlinkJoinType outerJoinType, int input1Size, int input1Duplicates, int input1ValueLength, float input1KeyDensity, int input2Size, int input2Duplicates, int input2ValueLength, float input2KeyDensity) { TypeComparator<Tuple2<Integer, String>> comparator1 = new TupleComparator<>( new int[]{0}, new TypeComparator<?>[]{new IntComparator(true)}, new TypeSerializer<?>[]{IntSerializer.INSTANCE} ); TypeComparator<Tuple2<Integer, String>> comparator2 = new TupleComparator<>( new int[]{0}, new TypeComparator<?>[]{new IntComparator(true)}, new TypeSerializer<?>[]{IntSerializer.INSTANCE} ); final int duplicateKey = 13; try { final TupleGenerator generator1 = new TupleGenerator(SEED1, 500, input1KeyDensity, input1ValueLength, KeyMode.SORTED_SPARSE, ValueMode.RANDOM_LENGTH, null); final TupleGenerator generator2 = new TupleGenerator(SEED2, 500, input2KeyDensity, input2ValueLength, KeyMode.SORTED_SPARSE, ValueMode.RANDOM_LENGTH, null); final TupleGeneratorIterator gen1Iter = new TupleGeneratorIterator(generator1, input1Size); final TupleGeneratorIterator gen2Iter = new TupleGeneratorIterator(generator2, input2Size); final TupleConstantValueIterator const1Iter = new TupleConstantValueIterator(duplicateKey, "LEFT String for Duplicate Keys", input1Duplicates); final TupleConstantValueIterator const2Iter = new TupleConstantValueIterator(duplicateKey, "RIGHT String for Duplicate Keys", input2Duplicates); final List<MutableObjectIterator<Tuple2<Integer, String>>> inList1 = new ArrayList<>(); inList1.add(gen1Iter); inList1.add(const1Iter); final List<MutableObjectIterator<Tuple2<Integer, String>>> inList2 = new ArrayList<>(); inList2.add(gen2Iter); inList2.add(const2Iter); MutableObjectIterator<Tuple2<Integer, String>> input1 = new MergeIterator<>(inList1, comparator1.duplicate()); MutableObjectIterator<Tuple2<Integer, String>> input2 = new MergeIterator<>(inList2, comparator2.duplicate()); // collect expected data final Map<Integer, Collection<Match>> expectedMatchesMap = joinValues( RandomSortMergeInnerJoinTest.collectData(input1), RandomSortMergeInnerJoinTest.collectData(input2), outerJoinType); // re-create the whole thing for actual processing // reset the generators and iterators generator1.reset(); generator2.reset(); const1Iter.reset(); const2Iter.reset(); gen1Iter.reset(); gen2Iter.reset(); inList1.clear(); inList1.add(gen1Iter); inList1.add(const1Iter); inList2.clear(); inList2.add(gen2Iter); inList2.add(const2Iter); input1 = new MergeIterator<>(inList1, comparator1.duplicate()); input2 = new MergeIterator<>(inList2, comparator2.duplicate()); StreamOperator operator = getOperator(outerJoinType); RandomSortMergeInnerJoinTest.match(expectedMatchesMap, RandomSortMergeInnerJoinTest.transformToBinary(myJoin(operator, input1, input2))); // assert that each expected match was seen for (Entry<Integer, Collection<Match>> entry : expectedMatchesMap.entrySet()) { if (!entry.getValue().isEmpty()) { Assert.fail("Collection for key " + entry.getKey() + " is not empty"); } } } catch (Exception e) { e.printStackTrace(); Assert.fail("An exception occurred during the test: " + e.getMessage()); } }
Example #20
Source File: ReusingSortMergeInnerJoinIteratorITCase.java From flink with Apache License 2.0 | 4 votes |
@Test public void testMergeWithHighNumberOfCommonKeys() { // the size of the left and right inputs final int INPUT_1_SIZE = 200; final int INPUT_2_SIZE = 100; final int INPUT_1_DUPLICATES = 10; final int INPUT_2_DUPLICATES = 4000; final int DUPLICATE_KEY = 13; try { final TupleGenerator generator1 = new TupleGenerator(SEED1, 500, 4096, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TupleGenerator generator2 = new TupleGenerator(SEED2, 500, 2048, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TestData.TupleGeneratorIterator gen1Iter = new TestData.TupleGeneratorIterator(generator1, INPUT_1_SIZE); final TestData.TupleGeneratorIterator gen2Iter = new TestData.TupleGeneratorIterator(generator2, INPUT_2_SIZE); final TestData.TupleConstantValueIterator const1Iter = new TestData.TupleConstantValueIterator(DUPLICATE_KEY, "LEFT String for Duplicate Keys", INPUT_1_DUPLICATES); final TestData.TupleConstantValueIterator const2Iter = new TestData.TupleConstantValueIterator(DUPLICATE_KEY, "RIGHT String for Duplicate Keys", INPUT_2_DUPLICATES); final List<MutableObjectIterator<Tuple2<Integer, String>>> inList1 = new ArrayList<MutableObjectIterator<Tuple2<Integer, String>>>(); inList1.add(gen1Iter); inList1.add(const1Iter); final List<MutableObjectIterator<Tuple2<Integer, String>>> inList2 = new ArrayList<MutableObjectIterator<Tuple2<Integer, String>>>(); inList2.add(gen2Iter); inList2.add(const2Iter); MutableObjectIterator<Tuple2<Integer, String>> input1 = new MergeIterator<Tuple2<Integer, String>>(inList1, comparator1.duplicate()); MutableObjectIterator<Tuple2<Integer, String>> input2 = new MergeIterator<Tuple2<Integer, String>>(inList2, comparator2.duplicate()); // collect expected data final Map<Integer, Collection<Match>> expectedMatchesMap = matchValues( collectData(input1), collectData(input2)); // re-create the whole thing for actual processing // reset the generators and iterators generator1.reset(); generator2.reset(); const1Iter.reset(); const2Iter.reset(); gen1Iter.reset(); gen2Iter.reset(); inList1.clear(); inList1.add(gen1Iter); inList1.add(const1Iter); inList2.clear(); inList2.add(gen2Iter); inList2.add(const2Iter); input1 = new MergeIterator<Tuple2<Integer, String>>(inList1, comparator1.duplicate()); input2 = new MergeIterator<Tuple2<Integer, String>>(inList2, comparator2.duplicate()); final FlatJoinFunction<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> matcher = new MatchRemovingJoiner(expectedMatchesMap); final Collector<Tuple2<Integer, String>> collector = new DiscardingOutputCollector<Tuple2<Integer, String>>(); // we create this sort-merge iterator with little memory for the block-nested-loops fall-back to make sure it // needs to spill for the duplicate keys ReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> iterator = new ReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>>( input1, input2, this.serializer1, this.comparator1, this.serializer2, this.comparator2, this.pairComparator, this.memoryManager, this.ioManager, PAGES_FOR_BNLJN, this.parentTask); iterator.open(); while (iterator.callWithNextKey(matcher, collector)); iterator.close(); // assert that each expected match was seen for (Entry<Integer, Collection<Match>> entry : expectedMatchesMap.entrySet()) { if (!entry.getValue().isEmpty()) { Assert.fail("Collection for key " + entry.getKey() + " is not empty"); } } } catch (Exception e) { e.printStackTrace(); Assert.fail("An exception occurred during the test: " + e.getMessage()); } }
Example #21
Source File: NonReusingSortMergeInnerJoinIteratorITCase.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void testMerge() { try { final TupleGenerator generator1 = new TupleGenerator(SEED1, 500, 4096, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TupleGenerator generator2 = new TupleGenerator(SEED2, 500, 2048, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TestData.TupleGeneratorIterator input1 = new TestData.TupleGeneratorIterator(generator1, INPUT_1_SIZE); final TestData.TupleGeneratorIterator input2 = new TestData.TupleGeneratorIterator(generator2, INPUT_2_SIZE); // collect expected data final Map<Integer, Collection<Match>> expectedMatchesMap = matchValues( collectData(input1), collectData(input2)); final FlatJoinFunction<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> joinFunction = new MatchRemovingJoiner(expectedMatchesMap); final Collector<Tuple2<Integer, String>> collector = new DiscardingOutputCollector<Tuple2<Integer, String>>(); // reset the generators generator1.reset(); generator2.reset(); input1.reset(); input2.reset(); // compare with iterator values NonReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> iterator = new NonReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>>( input1, input2, this.serializer1, this.comparator1, this.serializer2, this.comparator2, this.pairComparator, this.memoryManager, this.ioManager, PAGES_FOR_BNLJN, this.parentTask); iterator.open(); while (iterator.callWithNextKey(joinFunction, collector)); iterator.close(); // assert that each expected match was seen for (Entry<Integer, Collection<Match>> entry : expectedMatchesMap.entrySet()) { Assert.assertTrue("Collection for key " + entry.getKey() + " is not empty", entry.getValue().isEmpty()); } } catch (Exception e) { e.printStackTrace(); Assert.fail("An exception occurred during the test: " + e.getMessage()); } }
Example #22
Source File: NonReusingSortMergeInnerJoinIteratorITCase.java From flink with Apache License 2.0 | 4 votes |
@Test public void testMergeWithHighNumberOfCommonKeys() { // the size of the left and right inputs final int INPUT_1_SIZE = 200; final int INPUT_2_SIZE = 100; final int INPUT_1_DUPLICATES = 10; final int INPUT_2_DUPLICATES = 4000; final int DUPLICATE_KEY = 13; try { final TupleGenerator generator1 = new TupleGenerator(SEED1, 500, 4096, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TupleGenerator generator2 = new TupleGenerator(SEED2, 500, 2048, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TestData.TupleGeneratorIterator gen1Iter = new TestData.TupleGeneratorIterator(generator1, INPUT_1_SIZE); final TestData.TupleGeneratorIterator gen2Iter = new TestData.TupleGeneratorIterator(generator2, INPUT_2_SIZE); final TestData.TupleConstantValueIterator const1Iter = new TestData.TupleConstantValueIterator(DUPLICATE_KEY, "LEFT String for Duplicate Keys", INPUT_1_DUPLICATES); final TestData.TupleConstantValueIterator const2Iter = new TestData.TupleConstantValueIterator(DUPLICATE_KEY, "RIGHT String for Duplicate Keys", INPUT_2_DUPLICATES); final List<MutableObjectIterator<Tuple2<Integer, String>>> inList1 = new ArrayList<MutableObjectIterator<Tuple2<Integer, String>>>(); inList1.add(gen1Iter); inList1.add(const1Iter); final List<MutableObjectIterator<Tuple2<Integer, String>>> inList2 = new ArrayList<MutableObjectIterator<Tuple2<Integer, String>>>(); inList2.add(gen2Iter); inList2.add(const2Iter); MutableObjectIterator<Tuple2<Integer, String>> input1 = new MergeIterator<Tuple2<Integer, String>>(inList1, comparator1.duplicate()); MutableObjectIterator<Tuple2<Integer, String>> input2 = new MergeIterator<Tuple2<Integer, String>>(inList2, comparator2.duplicate()); // collect expected data final Map<Integer, Collection<Match>> expectedMatchesMap = matchValues( collectData(input1), collectData(input2)); // re-create the whole thing for actual processing // reset the generators and iterators generator1.reset(); generator2.reset(); const1Iter.reset(); const2Iter.reset(); gen1Iter.reset(); gen2Iter.reset(); inList1.clear(); inList1.add(gen1Iter); inList1.add(const1Iter); inList2.clear(); inList2.add(gen2Iter); inList2.add(const2Iter); input1 = new MergeIterator<Tuple2<Integer, String>>(inList1, comparator1.duplicate()); input2 = new MergeIterator<Tuple2<Integer, String>>(inList2, comparator2.duplicate()); final FlatJoinFunction<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> joinFunction = new MatchRemovingJoiner(expectedMatchesMap); final Collector<Tuple2<Integer, String>> collector = new DiscardingOutputCollector<Tuple2<Integer, String>>(); // we create this sort-merge iterator with little memory for the block-nested-loops fall-back to make sure it // needs to spill for the duplicate keys NonReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> iterator = new NonReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>>( input1, input2, this.serializer1, this.comparator1, this.serializer2, this.comparator2, this.pairComparator, this.memoryManager, this.ioManager, PAGES_FOR_BNLJN, this.parentTask); iterator.open(); while (iterator.callWithNextKey(joinFunction, collector)); iterator.close(); // assert that each expected match was seen for (Entry<Integer, Collection<Match>> entry : expectedMatchesMap.entrySet()) { if (!entry.getValue().isEmpty()) { Assert.fail("Collection for key " + entry.getKey() + " is not empty"); } } } catch (Exception e) { e.printStackTrace(); Assert.fail("An exception occurred during the test: " + e.getMessage()); } }
Example #23
Source File: NonReusingSortMergeInnerJoinIteratorITCase.java From flink with Apache License 2.0 | 4 votes |
@Test public void testMerge() { try { final TupleGenerator generator1 = new TupleGenerator(SEED1, 500, 4096, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TupleGenerator generator2 = new TupleGenerator(SEED2, 500, 2048, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TestData.TupleGeneratorIterator input1 = new TestData.TupleGeneratorIterator(generator1, INPUT_1_SIZE); final TestData.TupleGeneratorIterator input2 = new TestData.TupleGeneratorIterator(generator2, INPUT_2_SIZE); // collect expected data final Map<Integer, Collection<Match>> expectedMatchesMap = matchValues( collectData(input1), collectData(input2)); final FlatJoinFunction<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> joinFunction = new MatchRemovingJoiner(expectedMatchesMap); final Collector<Tuple2<Integer, String>> collector = new DiscardingOutputCollector<Tuple2<Integer, String>>(); // reset the generators generator1.reset(); generator2.reset(); input1.reset(); input2.reset(); // compare with iterator values NonReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> iterator = new NonReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>>( input1, input2, this.serializer1, this.comparator1, this.serializer2, this.comparator2, this.pairComparator, this.memoryManager, this.ioManager, PAGES_FOR_BNLJN, this.parentTask); iterator.open(); while (iterator.callWithNextKey(joinFunction, collector)); iterator.close(); // assert that each expected match was seen for (Entry<Integer, Collection<Match>> entry : expectedMatchesMap.entrySet()) { Assert.assertTrue("Collection for key " + entry.getKey() + " is not empty", entry.getValue().isEmpty()); } } catch (Exception e) { e.printStackTrace(); Assert.fail("An exception occurred during the test: " + e.getMessage()); } }
Example #24
Source File: RandomSortMergeInnerJoinTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testMergeWithHighNumberOfCommonKeys() { // the size of the left and right inputs final int input1Size = 200; final int input2Size = 100; final int input1Duplicates = 10; final int input2Duplicates = 4000; final int duplicateKey = 13; try { final TupleGenerator generator1 = new TupleGenerator(SEED1, 500, 4096, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TupleGenerator generator2 = new TupleGenerator(SEED2, 500, 2048, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TestData.TupleGeneratorIterator gen1Iter = new TestData.TupleGeneratorIterator(generator1, input1Size); final TestData.TupleGeneratorIterator gen2Iter = new TestData.TupleGeneratorIterator(generator2, input2Size); final TestData.TupleConstantValueIterator const1Iter = new TestData.TupleConstantValueIterator(duplicateKey, "LEFT String for Duplicate Keys", input1Duplicates); final TestData.TupleConstantValueIterator const2Iter = new TestData.TupleConstantValueIterator(duplicateKey, "RIGHT String for Duplicate Keys", input2Duplicates); final List<MutableObjectIterator<Tuple2<Integer, String>>> inList1 = new ArrayList<>(); inList1.add(gen1Iter); inList1.add(const1Iter); final List<MutableObjectIterator<Tuple2<Integer, String>>> inList2 = new ArrayList<>(); inList2.add(gen2Iter); inList2.add(const2Iter); MutableObjectIterator<Tuple2<Integer, String>> input1 = new MergeIterator<>(inList1, comparator1.duplicate()); MutableObjectIterator<Tuple2<Integer, String>> input2 = new MergeIterator<>(inList2, comparator2.duplicate()); // collect expected data final Map<Integer, Collection<Match>> expectedMatchesMap = matchValues( collectData(input1), collectData(input2)); // re-create the whole thing for actual processing // reset the generators and iterators generator1.reset(); generator2.reset(); const1Iter.reset(); const2Iter.reset(); gen1Iter.reset(); gen2Iter.reset(); inList1.clear(); inList1.add(gen1Iter); inList1.add(const1Iter); inList2.clear(); inList2.add(gen2Iter); inList2.add(const2Iter); input1 = new MergeIterator<>(inList1, comparator1.duplicate()); input2 = new MergeIterator<>(inList2, comparator2.duplicate()); StreamOperator operator = getOperator(); match(expectedMatchesMap, transformToBinary(join(operator, input1, input2))); // assert that each expected match was seen for (Map.Entry<Integer, Collection<Match>> entry : expectedMatchesMap.entrySet()) { if (!entry.getValue().isEmpty()) { Assert.fail("Collection for key " + entry.getKey() + " is not empty"); } } } catch (Exception e) { e.printStackTrace(); Assert.fail("An exception occurred during the test: " + e.getMessage()); } }
Example #25
Source File: RandomSortMergeOuterJoinTest.java From flink with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked, rawtypes") protected void testOuterJoinWithHighNumberOfCommonKeys( FlinkJoinType outerJoinType, int input1Size, int input1Duplicates, int input1ValueLength, float input1KeyDensity, int input2Size, int input2Duplicates, int input2ValueLength, float input2KeyDensity) { TypeComparator<Tuple2<Integer, String>> comparator1 = new TupleComparator<>( new int[]{0}, new TypeComparator<?>[]{new IntComparator(true)}, new TypeSerializer<?>[]{IntSerializer.INSTANCE} ); TypeComparator<Tuple2<Integer, String>> comparator2 = new TupleComparator<>( new int[]{0}, new TypeComparator<?>[]{new IntComparator(true)}, new TypeSerializer<?>[]{IntSerializer.INSTANCE} ); final int duplicateKey = 13; try { final TupleGenerator generator1 = new TupleGenerator(SEED1, 500, input1KeyDensity, input1ValueLength, KeyMode.SORTED_SPARSE, ValueMode.RANDOM_LENGTH, null); final TupleGenerator generator2 = new TupleGenerator(SEED2, 500, input2KeyDensity, input2ValueLength, KeyMode.SORTED_SPARSE, ValueMode.RANDOM_LENGTH, null); final TupleGeneratorIterator gen1Iter = new TupleGeneratorIterator(generator1, input1Size); final TupleGeneratorIterator gen2Iter = new TupleGeneratorIterator(generator2, input2Size); final TupleConstantValueIterator const1Iter = new TupleConstantValueIterator(duplicateKey, "LEFT String for Duplicate Keys", input1Duplicates); final TupleConstantValueIterator const2Iter = new TupleConstantValueIterator(duplicateKey, "RIGHT String for Duplicate Keys", input2Duplicates); final List<MutableObjectIterator<Tuple2<Integer, String>>> inList1 = new ArrayList<>(); inList1.add(gen1Iter); inList1.add(const1Iter); final List<MutableObjectIterator<Tuple2<Integer, String>>> inList2 = new ArrayList<>(); inList2.add(gen2Iter); inList2.add(const2Iter); MutableObjectIterator<Tuple2<Integer, String>> input1 = new MergeIterator<>(inList1, comparator1.duplicate()); MutableObjectIterator<Tuple2<Integer, String>> input2 = new MergeIterator<>(inList2, comparator2.duplicate()); // collect expected data final Map<Integer, Collection<Match>> expectedMatchesMap = joinValues( RandomSortMergeInnerJoinTest.collectData(input1), RandomSortMergeInnerJoinTest.collectData(input2), outerJoinType); // re-create the whole thing for actual processing // reset the generators and iterators generator1.reset(); generator2.reset(); const1Iter.reset(); const2Iter.reset(); gen1Iter.reset(); gen2Iter.reset(); inList1.clear(); inList1.add(gen1Iter); inList1.add(const1Iter); inList2.clear(); inList2.add(gen2Iter); inList2.add(const2Iter); input1 = new MergeIterator<>(inList1, comparator1.duplicate()); input2 = new MergeIterator<>(inList2, comparator2.duplicate()); StreamOperator operator = getOperator(outerJoinType); RandomSortMergeInnerJoinTest.match(expectedMatchesMap, RandomSortMergeInnerJoinTest.transformToBinary(myJoin(operator, input1, input2))); // assert that each expected match was seen for (Entry<Integer, Collection<Match>> entry : expectedMatchesMap.entrySet()) { if (!entry.getValue().isEmpty()) { Assert.fail("Collection for key " + entry.getKey() + " is not empty"); } } } catch (Exception e) { e.printStackTrace(); Assert.fail("An exception occurred during the test: " + e.getMessage()); } }
Example #26
Source File: ReusingSortMergeInnerJoinIteratorITCase.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void testMergeWithHighNumberOfCommonKeys() { // the size of the left and right inputs final int INPUT_1_SIZE = 200; final int INPUT_2_SIZE = 100; final int INPUT_1_DUPLICATES = 10; final int INPUT_2_DUPLICATES = 4000; final int DUPLICATE_KEY = 13; try { final TupleGenerator generator1 = new TupleGenerator(SEED1, 500, 4096, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TupleGenerator generator2 = new TupleGenerator(SEED2, 500, 2048, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TestData.TupleGeneratorIterator gen1Iter = new TestData.TupleGeneratorIterator(generator1, INPUT_1_SIZE); final TestData.TupleGeneratorIterator gen2Iter = new TestData.TupleGeneratorIterator(generator2, INPUT_2_SIZE); final TestData.TupleConstantValueIterator const1Iter = new TestData.TupleConstantValueIterator(DUPLICATE_KEY, "LEFT String for Duplicate Keys", INPUT_1_DUPLICATES); final TestData.TupleConstantValueIterator const2Iter = new TestData.TupleConstantValueIterator(DUPLICATE_KEY, "RIGHT String for Duplicate Keys", INPUT_2_DUPLICATES); final List<MutableObjectIterator<Tuple2<Integer, String>>> inList1 = new ArrayList<MutableObjectIterator<Tuple2<Integer, String>>>(); inList1.add(gen1Iter); inList1.add(const1Iter); final List<MutableObjectIterator<Tuple2<Integer, String>>> inList2 = new ArrayList<MutableObjectIterator<Tuple2<Integer, String>>>(); inList2.add(gen2Iter); inList2.add(const2Iter); MutableObjectIterator<Tuple2<Integer, String>> input1 = new MergeIterator<Tuple2<Integer, String>>(inList1, comparator1.duplicate()); MutableObjectIterator<Tuple2<Integer, String>> input2 = new MergeIterator<Tuple2<Integer, String>>(inList2, comparator2.duplicate()); // collect expected data final Map<Integer, Collection<Match>> expectedMatchesMap = matchValues( collectData(input1), collectData(input2)); // re-create the whole thing for actual processing // reset the generators and iterators generator1.reset(); generator2.reset(); const1Iter.reset(); const2Iter.reset(); gen1Iter.reset(); gen2Iter.reset(); inList1.clear(); inList1.add(gen1Iter); inList1.add(const1Iter); inList2.clear(); inList2.add(gen2Iter); inList2.add(const2Iter); input1 = new MergeIterator<Tuple2<Integer, String>>(inList1, comparator1.duplicate()); input2 = new MergeIterator<Tuple2<Integer, String>>(inList2, comparator2.duplicate()); final FlatJoinFunction<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> matcher = new MatchRemovingJoiner(expectedMatchesMap); final Collector<Tuple2<Integer, String>> collector = new DiscardingOutputCollector<Tuple2<Integer, String>>(); // we create this sort-merge iterator with little memory for the block-nested-loops fall-back to make sure it // needs to spill for the duplicate keys ReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> iterator = new ReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>>( input1, input2, this.serializer1, this.comparator1, this.serializer2, this.comparator2, this.pairComparator, this.memoryManager, this.ioManager, PAGES_FOR_BNLJN, this.parentTask); iterator.open(); while (iterator.callWithNextKey(matcher, collector)); iterator.close(); // assert that each expected match was seen for (Entry<Integer, Collection<Match>> entry : expectedMatchesMap.entrySet()) { if (!entry.getValue().isEmpty()) { Assert.fail("Collection for key " + entry.getKey() + " is not empty"); } } } catch (Exception e) { e.printStackTrace(); Assert.fail("An exception occurred during the test: " + e.getMessage()); } }
Example #27
Source File: ReusingSortMergeInnerJoinIteratorITCase.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void testMerge() { try { final TupleGenerator generator1 = new TupleGenerator(SEED1, 500, 4096, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TupleGenerator generator2 = new TupleGenerator(SEED2, 500, 2048, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TestData.TupleGeneratorIterator input1 = new TestData.TupleGeneratorIterator(generator1, INPUT_1_SIZE); final TestData.TupleGeneratorIterator input2 = new TestData.TupleGeneratorIterator(generator2, INPUT_2_SIZE); // collect expected data final Map<Integer, Collection<Match>> expectedMatchesMap = matchValues( collectData(input1), collectData(input2)); final FlatJoinFunction<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> joinFunction = new MatchRemovingJoiner(expectedMatchesMap); final Collector<Tuple2<Integer, String>> collector = new DiscardingOutputCollector<Tuple2<Integer, String>>(); // reset the generators generator1.reset(); generator2.reset(); input1.reset(); input2.reset(); // compare with iterator values ReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> iterator = new ReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>>( input1, input2, this.serializer1, this.comparator1, this.serializer2, this.comparator2, this.pairComparator, this.memoryManager, this.ioManager, PAGES_FOR_BNLJN, this.parentTask); iterator.open(); while (iterator.callWithNextKey(joinFunction, collector)); iterator.close(); // assert that each expected match was seen for (Entry<Integer, Collection<Match>> entry : expectedMatchesMap.entrySet()) { Assert.assertTrue("Collection for key " + entry.getKey() + " is not empty", entry.getValue().isEmpty()); } } catch (Exception e) { e.printStackTrace(); Assert.fail("An exception occurred during the test: " + e.getMessage()); } }
Example #28
Source File: NonReusingSortMergeInnerJoinIteratorITCase.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void testMergeWithHighNumberOfCommonKeys() { // the size of the left and right inputs final int INPUT_1_SIZE = 200; final int INPUT_2_SIZE = 100; final int INPUT_1_DUPLICATES = 10; final int INPUT_2_DUPLICATES = 4000; final int DUPLICATE_KEY = 13; try { final TupleGenerator generator1 = new TupleGenerator(SEED1, 500, 4096, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TupleGenerator generator2 = new TupleGenerator(SEED2, 500, 2048, KeyMode.SORTED, ValueMode.RANDOM_LENGTH); final TestData.TupleGeneratorIterator gen1Iter = new TestData.TupleGeneratorIterator(generator1, INPUT_1_SIZE); final TestData.TupleGeneratorIterator gen2Iter = new TestData.TupleGeneratorIterator(generator2, INPUT_2_SIZE); final TestData.TupleConstantValueIterator const1Iter = new TestData.TupleConstantValueIterator(DUPLICATE_KEY, "LEFT String for Duplicate Keys", INPUT_1_DUPLICATES); final TestData.TupleConstantValueIterator const2Iter = new TestData.TupleConstantValueIterator(DUPLICATE_KEY, "RIGHT String for Duplicate Keys", INPUT_2_DUPLICATES); final List<MutableObjectIterator<Tuple2<Integer, String>>> inList1 = new ArrayList<MutableObjectIterator<Tuple2<Integer, String>>>(); inList1.add(gen1Iter); inList1.add(const1Iter); final List<MutableObjectIterator<Tuple2<Integer, String>>> inList2 = new ArrayList<MutableObjectIterator<Tuple2<Integer, String>>>(); inList2.add(gen2Iter); inList2.add(const2Iter); MutableObjectIterator<Tuple2<Integer, String>> input1 = new MergeIterator<Tuple2<Integer, String>>(inList1, comparator1.duplicate()); MutableObjectIterator<Tuple2<Integer, String>> input2 = new MergeIterator<Tuple2<Integer, String>>(inList2, comparator2.duplicate()); // collect expected data final Map<Integer, Collection<Match>> expectedMatchesMap = matchValues( collectData(input1), collectData(input2)); // re-create the whole thing for actual processing // reset the generators and iterators generator1.reset(); generator2.reset(); const1Iter.reset(); const2Iter.reset(); gen1Iter.reset(); gen2Iter.reset(); inList1.clear(); inList1.add(gen1Iter); inList1.add(const1Iter); inList2.clear(); inList2.add(gen2Iter); inList2.add(const2Iter); input1 = new MergeIterator<Tuple2<Integer, String>>(inList1, comparator1.duplicate()); input2 = new MergeIterator<Tuple2<Integer, String>>(inList2, comparator2.duplicate()); final FlatJoinFunction<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> joinFunction = new MatchRemovingJoiner(expectedMatchesMap); final Collector<Tuple2<Integer, String>> collector = new DiscardingOutputCollector<Tuple2<Integer, String>>(); // we create this sort-merge iterator with little memory for the block-nested-loops fall-back to make sure it // needs to spill for the duplicate keys NonReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>> iterator = new NonReusingMergeInnerJoinIterator<Tuple2<Integer, String>, Tuple2<Integer, String>, Tuple2<Integer, String>>( input1, input2, this.serializer1, this.comparator1, this.serializer2, this.comparator2, this.pairComparator, this.memoryManager, this.ioManager, PAGES_FOR_BNLJN, this.parentTask); iterator.open(); while (iterator.callWithNextKey(joinFunction, collector)); iterator.close(); // assert that each expected match was seen for (Entry<Integer, Collection<Match>> entry : expectedMatchesMap.entrySet()) { if (!entry.getValue().isEmpty()) { Assert.fail("Collection for key " + entry.getKey() + " is not empty"); } } } catch (Exception e) { e.printStackTrace(); Assert.fail("An exception occurred during the test: " + e.getMessage()); } }