Google Cloud Dataflow SDK for Java, version 1.9.1
Class FlatMapElements<InputT,OutputT>
- java.lang.Object
-
- com.google.cloud.dataflow.sdk.transforms.PTransform<PCollection<InputT>,PCollection<OutputT>>
-
- com.google.cloud.dataflow.sdk.transforms.FlatMapElements<InputT,OutputT>
-
- All Implemented Interfaces:
- HasDisplayData, Serializable
public class FlatMapElements<InputT,OutputT> extends PTransform<PCollection<InputT>,PCollection<OutputT>>
PTransform
s for mapping a simple function that returns iterables over the elements of aPCollection
and merging the results.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static class
FlatMapElements.MissingOutputTypeDescriptor<InputT,OutputT>
An intermediate builder for aFlatMapElements
transform.
-
Field Summary
-
Fields inherited from class com.google.cloud.dataflow.sdk.transforms.PTransform
name
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description PCollection<OutputT>
apply(PCollection<InputT> input)
Applies thisPTransform
on the givenInputT
, and returns itsOutput
.static <InputT,OutputT>
FlatMapElements.MissingOutputTypeDescriptor<InputT,OutputT>via(SerializableFunction<InputT,? extends Iterable<OutputT>> fn)
For aSerializableFunction<InputT, ? extends Iterable<OutputT>>
fn
, returns aPTransform
that appliesfn
to every element of the inputPCollection<InputT>
and outputs all of the elements to the outputPCollection<OutputT>
.static <InputT,OutputT>
FlatMapElements<InputT,OutputT>via(SimpleFunction<InputT,? extends Iterable<OutputT>> fn)
For aSimpleFunction<InputT, ? extends Iterable<OutputT>>
fn
, return aPTransform
that appliesfn
to every element of the inputPCollection<InputT>
and outputs all of the elements to the outputPCollection<OutputT>
.-
Methods inherited from class com.google.cloud.dataflow.sdk.transforms.PTransform
getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, populateDisplayData, toString, validate
-
-
-
-
Method Detail
-
via
public static <InputT,OutputT> FlatMapElements.MissingOutputTypeDescriptor<InputT,OutputT> via(SerializableFunction<InputT,? extends Iterable<OutputT>> fn)
For aSerializableFunction<InputT, ? extends Iterable<OutputT>>
fn
, returns aPTransform
that appliesfn
to every element of the inputPCollection<InputT>
and outputs all of the elements to the outputPCollection<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 aSimpleFunction<InputT, ? extends Iterable<OutputT>>
fn
, return aPTransform
that appliesfn
to every element of the inputPCollection<InputT>
and outputs all of the elements to the outputPCollection<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)
.
-
apply
public PCollection<OutputT> apply(PCollection<InputT> input)
Description copied from class:PTransform
Applies thisPTransform
on the givenInputT
, and returns itsOutput
.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)
.- Overrides:
apply
in classPTransform<PCollection<InputT>,PCollection<OutputT>>
-
-