public class MapElements<InputT,OutputT> extends PTransform<PCollection<? extends InputT>,PCollection<OutputT>>
PTransform
s for mapping a simple function over the elements of a PCollection
.name
Modifier and Type | Method and Description |
---|---|
PCollection<OutputT> |
expand(PCollection<? extends InputT> input)
Applies this
PTransform on the given InputT , and returns its
Output . |
static <OutputT> MapElements<?,OutputT> |
into(TypeDescriptor<OutputT> outputType)
Returns a new
MapElements transform with the given type descriptor for the output
type, but the mapping function yet to be specified using via(SerializableFunction) . |
void |
populateDisplayData(DisplayData.Builder builder)
Register display data for the given transform or component.
|
<NewInputT> |
via(SerializableFunction<NewInputT,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. |
getAdditionalInputs, getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, toString, validate
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 static <OutputT> MapElements<?,OutputT> into(TypeDescriptor<OutputT> outputType)
MapElements
transform with the given type descriptor for the output
type, but the mapping function yet to be specified using via(SerializableFunction)
.public <NewInputT> MapElements<NewInputT,OutputT> via(SerializableFunction<NewInputT,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.into(TypeDescriptors.integers())
.via((String word) -> word.length()));
In Java 7, the overload via(SimpleFunction)
is more concise as the output type
descriptor need not be provided.
public PCollection<OutputT> expand(PCollection<? extends InputT> input)
PTransform
PTransform
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).
expand
in class PTransform<PCollection<? extends InputT>,PCollection<OutputT>>
public void populateDisplayData(DisplayData.Builder builder)
PTransform
populateDisplayData(DisplayData.Builder)
is invoked by Pipeline runners to collect
display data via DisplayData.from(HasDisplayData)
. Implementations may call
super.populateDisplayData(builder)
in order to register display data in the current
namespace, but should otherwise use subcomponent.populateDisplayData(builder)
to use
the namespace of the subcomponent.
By default, does not register any display data. Implementors may override this method to provide their own display data.
populateDisplayData
in interface HasDisplayData
populateDisplayData
in class PTransform<PCollection<? extends InputT>,PCollection<OutputT>>
builder
- The builder to populate with display data.HasDisplayData