Class Flatten
Flatten<T>
takes multiple PCollection<T>
s bundled into a
PCollectionList<T>
and returns a single PCollection<T>
containing all the elements in
all the input PCollection
s. The name "Flatten" suggests taking a list of lists and
flattening them into a single list.
Example of use:
PCollection<String> pc1 = ...;
PCollection<String> pc2 = ...;
PCollection<String> pc3 = ...;
PCollectionList<String> pcs = PCollectionList.of(pc1).and(pc2).and(pc3);
PCollection<String> merged = pcs.apply(Flatten.<String>pCollections());
By default, the Coder
of the output PCollection
is the same as the
Coder
of the first PCollection
in the input PCollectionList
(if the
PCollectionList
is non-empty).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
FlattenIterables<T>
takes aPCollection<Iterable<T>>
and returns aPCollection<T>
that contains all the elements from each iterable.static class
APTransform
that flattens aPCollectionList
into aPCollection
containing all the elements of all thePCollection
s in its input. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Flatten.Iterables
<T> Returns aPTransform
that takes aPCollection<Iterable<T>>
and returns aPCollection<T>
containing all the elements from all theIterable
s.static <T> Flatten.PCollections
<T> Returns aPTransform
that flattens aPCollectionList
into aPCollection
containing all the elements of all thePCollection
s in its input.static <T> PTransform
<PCollection<T>, PCollection<T>> with
(PTransform<PBegin, PCollection<T>> other) Returns aPTransform
that flattens the inputPCollection
with the output of anotherPTransform
resulting in aPCollection
containing all the elements of both the inputPCollection
s and the output of the givenPTransform
as its output.static <T> PTransform
<PCollection<T>, PCollection<T>> with
(PCollection<T> other) Returns aPTransform
that flattens the inputPCollection
with a givenPCollection
resulting in aPCollection
containing all the elements of bothPCollection
s as its output.
-
Constructor Details
-
Flatten
public Flatten()
-
-
Method Details
-
pCollections
Returns aPTransform
that flattens aPCollectionList
into aPCollection
containing all the elements of all thePCollection
s in its input.All inputs must have equal
WindowFn
s. The output elements ofFlatten<T>
are in the same windows and have the same timestamps as their corresponding input elements. The outputPCollection
will have the sameWindowFn
as all of the inputs.- Type Parameters:
T
- the type of the elements in the input and outputPCollection
s.
-
iterables
Returns aPTransform
that takes aPCollection<Iterable<T>>
and returns aPCollection<T>
containing all the elements from all theIterable
s.Example of use:
PCollection<Iterable<Integer>> pcOfIterables = ...; PCollection<Integer> pc = pcOfIterables.apply(Flatten.<Integer>iterables());
By default, the output
PCollection
encodes its elements using the sameCoder
that the input uses for the elements in itsIterable
.- Type Parameters:
T
- the type of the elements of the inputIterable
and the outputPCollection
-
with
Returns aPTransform
that flattens the inputPCollection
with a givenPCollection
resulting in aPCollection
containing all the elements of bothPCollection
s as its output.This is equivalent to creating a
PCollectionList
containing both the input andother
and then applyingpCollections()
, but has the advantage that it can be more easily used inline.Both must have equal
WindowFn
s. The output elements ofFlatten<T>
are in the same windows and have the same timestamps as their corresponding input elements. The outputPCollection
will have the sameWindowFn
as both inputs.- Type Parameters:
T
- the type of the elements in the input and outputPCollection
s.- Parameters:
other
- the other PCollection to flatten with the input
-
with
public static <T> PTransform<PCollection<T>,PCollection<T>> with(PTransform<PBegin, PCollection<T>> other) Returns aPTransform
that flattens the inputPCollection
with the output of anotherPTransform
resulting in aPCollection
containing all the elements of both the inputPCollection
s and the output of the givenPTransform
as its output.This is equivalent to creating a
PCollectionList
containing both the input and the output ofother
and then applyingpCollections()
, but has the advantage that it can be more easily used inline.Both
PCollections
must have equalWindowFn
s. The output elements ofFlatten<T>
are in the same windows and have the same timestamps as their corresponding input elements. The outputPCollection
will have the sameWindowFn
as both inputs.- Type Parameters:
T
- the type of the elements in the input and outputPCollection
s.- Parameters:
other
- a PTransform whose ouptput should be flattened with the input
-