Class Distinct<T>
- java.lang.Object
-
- org.apache.beam.sdk.transforms.PTransform<PCollection<T>,PCollection<T>>
-
- org.apache.beam.sdk.transforms.Distinct<T>
-
- Type Parameters:
T
- the type of the elements of the input and outputPCollection
s
- All Implemented Interfaces:
java.io.Serializable
,HasDisplayData
public class Distinct<T> extends PTransform<PCollection<T>,PCollection<T>>
Distinct<T>
takes aPCollection<T>
and returns aPCollection<T>
that has all distinct elements of the input. Thus, each element is unique within each window.Two values of type
T
are compared for equality not by regular JavaObject.equals(java.lang.Object)
, but instead by first encoding each of the elements using thePCollection
'sCoder
, and then comparing the encoded bytes. This admits efficient parallel evaluation.Optionally, a function may be provided that maps each element to a representative value. In this case, two elements will be considered duplicates if they have equal representative values, with equality being determined as above.
By default, the
Coder
of the outputPCollection
is the same as theCoder
of the inputPCollection
.Each output element is in the same window as its corresponding input element, and has the timestamp of the end of that window. The output
PCollection
has the sameWindowFn
as the input.Does not preserve any order the input PCollection might have had.
Example of use:
PCollection<String> words = ...; PCollection<String> uniqueWords = words.apply(Distinct.<String>create());
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Distinct.WithRepresentativeValues<T,IdT>
ADistinct
PTransform
that uses aSerializableFunction
to obtain a representative value for each input element.
-
Field Summary
-
Fields inherited from class org.apache.beam.sdk.transforms.PTransform
name, resourceHints
-
-
Constructor Summary
Constructors Constructor Description Distinct()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> Distinct<T>
create()
Returns aDistinct<T>
PTransform
.PCollection<T>
expand(PCollection<T> in)
Override this method to specify how thisPTransform
should be expanded on the givenInputT
.static <T,IdT>
Distinct.WithRepresentativeValues<T,IdT>withRepresentativeValueFn(SerializableFunction<T,IdT> fn)
Returns aDistinct<T, IdT>
PTransform
.-
Methods inherited from class org.apache.beam.sdk.transforms.PTransform
compose, compose, getAdditionalInputs, getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, getResourceHints, populateDisplayData, setResourceHints, toString, validate, validate
-
-
-
-
Method Detail
-
create
public static <T> Distinct<T> create()
Returns aDistinct<T>
PTransform
.- Type Parameters:
T
- the type of the elements of the input and outputPCollection
s
-
withRepresentativeValueFn
public static <T,IdT> Distinct.WithRepresentativeValues<T,IdT> withRepresentativeValueFn(SerializableFunction<T,IdT> fn)
Returns aDistinct<T, IdT>
PTransform
.- Type Parameters:
T
- the type of the elements of the input and outputPCollection
sIdT
- the type of the representative value used to dedup
-
expand
public PCollection<T> expand(PCollection<T> in)
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<T>,PCollection<T>>
-
-