/** * Finalizes the operator and retrieves its output dataset. * Using this output new operator {@link MapElements} is added * to the flow to extract values from pairs. * * @param outputHints output dataset description * @return the dataset representing the new operator's output */ default Dataset<V> outputValues(OutputHint... outputHints) { return MapElements .named("extract-values") .of(output()) .using(Pair::getSecond) .output(outputHints); } }
/** * Finalizes the operator and retrieves its output dataset. * Using this output new operator {@link MapElements} is added * to the flow to extract values from pairs. * * @param outputHints output dataset description * @return the dataset representing the new operator's output */ default Dataset<V> outputValues(OutputHint... outputHints) { return MapElements .named("extract-values") .of(output()) .using(Pair::getSecond) .output(outputHints); } }
final Dataset<LogLine> parsed = MapElements.named("LOG-PARSER") .of(lines) .using(LogParser::parseLine)
return MapElements.named("FORMAT") .of(counted) .using(p -> p.getFirst() + ":" + p.getSecond())
final Dataset<Integer> mapped = MapElements.named("first") .of(input) .using(e -> e)
@Test public void testBuild_WithCounters() { Flow flow = Flow.create("TEST"); Dataset<String> dataset = Util.createMockDataset(flow, 1); Dataset<String> mapped = MapElements.named("Map1") .of(dataset) .using((input, context) -> { // use simple counter context.getCounter("my-counter").increment(); return input.toLowerCase(); }) .output(); assertEquals(flow, mapped.getFlow()); assertEquals(1, flow.size()); MapElements map = (MapElements) flow.operators().iterator().next(); assertEquals(flow, map.getFlow()); assertEquals("Map1", map.getName()); assertNotNull(map.getMapper()); assertEquals(mapped, map.output()); }
@Test public void testBuild() { Flow flow = Flow.create("TEST"); Dataset<String> dataset = Util.createMockDataset(flow, 1); Dataset<String> mapped = MapElements.named("Map1") .of(dataset) .using(s -> s) .output(); assertEquals(flow, mapped.getFlow()); assertEquals(1, flow.size()); MapElements map = (MapElements) flow.operators().iterator().next(); assertEquals(flow, map.getFlow()); assertEquals("Map1", map.getName()); assertNotNull(map.getMapper()); assertEquals(mapped, map.output()); }