/** * This is not a basic operator. It can be straightforwardly implemented * by using {@code FlatMap} operator. * @return the operator chain representing this operation including FlatMap */ @Override public DAG<Operator<?, ?>> getBasicOps() { return DAG.of( // do not use the client API here, because it modifies the Flow! new FlatMap<IN, OUT>(getName(), getFlow(), input, (i, c) -> c.collect(mapper.apply(i, c.asContext())), null, getHints())); }
/** * This is not a basic operator. It can be straightforwardly implemented * by using {@code FlatMap} operator. * @return the operator chain representing this operation including FlatMap */ @Override public DAG<Operator<?, ?>> getBasicOps() { return DAG.of( // do not use the client API here, because it modifies the Flow! new FlatMap<IN, OUT>(getName(), getFlow(), input, (i, c) -> c.collect(mapper.apply(i, c.asContext())), null, getHints())); }
@Test public void testBuild_ImplicitName() { Flow flow = Flow.create("TEST"); Dataset<String> dataset = Util.createMockDataset(flow, 1); Dataset<String> mapped = MapElements.of(dataset) .using(s -> s) .output(); MapElements map = (MapElements) flow.operators().iterator().next(); assertEquals("MapElements", map.getName()); }
@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()); }