Class Combine.GroupedValues<K,InputT,OutputT>
- Type Parameters:
K
- type of input and output keysInputT
- type of input valuesOutputT
- type of output values
- All Implemented Interfaces:
Serializable
,HasDisplayData
- Enclosing class:
Combine
GroupedValues<K, InputT, OutputT>
takes a PCollection<KV<K, Iterable<InputT>>>
,
such as the result of GroupByKey
, applies a specified CombineFn<InputT, AccumT, OutputT>
to each of the input KV<K, Iterable<InputT>>
elements to produce a combined output KV<K, OutputT>
element, and returns a
PCollection<KV<K, OutputT>>
containing all the combined output elements. It is common for
InputT == OutputT
, but not required. Common combining functions include sums, mins,
maxes, and averages of numbers, conjunctions and disjunctions of booleans, statistical
aggregations, etc.
Example of use:
PCollection<KV<String, Integer>> pc = ...;
PCollection<KV<String, Iterable<Integer>>> groupedByKey = pc.apply(
GroupByKey.create());
PCollection<KV<String, Integer>> sumByKey =
groupedByKey.apply(Combine.groupedValues(
Sum.ofIntegers()));
See also Combine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)
/Combine.PerKey
, which captures the common pattern of
"combining by key" in a single easy-to-use PTransform
.
Combining for different keys can happen in parallel. Moreover, combining of the
Iterable<InputT>
values associated a single key can happen in parallel, with different subsets
of the values being combined separately, and their intermediate results combined further, in an
arbitrary tree reduction pattern, until a single result value is produced for each key.
By default, the Coder
of the keys of the output PCollection<KV<K, OutputT>>
is that of the keys of the input PCollection<KV<K, InputT>>
, and the Coder
of
the values of the output PCollection<KV<K, OutputT>>
is inferred from the concrete type
of the CombineFn<InputT, AccumT, OutputT>
's output type OutputT
.
Each output element has the same timestamp and is in the same window as its corresponding
input element, and the output PCollection
has the same WindowFn
associated with it as the input.
See also Combine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)
/Combine.Globally
, which combines all the values
in a PCollection
into a single value in a PCollection
.
- See Also:
-
Field Summary
Fields inherited from class org.apache.beam.sdk.transforms.PTransform
annotations, displayData, name, resourceHints
-
Method Summary
Modifier and TypeMethodDescriptionOverride this method to specify how thisPTransform
should be expanded on the givenInputT
.getAppliedFn
(CoderRegistry registry, Coder<? extends KV<K, ? extends Iterable<InputT>>> inputCoder, WindowingStrategy<?, ?> windowingStrategy) Returns theCombine.CombineFn
bound to its coders.CombineFnBase.GlobalCombineFn
<? super InputT, ?, OutputT> getFn()
Returns theCombineFnBase.GlobalCombineFn
used by this Combine operation.List
<PCollectionView<?>> void
populateDisplayData
(DisplayData.Builder builder) Register display data for the given transform or component.withSideInputs
(Iterable<? extends PCollectionView<?>> sideInputs) withSideInputs
(PCollectionView<?>... sideInputs) Methods inherited from class org.apache.beam.sdk.transforms.PTransform
addAnnotation, compose, compose, getAdditionalInputs, getAnnotations, getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, getResourceHints, setDisplayData, setResourceHints, toString, validate, validate
-
Method Details
-
withSideInputs
-
withSideInputs
public Combine.GroupedValues<K,InputT, withSideInputsOutputT> (Iterable<? extends PCollectionView<?>> sideInputs) -
getFn
Returns theCombineFnBase.GlobalCombineFn
used by this Combine operation. -
getSideInputs
-
expand
public PCollection<KV<K,OutputT>> expand(PCollection<? extends KV<K, ? extends Iterable<InputT>>> input) 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<? extends KV<K,
? extends Iterable<InputT>>>, PCollection<KV<K, OutputT>>>
-
getAppliedFn
public org.apache.beam.sdk.util.AppliedCombineFn<? super K,? super InputT, getAppliedFn?, OutputT> (CoderRegistry registry, Coder<? extends KV<K, ? extends Iterable<InputT>>> inputCoder, WindowingStrategy<?, ?> windowingStrategy) Returns theCombine.CombineFn
bound to its coders.For internal use.
-
populateDisplayData
Description copied from class:PTransform
Register display data for the given transform or component.populateDisplayData(DisplayData.Builder)
is invoked by Pipeline runners to collect display data viaDisplayData.from(HasDisplayData)
. Implementations may callsuper.populateDisplayData(builder)
in order to register display data in the current namespace, but should otherwise usesubcomponent.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.
- Specified by:
populateDisplayData
in interfaceHasDisplayData
- Overrides:
populateDisplayData
in classPTransform<PCollection<? extends KV<K,
? extends Iterable<InputT>>>, PCollection<KV<K, OutputT>>> - Parameters:
builder
- The builder to populate with display data.- See Also:
-