/** This operator can be implemented using FlatMap. */ @Override public DAG<Operator<?, ?>> getBasicOps() { return DAG.of(new FlatMap<>(getName(), getFlow(), input, (elem, collector) -> { if (predicate.apply(elem)) { collector.collect(elem); } }, null, getHints())); } }
/** This operator can be implemented using FlatMap. */ @Override public DAG<Operator<?, ?>> getBasicOps() { return DAG.of(new FlatMap<>(getName(), getFlow(), input, (elem, collector) -> { if (predicate.apply(elem)) { collector.collect(elem); } }, null, getHints())); } }
@Test public void testBuild() { Flow flow = Flow.create("TEST"); Dataset<String> dataset = Util.createMockDataset(flow, 1); Dataset<String> filtered = Filter.named("Filter1") .of(dataset) .by(s -> !s.equals("")) .output(); assertEquals(flow, filtered.getFlow()); assertEquals(1, flow.size()); Filter filter = (Filter) flow.operators().iterator().next(); assertEquals(flow, filter.getFlow()); assertEquals("Filter1", filter.getName()); assertNotNull(filter.predicate); assertEquals(filtered, filter.output()); }
@Test public void testBuild() { String opName = "split"; Flow flow = Flow.create("split-test"); Dataset<String> dataset = Util.createMockDataset(flow, 1); Split.Output<String> split = Split.named(opName) .of(dataset) .using((UnaryPredicate<String>) what -> true) .output(); assertEquals(2, flow.size()); Filter positive = (Filter) getOperator(flow, opName + Split.POSITIVE_FILTER_SUFFIX); assertSame(flow, positive.getFlow()); assertNotNull(positive.getPredicate()); assertSame(positive.output(), split.positive()); Filter negative = (Filter) getOperator(flow, opName + Split.NEGATIVE_FILTER_SUFFIX); assertSame(flow, negative.getFlow()); assertNotNull(negative.getPredicate()); assertSame(negative.output(), split.negative()); }