Class Combine
PTransforms for combining PCollection elements globally and per-key.
See the documentation for how to use the operations in this class.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classCombine.AccumulatingCombineFn<InputT,AccumT extends Combine.AccumulatingCombineFn.Accumulator<InputT, AccumT, OutputT>, OutputT> ACombineFnthat uses a subclass ofCombine.AccumulatingCombineFn.Accumulatoras its accumulator type.static classAn abstract subclass ofCombine.CombineFnfor implementing combiners that are more easily and efficiently expressed as binary operations ondoubles.static classAn abstract subclass ofCombine.CombineFnfor implementing combiners that are more easily expressed as binary operations.static classAn abstract subclass ofCombine.CombineFnfor implementing combiners that are more easily and efficiently expressed as binary operations onintsstatic classAn abstract subclass ofCombine.CombineFnfor implementing combiners that are more easily and efficiently expressed as binary operations onlongs.static classCombine.CombineFn<InputT extends @Nullable Object,AccumT extends @Nullable Object, OutputT extends @Nullable Object> ACombineFn<InputT, AccumT, OutputT>specifies how to combine a collection of input values of typeInputTinto a single output value of typeOutputT.static classCombine.Globally<InputT, OutputT>takes aPCollection<InputT>and returns aPCollection<OutputT>whose elements are the result of combining all the elements in each window of the inputPCollection, using a specifiedCombineFn<InputT, AccumT, OutputT>.static classCombine.GloballyAsSingletonView<InputT, OutputT>takes aPCollection<InputT>and returns aPCollectionView<OutputT>whose elements are the result of combining all the elements in each window of the inputPCollection, using a specifiedCombineFn<InputT, AccumT, OutputT>.static classGroupedValues<K, InputT, OutputT>takes aPCollection<KV<K, Iterable<InputT>>>, such as the result ofGroupByKey, applies a specifiedCombineFn<InputT, AccumT, OutputT>to each of the inputKV<K, Iterable<InputT>>elements to produce a combined outputKV<K, OutputT>element, and returns aPCollection<KV<K, OutputT>>containing all the combined output elements.static classHolds a single value value of typeVwhich may or may not be present.static classstatic classPerKey<K, InputT, OutputT>takes aPCollection<KV<K, InputT>>, groups it by key, applies a combining function to theInputTvalues associated with each key to produce a combinedOutputTvalue, and returns aPCollection<KV<K, OutputT>>representing a map from each distinct key of the inputPCollectionto the corresponding combined value.static classLikeCombine.PerKey, but sharding the combining of hot keys.static classDeprecated. -
Method Summary
Modifier and TypeMethodDescriptionstatic <K,InputT, OutputT>
Combine.PerKey<K, InputT, OutputT> fewKeys(CombineFnBase.GlobalCombineFn<? super InputT, ?, OutputT> fn) Returns aCombine.PerKey, and set fewKeys inGroupByKey.static <InputT,OutputT>
Combine.Globally<InputT, OutputT> globally(CombineFnBase.GlobalCombineFn<? super InputT, ?, OutputT> fn) Returns aCombine.GloballyPTransformthat uses the givenGloballyCombineFnto combine all the elements in each window of the inputPCollectioninto a single value in the outputPCollection.static <V> Combine.Globally<V, V> globally(SerializableBiFunction<V, V, V> combiner) Returns aCombine.GloballyPTransformthat uses the givenSerializableBiFunctionto combine all the elements in each window of the inputPCollectioninto a single value in the outputPCollection.static <V> Combine.Globally<V, V> globally(SerializableFunction<Iterable<V>, V> combiner) Returns aCombine.GloballyPTransformthat uses the givenSerializableFunctionto combine all the elements in each window of the inputPCollectioninto a single value in the outputPCollection.static <K,InputT, OutputT>
Combine.GroupedValues<K, InputT, OutputT> groupedValues(CombineFnBase.GlobalCombineFn<? super InputT, ?, OutputT> fn) Returns aCombine.GroupedValuesPTransformthat takes aPCollectionofKVs where a key maps to anIterableof values, e.g., the result of aGroupByKey, then uses the givenCombineFnto combine all the values associated with a key, ignoring the key.static <K,V> Combine.GroupedValues <K, V, V> groupedValues(SerializableBiFunction<V, V, V> fn) Returns aCombine.GroupedValuesPTransformthat takes aPCollectionofKVs where a key maps to anIterableof values, e.g., the result of aGroupByKey, then uses the givenSerializableFunctionto combine all the values associated with a key, ignoring the key.static <K,V> Combine.GroupedValues <K, V, V> groupedValues(SerializableFunction<Iterable<V>, V> fn) Returns aCombine.GroupedValuesPTransformthat takes aPCollectionofKVs where a key maps to anIterableof values, e.g., the result of aGroupByKey, then uses the givenSerializableFunctionto combine all the values associated with a key, ignoring the key.static <K,InputT, OutputT>
Combine.PerKey<K, InputT, OutputT> perKey(CombineFnBase.GlobalCombineFn<? super InputT, ?, OutputT> fn) Returns aCombine.PerKeyPTransformthat first groups its inputPCollectionofKVs by keys and windows, then invokes the given function on each of the values lists to produce a combined value, and then returns aPCollectionofKVs mapping each distinct key to its combined value for each window.static <K,V> Combine.PerKey <K, V, V> perKey(SerializableBiFunction<V, V, V> fn) Returns aCombine.PerKeyPTransformthat first groups its inputPCollectionofKVs by keys and windows, then invokes the given function on each of the values lists to produce a combined value, and then returns aPCollectionofKVs mapping each distinct key to its combined value for each window.static <K,V> Combine.PerKey <K, V, V> perKey(SerializableFunction<Iterable<V>, V> fn) Returns aCombine.PerKeyPTransformthat first groups its inputPCollectionofKVs by keys and windows, then invokes the given function on each of the values lists to produce a combined value, and then returns aPCollectionofKVs mapping each distinct key to its combined value for each window.
-
Method Details
-
globally
Returns aCombine.GloballyPTransformthat uses the givenSerializableFunctionto combine all the elements in each window of the inputPCollectioninto a single value in the outputPCollection. The types of the input elements and the output elements must be the same.If the input
PCollectionis windowed intoGlobalWindows, a default value in theGlobalWindowwill be output if the inputPCollectionis empty. To use this with inputs with other windowing, eitherCombine.Globally.withoutDefaults()orCombine.Globally.asSingletonView()must be called.See
Combine.Globallyfor more information. -
globally
Returns aCombine.GloballyPTransformthat uses the givenSerializableBiFunctionto combine all the elements in each window of the inputPCollectioninto a single value in the outputPCollection. The types of the input elements and the output elements must be the same.If the input
PCollectionis windowed intoGlobalWindows, a default value in theGlobalWindowwill be output if the inputPCollectionis empty. To use this with inputs with other windowing, eitherCombine.Globally.withoutDefaults()orCombine.Globally.asSingletonView()must be called.See
Combine.Globallyfor more information. -
globally
public static <InputT,OutputT> Combine.Globally<InputT,OutputT> globally(CombineFnBase.GlobalCombineFn<? super InputT, ?, OutputT> fn) Returns aCombine.GloballyPTransformthat uses the givenGloballyCombineFnto combine all the elements in each window of the inputPCollectioninto a single value in the outputPCollection. The types of the input elements and the output elements can differ.If the input
PCollectionis windowed intoGlobalWindows, a default value in theGlobalWindowwill be output if the inputPCollectionis empty. To use this with inputs with other windowing, eitherCombine.Globally.withoutDefaults()orCombine.Globally.asSingletonView()must be called.See
Combine.Globallyfor more information. -
perKey
Returns aCombine.PerKeyPTransformthat first groups its inputPCollectionofKVs by keys and windows, then invokes the given function on each of the values lists to produce a combined value, and then returns aPCollectionofKVs mapping each distinct key to its combined value for each window.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
PCollectionhas the sameWindowFnas the input.See
Combine.PerKeyfor more information. -
perKey
Returns aCombine.PerKeyPTransformthat first groups its inputPCollectionofKVs by keys and windows, then invokes the given function on each of the values lists to produce a combined value, and then returns aPCollectionofKVs mapping each distinct key to its combined value for each window.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
PCollectionhas the sameWindowFnas the input.See
Combine.PerKeyfor more information. -
perKey
public static <K,InputT, Combine.PerKey<K,OutputT> InputT, perKeyOutputT> (CombineFnBase.GlobalCombineFn<? super InputT, ?, OutputT> fn) Returns aCombine.PerKeyPTransformthat first groups its inputPCollectionofKVs by keys and windows, then invokes the given function on each of the values lists to produce a combined value, and then returns aPCollectionofKVs mapping each distinct key to its combined value for each window.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
PCollectionhas the sameWindowFnas the input.See
Combine.PerKeyfor more information. -
fewKeys
@Internal public static <K,InputT, Combine.PerKey<K,OutputT> InputT, fewKeysOutputT> (CombineFnBase.GlobalCombineFn<? super InputT, ?, OutputT> fn) Returns aCombine.PerKey, and set fewKeys inGroupByKey. -
groupedValues
public static <K,V> Combine.GroupedValues<K,V, groupedValuesV> (SerializableFunction<Iterable<V>, V> fn) Returns aCombine.GroupedValuesPTransformthat takes aPCollectionofKVs where a key maps to anIterableof values, e.g., the result of aGroupByKey, then uses the givenSerializableFunctionto combine all the values associated with a key, ignoring the key. The type of the input and output values must be the same.Each output element has the same timestamp and is in the same window as its corresponding input element, and the output
PCollectionhas the sameWindowFnassociated with it as the input.See
Combine.GroupedValuesfor more information.Note that
perKey(SerializableFunction)is typically more convenient to use thanGroupByKeyfollowed bygroupedValues(...). -
groupedValues
Returns aCombine.GroupedValuesPTransformthat takes aPCollectionofKVs where a key maps to anIterableof values, e.g., the result of aGroupByKey, then uses the givenSerializableFunctionto combine all the values associated with a key, ignoring the key. The type of the input and output values must be the same.Each output element has the same timestamp and is in the same window as its corresponding input element, and the output
PCollectionhas the sameWindowFnassociated with it as the input.See
Combine.GroupedValuesfor more information.Note that
perKey(SerializableBiFunction)is typically more convenient to use thanGroupByKeyfollowed bygroupedValues(...). -
groupedValues
public static <K,InputT, Combine.GroupedValues<K,OutputT> InputT, groupedValuesOutputT> (CombineFnBase.GlobalCombineFn<? super InputT, ?, OutputT> fn) Returns aCombine.GroupedValuesPTransformthat takes aPCollectionofKVs where a key maps to anIterableof values, e.g., the result of aGroupByKey, then uses the givenCombineFnto combine all the values associated with a key, ignoring the key. The types of the input and output values can differ.Each output element has the same timestamp and is in the same window as its corresponding input element, and the output
PCollectionhas the sameWindowFnassociated with it as the input.See
Combine.GroupedValuesfor more information.Note that
perKey(CombineFnBase.GlobalCombineFn)is typically more convenient to use thanGroupByKeyfollowed bygroupedValues(...).
-