fn( (element, c) -> { c.sideInput(schemaView); // Ignore result return element.substring(0, 1); }, (dest, c) -> { Schema schema = new Schema.Parser().parse(c.sideInput(schemaView).get(dest)); return AvroIO.sinkViaGenericRecords(schema, formatter); }, fn( (dest, c) -> { c.sideInput(schemaView); // Ignore result return FileIO.Write.defaultNaming("file_" + dest, ".avro"); },
Instant now = Instant.now(); Growth.PollResult<OutputT> res = spec.getPollFn().getClosure().apply(c.element(), wrapProcessContext(c));
/** Basic test of {@link FlatMapElements} with a {@link Fn} and a side input. */ @Test @Category(NeedsRunner.class) public void testFlatMapBasicWithSideInput() throws Exception { final PCollectionView<Integer> view = pipeline.apply("Create base", Create.of(40)).apply(View.asSingleton()); PCollection<Integer> output = pipeline .apply(Create.of(0, 1, 2)) .apply( FlatMapElements.into(integers()) .via( fn( (input, c) -> ImmutableList.of( c.sideInput(view) - input, c.sideInput(view) + input), requiresSideInputs(view)))); PAssert.that(output).containsInAnyOrder(38, 39, 40, 40, 41, 42); pipeline.run(); }
/** Basic test of {@link MapElements} with a {@link Fn} and a side input. */ @Test @Category(NeedsRunner.class) public void testMapBasicWithSideInput() throws Exception { final PCollectionView<Integer> view = pipeline.apply("Create base", Create.of(40)).apply(View.asSingleton()); PCollection<Integer> output = pipeline .apply(Create.of(0, 1, 2)) .apply( MapElements.into(integers()) .via( fn((element, c) -> element + c.sideInput(view), requiresSideInputs(view)))); PAssert.that(output).containsInAnyOrder(40, 41, 42); pipeline.run(); }
@ProcessElement public void processElement( @Element InputT element, OutputReceiver<OutputT> receiver, ProcessContext c) throws Exception { receiver.output( fn.getClosure().apply(element, Fn.Context.wrapProcessContext(c))); }