Package org.apache.beam.sdk.transforms
Class Max
java.lang.Object
org.apache.beam.sdk.transforms.Max
PTransforms for computing the maximum of the elements in a PCollection, or the
maximum of the values associated with each key in a PCollection of KVs.
Example 1: get the maximum of a PCollection of Doubles.
PCollection<Double> input = ...;
PCollection<Double> max = input.apply(Max.doublesGlobally());
Example 2: calculate the maximum of the Integers associated with each unique key
(which is of type String).
PCollection<KV<String, Integer>> input = ...;
PCollection<KV<String, Integer>> maxPerKey = input
.apply(Max.<String>integersPerKey());
-
Method Summary
Modifier and TypeMethodDescriptionstatic Combine.Globally<Double, Double> Returns aPTransformthat takes an inputPCollection<Double>and returns aPCollection<Double>whose contents is the maximum of the inputPCollection's elements, orDouble.NEGATIVE_INFINITYif there are no elements.static <K> Combine.PerKey<K, Double, Double> Returns aPTransformthat takes an inputPCollection<KV<K, Double>>and returns aPCollection<KV<K, Double>>that contains an output element mapping each distinct key in the inputPCollectionto the maximum of the values associated with that key in the inputPCollection.static <T extends Comparable<? super T>>
Combine.Globally<T, T> globally()Returns aPTransformthat takes an inputPCollection<T>and returns aPCollection<T>whose contents is the maximum according to the natural ordering ofTof the inputPCollection's elements, ornullif there are no elements.static <T,ComparatorT extends Comparator<? super T> & Serializable>
Combine.Globally<T, T> globally(ComparatorT comparator) Returns aPTransformthat takes an inputPCollection<T>and returns aPCollection<T>whose contents is the maximum of the inputPCollection's elements, ornullif there are no elements.static Combine.Globally<Integer, Integer> Returns aPTransformthat takes an inputPCollection<Integer>and returns aPCollection<Integer>whose contents is the maximum of the inputPCollection's elements, orInteger.MIN_VALUEif there are no elements.static <K> Combine.PerKey<K, Integer, Integer> Returns aPTransformthat takes an inputPCollection<KV<K, Integer>>and returns aPCollection<KV<K, Integer>>that contains an output element mapping each distinct key in the inputPCollectionto the maximum of the values associated with that key in the inputPCollection.static Combine.Globally<Long, Long> Returns aPTransformthat takes an inputPCollection<Long>and returns aPCollection<Long>whose contents is the maximum of the inputPCollection's elements, orLong.MIN_VALUEif there are no elements.static <K> Combine.PerKey<K, Long, Long> Returns aPTransformthat takes an inputPCollection<KV<K, Long>>and returns aPCollection<KV<K, Long>>that contains an output element mapping each distinct key in the inputPCollectionto the maximum of the values associated with that key in the inputPCollection.static <T extends Comparable<? super T>>
Combine.BinaryCombineFn<T> static <T extends Comparable<? super T>>
Combine.BinaryCombineFn<T> naturalOrder(T identity) static <T,ComparatorT extends Comparator<? super T> & Serializable>
Combine.BinaryCombineFn<T> of(ComparatorT comparator) ACombineFnthat computes the maximum of a collection of elements of typeTusing an arbitraryComparator, useful as an argument toCombine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)orCombine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>).static <T,ComparatorT extends Comparator<? super T> & Serializable>
Combine.BinaryCombineFn<T> of(T identity, ComparatorT comparator) ACombineFnthat computes the maximum of a collection of elements of typeTusing an arbitraryComparatorandidentity, useful as an argument toCombine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)orCombine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>).ACombineFnthat computes the maximum of a collection ofDoubles, useful as an argument toCombine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)orCombine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>).ACombineFnthat computes the maximum of a collection ofIntegers, useful as an argument toCombine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)orCombine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>).static Combine.BinaryCombineLongFnofLongs()ACombineFnthat computes the maximum of a collection ofLongs, useful as an argument toCombine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)orCombine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>).static <K,T extends Comparable<? super T>>
Combine.PerKey<K, T, T> perKey()Returns aPTransformthat takes an inputPCollection<KV<K, T>>and returns aPCollection<KV<K, T>>that contains an output element mapping each distinct key in the inputPCollectionto the maximum according to the natural ordering ofTof the values associated with that key in the inputPCollection.static <K,T, ComparatorT extends Comparator<? super T> & Serializable>
Combine.PerKey<K, T, T> perKey(ComparatorT comparator) Returns aPTransformthat takes an inputPCollection<KV<K, T>>and returns aPCollection<KV<K, T>>that contains one output element per key mapping each to the maximum of the values associated with that key in the inputPCollection.
-
Method Details
-
integersGlobally
Returns aPTransformthat takes an inputPCollection<Integer>and returns aPCollection<Integer>whose contents is the maximum of the inputPCollection's elements, orInteger.MIN_VALUEif there are no elements. -
integersPerKey
Returns aPTransformthat takes an inputPCollection<KV<K, Integer>>and returns aPCollection<KV<K, Integer>>that contains an output element mapping each distinct key in the inputPCollectionto the maximum of the values associated with that key in the inputPCollection.See
Combine.PerKeyfor how this affects timestamps and windowing. -
longsGlobally
Returns aPTransformthat takes an inputPCollection<Long>and returns aPCollection<Long>whose contents is the maximum of the inputPCollection's elements, orLong.MIN_VALUEif there are no elements. -
longsPerKey
Returns aPTransformthat takes an inputPCollection<KV<K, Long>>and returns aPCollection<KV<K, Long>>that contains an output element mapping each distinct key in the inputPCollectionto the maximum of the values associated with that key in the inputPCollection.See
Combine.PerKeyfor how this affects timestamps and windowing. -
doublesGlobally
Returns aPTransformthat takes an inputPCollection<Double>and returns aPCollection<Double>whose contents is the maximum of the inputPCollection's elements, orDouble.NEGATIVE_INFINITYif there are no elements. -
doublesPerKey
Returns aPTransformthat takes an inputPCollection<KV<K, Double>>and returns aPCollection<KV<K, Double>>that contains an output element mapping each distinct key in the inputPCollectionto the maximum of the values associated with that key in the inputPCollection.See
Combine.PerKeyfor how this affects timestamps and windowing. -
ofIntegers
ACombineFnthat computes the maximum of a collection ofIntegers, useful as an argument toCombine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)orCombine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>). -
ofLongs
ACombineFnthat computes the maximum of a collection ofLongs, useful as an argument toCombine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)orCombine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>). -
ofDoubles
ACombineFnthat computes the maximum of a collection ofDoubles, useful as an argument toCombine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)orCombine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>). -
of
public static <T,ComparatorT extends Comparator<? super T> & Serializable> Combine.BinaryCombineFn<T> of(T identity, ComparatorT comparator) ACombineFnthat computes the maximum of a collection of elements of typeTusing an arbitraryComparatorandidentity, useful as an argument toCombine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)orCombine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>).- Type Parameters:
T- the type of the values being compared
-
of
public static <T,ComparatorT extends Comparator<? super T> & Serializable> Combine.BinaryCombineFn<T> of(ComparatorT comparator) ACombineFnthat computes the maximum of a collection of elements of typeTusing an arbitraryComparator, useful as an argument toCombine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)orCombine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>).- Type Parameters:
T- the type of the values being compared
-
naturalOrder
-
naturalOrder
-
globally
Returns aPTransformthat takes an inputPCollection<T>and returns aPCollection<T>whose contents is the maximum according to the natural ordering ofTof the inputPCollection's elements, ornullif there are no elements. -
perKey
Returns aPTransformthat takes an inputPCollection<KV<K, T>>and returns aPCollection<KV<K, T>>that contains an output element mapping each distinct key in the inputPCollectionto the maximum according to the natural ordering ofTof the values associated with that key in the inputPCollection.See
Combine.PerKeyfor how this affects timestamps and windowing. -
globally
public static <T,ComparatorT extends Comparator<? super T> & Serializable> Combine.Globally<T,T> globally(ComparatorT comparator) Returns aPTransformthat takes an inputPCollection<T>and returns aPCollection<T>whose contents is the maximum of the inputPCollection's elements, ornullif there are no elements. -
perKey
public static <K,T, Combine.PerKey<K,ComparatorT extends Comparator<? super T> & Serializable> T, perKeyT> (ComparatorT comparator) Returns aPTransformthat takes an inputPCollection<KV<K, T>>and returns aPCollection<KV<K, T>>that contains one output element per key mapping each to the maximum of the values associated with that key in the inputPCollection.See
Combine.PerKeyfor how this affects timestamps and windowing.
-