Using side inputs
We have already seen how to use side outputs, and side inputs are analogous to them. Besides the single main input, a ParDo
transform can have multiple additional side inputs, as shown in the following figure:
We have multiple ways of declaring a side input to a ParDo
object. For instance, consider the following example:
ParDo.of(new MyDoFn()) Analogous to side outputs is also the way how we declare a side input – we must provide it to the ParDo by call to withSideInput as follows: input.apply(ParDo.of(new MyDoFn()) .withSideInput("side-input", sideInput));
Because we may have multiple side inputs, we need a way to distinguish them – if we assign a name to the side input, we can later access it easily in DoFn
using a @SideInput
annotation:
@ProcessElement public void processElement( @Element .. element, ...