public class MapElements<InputT,OutputT> extends PTransform<PCollection<InputT>,PCollection<OutputT>>
PTransforms for mapping a simple function over the elements of a PCollection.| Modifier and Type | Class and Description |
|---|---|
static class |
MapElements.MissingOutputTypeDescriptor<InputT,OutputT>
An intermediate builder for a
MapElements 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,OutputT> fn)
For a
SerializableFunction<InputT, OutputT> fn and output type descriptor,
returns a PTransform that takes an input PCollection<InputT> and returns
a PCollection<OutputT> containing fn.apply(v) for every element v in
the input. |
static <InputT,OutputT> |
via(SimpleFunction<InputT,OutputT> fn)
For a
SimpleFunction<InputT, OutputT> fn, returns a PTransform that
takes an input PCollection<InputT> and returns a PCollection<OutputT>
containing fn.apply(v) for every element v in the input. |
getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, populateDisplayData, toString, validatepublic static <InputT,OutputT> MapElements.MissingOutputTypeDescriptor<InputT,OutputT> via(SerializableFunction<InputT,OutputT> fn)
SerializableFunction<InputT, OutputT> fn and output type descriptor,
returns a PTransform that takes an input PCollection<InputT> and returns
a PCollection<OutputT> containing fn.apply(v) for every element v in
the input.
Example of use in Java 8:
PCollection<Integer> wordLengths = words.apply(
MapElements.via((String word) -> word.length())
.withOutputType(new TypeDescriptor<Integer>() {});
In Java 7, the overload via(SimpleFunction) is more concise as the output type
descriptor need not be provided.
public static <InputT,OutputT> MapElements<InputT,OutputT> via(SimpleFunction<InputT,OutputT> fn)
SimpleFunction<InputT, OutputT> fn, returns a PTransform that
takes an input PCollection<InputT> and returns a PCollection<OutputT>
containing fn.apply(v) for every element v in the input.
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> words = ...;
PCollection<Integer> wordsPerLine = words.apply(MapElements.via(
new SimpleFunction<String, Integer>() {
public Integer apply(String word) {
return word.length();
}
}));
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>>