K - the type of the keys of the input and output
PCollectionsInputT - the type of the values of the input PCollectionOutputT - the type of the values of the output PCollectionpublic 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, 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. |
void |
populateDisplayData(DisplayData.Builder builder)
Register display data for the given transform or component.
|
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, validatepublic 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)
PTransformPTransform 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).
apply in class PTransform<PCollection<KV<K,InputT>>,PCollection<KV<K,OutputT>>>public void populateDisplayData(DisplayData.Builder builder)
PTransformpopulateDisplayData(DisplayData.Builder) is invoked by Pipeline runners to collect
display data via DisplayData.from(HasDisplayData). Implementations may call
super.populateDisplayData(builder) in order to register display data in the current
namespace, but should otherwise use subcomponent.populateDisplayData(builder) to use
the namespace of the subcomponent.
By default, does not register any display data. Implementors may override this method to provide their own display data.
populateDisplayData in interface HasDisplayDatapopulateDisplayData in class PTransform<PCollection<KV<K,InputT>>,PCollection<KV<K,OutputT>>>builder - The builder to populate with display data.HasDisplayData