public class FlatMapElements<InputT,OutputT> extends PTransform<PCollection<InputT>,PCollection<OutputT>>
PTransforms for mapping a simple function that returns iterables over the elements of a
PCollection and merging the results.| Modifier and Type | Class and Description |
|---|---|
static class |
FlatMapElements.MissingOutputTypeDescriptor<InputT,OutputT>
An intermediate builder for a
FlatMapElements transform. |
name| Modifier and Type | Method and Description |
|---|---|
PCollection<OutputT> |
apply(PCollection<InputT> input)
Applies this
PTransform on the given InputT, and returns its
Output. |
static <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>. |
static <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>. |
getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, populateDisplayData, toString, validatepublic static <InputT,OutputT> FlatMapElements.MissingOutputTypeDescriptor<InputT,OutputT> via(SerializableFunction<InputT,? extends Iterable<OutputT>> fn)
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.
public static <InputT,OutputT> FlatMapElements<InputT,OutputT> via(SimpleFunction<InputT,? extends Iterable<OutputT>> fn)
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).
public PCollection<OutputT> apply(PCollection<InputT> input)
PTransformPTransform on the given InputT, and returns its
Output.
Composite transforms, which are defined in terms of other transforms, should return the output of one of the composed transforms. Non-composite transforms, which do not apply any transforms internally, should return a new unbound output and register evaluators (via backend-specific registration methods).
apply in class PTransform<PCollection<InputT>,PCollection<OutputT>>