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 {@code fn} to every element of the input
{@code PCollection |
static <InputT,OutputT> |
via(SimpleFunction<InputT,? extends Iterable<OutputT>> fn)
For a
SimpleFunction<InputT, ? extends Iterable<OutputT>> fn,
return a PTransform that applies {@code fn} to every element of the input
{@code PCollection |
getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, 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 {@code fn} to every element of the input
{@code PCollectionExample of use in Java 8:
{@code
PCollection words = lines.apply(
FlatMapElements.via((String line) -> Arrays.asList(line.split(" ")))
.withOutputType(new TypeDescriptor(){});
}
In Java 7, the overload {@link #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 {@code fn} to every element of the input
{@code PCollectionThis overload is intended primarily for use in Java 7. In Java 8, the overload {@link #via(SerializableFunction)} supports use of lambda for greater concision.
Example of use in Java 7:
{@code
PCollection lines = ...;
PCollection words = lines.apply(FlatMapElements.via(
new SimpleFunction>() {
public Integer apply(String line) {
return Arrays.asList(line.split(" "));
}
});
}
To use a Java 8 lambda, see {@link #of(SerializableFunction, TypeDescriptor)}.
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).
The default implementation throws an exception. A derived class must
either implement apply, or else each runner must supply a custom
implementation via
PipelineRunner.apply(com.google.cloud.dataflow.sdk.transforms.PTransform<InputT, OutputT>, InputT).
apply in class PTransform<PCollection<InputT>,PCollection<OutputT>>