.keyBy(e -> (byte) 0) .valueBy(e -> e) .scoreBy(Pair::getSecond)
@Test public void testBuild() { Flow flow = Flow.create("TEST"); Dataset<String> dataset = Util.createMockDataset(flow, 2); Time<String> windowing = Time.of(Duration.ofHours(1)); Dataset<Triple<String, Long, Long>> result = TopPerKey.named("TopPerKey1") .of(dataset) .keyBy(s -> s) .valueBy(s -> 1L) .scoreBy(s -> 1L) .windowBy(windowing) .output(); assertEquals(flow, result.getFlow()); assertEquals(1, flow.size()); TopPerKey tpk = (TopPerKey) Iterables.getOnlyElement(flow.operators()); assertEquals(flow, tpk.getFlow()); assertEquals("TopPerKey1", tpk.getName()); assertNotNull(tpk.getKeyExtractor()); assertNotNull(tpk.getValueExtractor()); assertNotNull(tpk.getScoreExtractor()); assertEquals(result, tpk.output()); assertSame(windowing, tpk.getWindowing()); }
@Test public void testWindow_applyIf() { Flow flow = Flow.create("TEST"); Dataset<String> dataset = Util.createMockDataset(flow, 3); TopPerKey.of(dataset) .keyBy(s -> s) .valueBy(s -> 1L) .scoreBy(s -> 1L) .applyIf(true, b -> b.windowBy(Time.of(Duration.ofHours(1)))) .output(); TopPerKey tpk = (TopPerKey) Iterables.getOnlyElement(flow.operators()); assertTrue(tpk.windowing instanceof Time); }
@Override protected Dataset<Triple<String, String, Integer>> getOutput(Dataset<Item> input) { return TopPerKey.of(input) .keyBy(Item::getKey) .valueBy(Item::getValue) .scoreBy(Item::getScore) .output(); }
@Override protected Dataset<Triple<String, String, Integer>> getOutput(Dataset<Item> input) { return TopPerKey.of(input) .keyBy(Item::getKey) .valueBy(Item::getValue) .scoreBy(Item::getScore) .output(); }
@Test public void testBuild_Windowing() { Flow flow = Flow.create("TEST"); Dataset<String> dataset = Util.createMockDataset(flow, 3); TopPerKey.of(dataset) .keyBy(s -> s) .valueBy(s -> 1L) .scoreBy(s -> 1L) .windowBy(Time.of(Duration.ofHours(1))) .output(); assertTrue(Iterables.getOnlyElement(flow.operators()) instanceof TopPerKey); }
@Test public void testBuild_ImplicitName() { Flow flow = Flow.create("TEST"); Dataset<String> dataset = Util.createMockDataset(flow, 2); TopPerKey.of(dataset) .keyBy(s -> s) .valueBy(s -> 1L) .scoreBy(s -> 1L) .output(); TopPerKey tpk = (TopPerKey) Iterables.getOnlyElement(flow.operators()); assertEquals("TopPerKey", tpk.getName()); }