/** * Returns a {@link PerKey Combine.PerKey} {@code PTransform} that first groups its input {@code * PCollection} of {@code KV}s by keys and windows, then invokes the given function on each of the * values lists to produce a combined value, and then returns a {@code PCollection} of {@code KV}s * mapping each distinct key to its combined value for each window. * * <p>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 {@code PCollection} has the same {@link * org.apache.beam.sdk.transforms.windowing.WindowFn} as the input. * * <p>See {@link PerKey Combine.PerKey} for more information. */ public static <K, InputT, OutputT> PerKey<K, InputT, OutputT> perKey( GlobalCombineFn<? super InputT, ?, OutputT> fn) { return perKey(fn, displayDataForFn(fn)); }
/** * Returns a {@link Globally Combine.Globally} {@code PTransform} that uses the given {@code * GloballyCombineFn} to combine all the elements in each window of the input {@code PCollection} * into a single value in the output {@code PCollection}. The types of the input elements and the * output elements can differ. * * <p>If the input {@code PCollection} is windowed into {@link GlobalWindows}, a default value in * the {@link GlobalWindow} will be output if the input {@code PCollection} is empty. To use this * with inputs with other windowing, either {@link Globally#withoutDefaults} or {@link * Globally#asSingletonView} must be called. * * <p>See {@link Globally Combine.Globally} for more information. */ public static <InputT, OutputT> Globally<InputT, OutputT> globally( GlobalCombineFn<? super InputT, ?, OutputT> fn) { return globally(fn, displayDataForFn(fn)); }
/** * Returns a {@link GroupedValues Combine.GroupedValues} {@code PTransform} that takes a {@code * PCollection} of {@code KV}s where a key maps to an {@code Iterable} of values, e.g., the result * of a {@code GroupByKey}, then uses the given {@code CombineFn} to combine all the values * associated with a key, ignoring the key. The types of the input and output values can differ. * * <p>Each output element has the same timestamp and is in the same window as its corresponding * input element, and the output {@code PCollection} has the same {@link * org.apache.beam.sdk.transforms.windowing.WindowFn} associated with it as the input. * * <p>See {@link GroupedValues Combine.GroupedValues} for more information. * * <p>Note that {@link #perKey(CombineFnBase.GlobalCombineFn)} is typically more convenient to use * than {@link GroupByKey} followed by {@code groupedValues(...)}. */ public static <K, InputT, OutputT> GroupedValues<K, InputT, OutputT> groupedValues( GlobalCombineFn<? super InputT, ?, OutputT> fn) { return groupedValues(fn, displayDataForFn(fn)); }
/** * Returns a {@link Globally Combine.Globally} {@code PTransform} that uses the given {@code * SerializableFunction} to combine all the elements in each window of the input {@code * PCollection} into a single value in the output {@code PCollection}. The types of the input * elements and the output elements must be the same. * * <p>If the input {@code PCollection} is windowed into {@link GlobalWindows}, a default value in * the {@link GlobalWindow} will be output if the input {@code PCollection} is empty. To use this * with inputs with other windowing, either {@link Globally#withoutDefaults} or {@link * Globally#asSingletonView} must be called. * * <p>See {@link Globally Combine.Globally} for more information. */ public static <V> Globally<V, V> globally(SerializableFunction<Iterable<V>, V> combiner) { return globally(IterableCombineFn.of(combiner), displayDataForFn(combiner)); }
/** * Returns a {@link PerKey Combine.PerKey} {@code PTransform} that first groups its input {@code * PCollection} of {@code KV}s by keys and windows, then invokes the given function on each of the * values lists to produce a combined value, and then returns a {@code PCollection} of {@code KV}s * mapping each distinct key to its combined value for each window. * * <p>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 {@code PCollection} has the same {@link * org.apache.beam.sdk.transforms.windowing.WindowFn} as the input. * * <p>See {@link PerKey Combine.PerKey} for more information. */ public static <K, V> PerKey<K, V, V> perKey(SerializableFunction<Iterable<V>, V> fn) { return perKey(IterableCombineFn.of(fn), displayDataForFn(fn)); }
/** * Returns a {@link GroupedValues Combine.GroupedValues} {@code PTransform} that takes a {@code * PCollection} of {@code KV}s where a key maps to an {@code Iterable} of values, e.g., the result * of a {@code GroupByKey}, then uses the given {@code SerializableFunction} to combine all the * values associated with a key, ignoring the key. The type of the input and output values must be * the same. * * <p>Each output element has the same timestamp and is in the same window as its corresponding * input element, and the output {@code PCollection} has the same {@link * org.apache.beam.sdk.transforms.windowing.WindowFn} associated with it as the input. * * <p>See {@link GroupedValues Combine.GroupedValues} for more information. * * <p>Note that {@link #perKey(SerializableFunction)} is typically more convenient to use than * {@link GroupByKey} followed by {@code groupedValues(...)}. */ public static <K, V> GroupedValues<K, V, V> groupedValues( SerializableFunction<Iterable<V>, V> fn) { return groupedValues(IterableCombineFn.of(fn), displayDataForFn(fn)); }