FlatMapElements (Google Cloud Dataflow SDK 1.9.1 API)

Google Cloud Dataflow SDK for Java, version 1.9.1

com.google.cloud.dataflow.sdk.transforms

Class FlatMapElements<InputT,OutputT>

    • Method Detail

      • via

        public static <InputT,OutputT> FlatMapElements.MissingOutputTypeDescriptor<InputT,OutputT> via(SerializableFunction<InputT,? extends Iterable<OutputT>> fn)
        For a SerializableFunction<InputT, ? extends Iterable<OutputT>> fn, returns a PTransform that applies fn to every element of the input PCollection<InputT> and outputs all of the elements to the output PCollection<OutputT>.

        Example of use in Java 8:

        
         PCollection<String> words = lines.apply(
             FlatMapElements.via((String line) -> Arrays.asList(line.split(" ")))
                 .withOutputType(new TypeDescriptor<String>(){});
         

        In Java 7, the overload via(SimpleFunction) is more concise as the output type descriptor need not be provided.

      • via

        public static <InputT,OutputT> FlatMapElements<InputT,OutputT> via(SimpleFunction<InputT,? extends Iterable<OutputT>> fn)
        For a SimpleFunction<InputT, ? extends Iterable<OutputT>> fn, return a PTransform that applies fn to every element of the input PCollection<InputT> and outputs all of the elements to the output PCollection<OutputT>.

        This overload is intended primarily for use in Java 7. In Java 8, the overload via(SerializableFunction) supports use of lambda for greater concision.

        Example of use in Java 7:

        
         PCollection<String> lines = ...;
         PCollection<String> words = lines.apply(FlatMapElements.via(
             new SimpleFunction<String, List<String>>() {
               public Integer apply(String line) {
                 return Arrays.asList(line.split(" "));
               }
             });
         

        To use a Java 8 lambda, see via(SerializableFunction).


Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Dataflow
Need help? Visit our support page.