K
- the type of the keys of the input and output
PCollection
sInputT
- the type of the values of the input PCollection
OutputT
- the type of the values of the output PCollection
public static class Combine.PerKey<K,InputT,OutputT> extends PTransform<PCollection<KV<K,InputT>>,PCollection<KV<K,OutputT>>>
PerKey<K, InputT, OutputT>
takes a
PCollection<KV<K, InputT>>
, groups it by key, applies a
combining function to the InputT
values associated with each
key to produce a combined OutputT
value, and returns a
PCollection<KV<K, OutputT>>
representing a map from each
distinct key of the input PCollection
to the corresponding
combined value. InputT
and OutputT
are often the same.
This is a concise shorthand for an application of
GroupByKey
followed by an application of
Combine.GroupedValues
. See those
operations for more details on how keys are compared for equality
and on the default Coder
for the output.
Example of use:
PCollection<KV<String, Double>> salesRecords = ...;
PCollection<KV<String, Double>> totalSalesPerPerson =
salesRecords.apply(Combine.<String, Double>perKey(
new Sum.SumDoubleFn()));
Each output element is in the window by which its corresponding input
was grouped, and has the timestamp of the end of that window. The output
PCollection
has the same
WindowFn
as the input.
name
Modifier and Type | Method and Description |
---|---|
PCollection<KV<K,OutputT>> |
apply(PCollection<KV<K,InputT>> input)
Applies this
PTransform on the given InputT , and returns its
Output . |
CombineFnBase.PerKeyCombineFn<? super K,? super InputT,?,OutputT> |
getFn()
Returns the
CombineFnBase.PerKeyCombineFn used by this Combine operation. |
List<PCollectionView<?>> |
getSideInputs()
Returns the side inputs used by this Combine operation.
|
Combine.PerKey<K,InputT,OutputT> |
named(String name)
Return a new
Globally transform that's like this transform but with the
specified name. |
Combine.PerKeyWithHotKeyFanout<K,InputT,OutputT> |
withHotKeyFanout(int hotKeyFanout)
Like
withHotKeyFanout(SerializableFunction) , but returning the given
constant value for every key. |
Combine.PerKeyWithHotKeyFanout<K,InputT,OutputT> |
withHotKeyFanout(SerializableFunction<? super K,Integer> hotKeyFanout)
If a single key has disproportionately many values, it may become a
bottleneck, especially in streaming mode.
|
Combine.PerKey<K,InputT,OutputT> |
withSideInputs(Iterable<? extends PCollectionView<?>> sideInputs)
Returns a
PTransform identical to this, but with the specified side inputs to use
in CombineWithContext.KeyedCombineFnWithContext . |
getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, toString, validate
public Combine.PerKey<K,InputT,OutputT> named(String name)
Globally
transform that's like this transform but with the
specified name. Does not modify this transform.public Combine.PerKey<K,InputT,OutputT> withSideInputs(Iterable<? extends PCollectionView<?>> sideInputs)
PTransform
identical to this, but with the specified side inputs to use
in CombineWithContext.KeyedCombineFnWithContext
.public Combine.PerKeyWithHotKeyFanout<K,InputT,OutputT> withHotKeyFanout(SerializableFunction<? super K,Integer> hotKeyFanout)
hotKeyFanout
- a function from keys to an integer N, where the key
will be spread among N intermediate nodes for partial combining.
If N is less than or equal to 1, this key will not be sent through an
intermediate node.public Combine.PerKeyWithHotKeyFanout<K,InputT,OutputT> withHotKeyFanout(int hotKeyFanout)
withHotKeyFanout(SerializableFunction)
, but returning the given
constant value for every key.public CombineFnBase.PerKeyCombineFn<? super K,? super InputT,?,OutputT> getFn()
CombineFnBase.PerKeyCombineFn
used by this Combine operation.public List<PCollectionView<?>> getSideInputs()
public PCollection<KV<K,OutputT>> apply(PCollection<KV<K,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).
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)
.
apply
in class PTransform<PCollection<KV<K,InputT>>,PCollection<KV<K,OutputT>>>