@Override protected Dataset<Pair<String, List<Long>>> getOutput(Dataset<Pair<String, Long>> input) { return ReduceByKey.of(input) .keyBy(Pair::getFirst, String.class) .valueBy(Pair::getSecond) .reduceBy((Stream<Long> values, Collector<List<Long>> coll) -> coll.collect(values.limit(2).collect(Collectors.toList()))) .withSortedValues(Long::compareTo) .output(); } });
@Override protected Dataset<Pair<String, List<Long>>> getOutput(Dataset<Pair<String, Long>> input) { return ReduceByKey.of(input) .keyBy(Pair::getFirst, String.class) .valueBy(Pair::getSecond) .reduceBy((Stream<Long> values, Collector<List<Long>> coll) -> coll.collect(values.limit(2).collect(Collectors.toList()))) .withSortedValues(Long::compareTo) .output(); } });
@Override protected Dataset<Pair<Integer, Set<Integer>>> getOutput(Dataset<Integer> input) { return ReduceByKey.of(input) .keyBy(e -> e % 2, Integer.class) .valueBy(e -> e) .reduceBy(s -> s.collect(Collectors.toSet())) .windowBy(Count.of(3)) .output(); }
@Override protected Dataset<Pair<Word, Long>> getOutput(Dataset<Pair<Word, Long>> input) { input = AssignEventTime.of(input).using(Pair::getSecond).output(); return ReduceByKey.of(input) .keyBy(Pair::getFirst) .valueBy(e -> 1L) .combineBy(Sums.ofLongs()) .windowBy(Time.of(Duration.ofSeconds(1))) .output(); }
@Override protected Dataset<Pair<String, List<Long>>> getOutput(Dataset<Pair<String, Long>> input) { return ReduceByKey.of(input) .keyBy(Pair::getFirst, String.class) .valueBy(Pair::getSecond) .reduceBy((Stream<Long> values, Collector<List<Long>> coll) -> coll.collect(values.collect(Collectors.toList()))) .withSortedValues(Long::compareTo) .output(); } });
@Override protected Dataset<Pair<String, Long>> getOutput(Dataset<String> input) { return ReduceByKey.of(input) .keyBy(e -> e) .valueBy(e -> 1L) .combineBy(Sums.ofLongs()) .output(); } });
@Override protected Dataset<Pair<Integer, Long>> getOutput(Dataset<Pair<Integer, Long>> input) { input = AssignEventTime.of(input).using(Pair::getSecond).output(); return ReduceByKey.of(input) .keyBy(Pair::getFirst, Integer.class) .valueBy(e -> 1L) .combineBy(Sums.ofLongs()) .windowBy(Time.of(Duration.ofSeconds(1))) .output(); }
@Override protected Dataset<Pair<Word, Long>> getOutput(Dataset<Pair<Word, Long>> input) { input = AssignEventTime.of(input).using(Pair::getSecond).output(); return ReduceByKey.of(input) .keyBy(Pair::getFirst) .valueBy(e -> 1L) .combineBy(Sums.ofLongs()) .windowBy(Time.of(Duration.ofSeconds(1))) .output(); }
@Test public void testBuild_ImplicitName() { Flow flow = Flow.create("TEST"); Dataset<String> dataset = Util.createMockDataset(flow, 2); ReduceByKey.of(dataset) .keyBy(s -> s) .valueBy(s -> 1L) .combineBy(n -> StreamSupport.stream(n.spliterator(), false).mapToLong(Long::new).sum()) .output(); ReduceByKey reduce = (ReduceByKey) flow.operators().iterator().next(); assertEquals("ReduceByKey", reduce.getName()); }
@Override protected Dataset<Set<Integer>> getOutput(Dataset<Integer> input) { return ReduceByKey.of(input) .keyBy(e -> e % 2, Integer.class) .valueBy(e -> e) .reduceBy(s -> s.collect(Collectors.toSet())) .windowBy(Count.of(3)) .outputValues(); }
@Override protected Dataset<Pair<Integer, Set<Integer>>> getOutput(Dataset<Integer> input) { return ReduceByKey.of(input) .keyBy(e -> e % 2, Integer.class) .valueBy(e -> e) .reduceBy(s -> s.collect(Collectors.toSet())) .windowBy(Count.of(3)) .output(); }
@Override protected Dataset<Pair<Integer, Long>> getOutput(Dataset<Integer> input) { return ReduceByKey.of(input) .keyBy(e -> e % 3, Integer.class) .valueBy(e -> 1L) .combineBy(Sums.ofLongs()) .windowBy(new TestWindowing()) .output(); }
@Override protected Dataset<Pair<Integer, Long>> getOutput(Dataset<Pair<Integer, Long>> input) { input = AssignEventTime.of(input).using(Pair::getSecond).output(); return ReduceByKey.of(input) .keyBy(Pair::getFirst, Integer.class) .valueBy(e -> 1L) .combineBy(Sums.ofLongs()) .windowBy(Time.of(Duration.ofSeconds(1))) .output(); }
@Test public void testBuild_ReduceBy() { Flow flow = Flow.create("TEST"); Dataset<String> dataset = Util.createMockDataset(flow, 2); ReduceByKey.of(dataset) .keyBy(s -> s) .valueBy(s -> 1L) .reduceBy(n -> StreamSupport.stream(n.spliterator(), false).mapToLong(Long::new).sum()) .output(); ReduceByKey reduce = (ReduceByKey) flow.operators().iterator().next(); assertNotNull(reduce.reducer); }
@Override protected Dataset<Pair<String, Long>> getOutput(Dataset<Pair<String, Long>> input) { return ReduceByKey.of(input) .keyBy(Pair::getFirst) .valueBy(Pair::getSecond) .combineBy(Sums.ofLongs()) .windowBy(new CWindowing<>(3)) .output(); }
@Override protected Dataset<Pair<Integer, Long>> getOutput(Dataset<Integer> input) { return ReduceByKey.of(input) .keyBy(e -> e % 3, Integer.class) .valueBy(e -> 1L) .combineBy(Sums.ofLongs()) .windowBy(new TestWindowing()) .output(); }
@Override protected Dataset<Pair<Integer, Integer>> getOutput(Dataset<Integer> input) { return ReduceByKey.of(input) .keyBy(e -> e % 2, Integer.class) .reduceBy(Fold.whileEmittingEach(0, (a, b) -> a + b)) .windowBy(Count.of(3)) .output(); }
@Override protected Dataset<Pair<String, List<Long>>> getOutput(Dataset<Pair<String, Long>> input) { return ReduceByKey.of(input) .keyBy(Pair::getFirst, String.class) .valueBy(Pair::getSecond) .reduceBy((Stream<Long> values, Collector<List<Long>> coll) -> coll.collect(values.collect(Collectors.toList()))) .withSortedValues(Long::compareTo) .output(); } });
@Override protected Dataset<Pair<String, Long>> getOutput(Dataset<String> input) { return ReduceByKey.of(input) .keyBy(e -> e) .valueBy(e -> 1L) .combineBy(Sums.ofLongs()) .output(); } });
@Override protected Dataset<Pair<Integer, Integer>> getOutput(Dataset<Integer> input) { return ReduceByKey.of(input) .keyBy(e -> e % 2, Integer.class) .reduceBy(Fold.whileEmittingEach(0, (a, b) -> a + b)) .windowBy(Count.of(3)) .output(); }