Class WithKeys<K,V>
- Type Parameters:
K
- the type of the keys in the outputPCollection
V
- the type of the elements in the inputPCollection
and the values in the outputPCollection
- All Implemented Interfaces:
Serializable
,HasDisplayData
WithKeys<K, V>
takes a PCollection<V>
, and either a constant key of type
K
or a function from V
to K
, and returns a PCollection<KV<K, V>>
, where
each of the values in the input PCollection
has been paired with either the constant key
or a key computed from the value.
Example of use:
PCollection<String> words = ...;
PCollection<KV<Integer, String>> lengthsToWords =
words.apply(WithKeys.of(new SerializableFunction<String, Integer>() {
public Integer apply(String s) { return s.length(); } }));
Each output element has the same timestamp and is in the same windows as its corresponding
input element, and the output PCollection
has the same WindowFn
associated with it as the input.
- See Also:
-
Field Summary
Fields inherited from class org.apache.beam.sdk.transforms.PTransform
annotations, displayData, name, resourceHints
-
Method Summary
Modifier and TypeMethodDescriptionPCollection
<KV<K, V>> expand
(PCollection<V> in) Override this method to specify how thisPTransform
should be expanded on the givenInputT
.static <K,
V> WithKeys <K, V> Returns aPTransform
that takes aPCollection<V>
and returns aPCollection<KV<K, V>>
, where each of the values in the inputPCollection
has been paired with the given key.static <K,
V> WithKeys <K, V> of
(SerializableFunction<V, K> fn) Returns aPTransform
that takes aPCollection<V>
and returns aPCollection<KV<K, V>>
, where each of the values in the inputPCollection
has been paired with a key computed from the value by invoking the givenSerializableFunction
.withKeyType
(TypeDescriptor<K> keyType) Return aWithKeys
that is like this one with the specified key type descriptor.Methods inherited from class org.apache.beam.sdk.transforms.PTransform
addAnnotation, compose, compose, getAdditionalInputs, getAnnotations, getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, getResourceHints, populateDisplayData, setDisplayData, setResourceHints, toString, validate, validate
-
Method Details
-
of
Returns aPTransform
that takes aPCollection<V>
and returns aPCollection<KV<K, V>>
, where each of the values in the inputPCollection
has been paired with a key computed from the value by invoking the givenSerializableFunction
.If using a lambda in Java 8,
withKeyType(TypeDescriptor)
must be called on the resultPTransform
. -
of
Returns aPTransform
that takes aPCollection<V>
and returns aPCollection<KV<K, V>>
, where each of the values in the inputPCollection
has been paired with the given key. -
withKeyType
Return aWithKeys
that is like this one with the specified key type descriptor.For use with lambdas in Java 8, either this method must be called with an appropriate type descriptor or
PCollection.setCoder(Coder)
must be called on the outputPCollection
. -
expand
Description copied from class:PTransform
Override this method to specify how thisPTransform
should be expanded on the givenInputT
.NOTE: This method should not be called directly. Instead apply the
PTransform
should be applied to theInputT
using theapply
method.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).
- Specified by:
expand
in classPTransform<PCollection<V>,
PCollection<KV<K, V>>>
-