Google Cloud Dataflow SDK for Java, version 1.9.1
Class WithKeys<K,V>
- java.lang.Object
-
- com.google.cloud.dataflow.sdk.transforms.PTransform<PCollection<V>,PCollection<KV<K,V>>>
-
- com.google.cloud.dataflow.sdk.transforms.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:
- HasDisplayData, Serializable
public class WithKeys<K,V> extends PTransform<PCollection<V>,PCollection<KV<K,V>>>
WithKeys<K, V>
takes aPCollection<V>
, and either a constant key of typeK
or a function fromV
toK
, and returns aPCollection<KV<K, V>>
, where each of the values in the inputPCollection
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 sameWindowFn
associated with it as the input.- See Also:
- Serialized Form
-
-
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<KV<K,V>>
apply(PCollection<V> in)
Applies thisPTransform
on the givenInputT
, and returns itsOutput
.static <K,V> WithKeys<K,V>
of(K key)
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
.WithKeys<K,V>
withKeyType(TypeDescriptor<K> keyType)
Return aWithKeys
that is like this one with the specified key type descriptor.-
Methods inherited from class com.google.cloud.dataflow.sdk.transforms.PTransform
getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, populateDisplayData, toString, validate
-
-
-
-
Method Detail
-
of
public 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
.If using a lambda in Java 8,
withKeyType(TypeDescriptor)
must be called on the resultPTransform
.
-
of
public static <K,V> WithKeys<K,V> of(K key)
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
public WithKeys<K,V> withKeyType(TypeDescriptor<K> keyType)
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
.
-
apply
public PCollection<KV<K,V>> apply(PCollection<V> in)
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<V>,PCollection<KV<K,V>>>
-
-