Package org.apache.beam.sdk.values
Class TypeDescriptors
java.lang.Object
org.apache.beam.sdk.values.TypeDescriptors
A utility class for creating
TypeDescriptor objects for different types, such as Java
primitive types, containers and KVs of other TypeDescriptor objects, and
extracting type variables of parameterized types (e.g. extracting the OutputT type
variable of a DoFn<InputT, OutputT>).-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA helper interface for use withextractFromTypeParameters(Object, Class, TypeVariableExtractor). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic TypeDescriptor<BigDecimal> TheTypeDescriptorfor BigDecimal.static TypeDescriptor<BigInteger> TheTypeDescriptorfor BigInteger.static TypeDescriptor<Boolean> booleans()TheTypeDescriptorfor Boolean.static TypeDescriptor<Byte> bytes()TheTypeDescriptorfor Byte.static TypeDescriptor<Character> TheTypeDescriptorfor Character.static TypeDescriptor<Double> doubles()TheTypeDescriptorfor Double.static <T,V> TypeDescriptor <V> extractFromTypeParameters(@NonNull T instance, Class<? super T> supertype, TypeDescriptors.TypeVariableExtractor<T, V> extractor) Extracts a type from the actual type parameters of a parameterized class, subject to Java type erasure.static <T,V> TypeDescriptor <V> extractFromTypeParameters(TypeDescriptor<T> type, Class<? super T> supertype, TypeDescriptors.TypeVariableExtractor<T, V> extractor) LikeextractFromTypeParameters(Object, Class, TypeVariableExtractor), but takes aTypeDescriptorof the instance being analyzed rather than the instance itself.static TypeDescriptor<Float> floats()TheTypeDescriptorfor Float.static <InputT,OutputT>
TypeDescriptor<InputT> inputOf(Contextful.Fn<InputT, OutputT> fn) LikeinputOf(ProcessFunction)but forContextful.Fn.static <InputT,OutputT>
TypeDescriptor<InputT> inputOf(ProcessFunction<InputT, OutputT> fn) Returns a type descriptor for the input of the givenProcessFunction, subject to Java type erasure: may contain unresolved type variables if the type was erased.static <InputT,OutputT>
TypeDescriptor<InputT> inputOf(SerializableFunction<InputT, OutputT> fn) Binary compatibility adapter forinputOf(ProcessFunction).static TypeDescriptor<Integer> integers()TheTypeDescriptorfor Integer.static <T> TypeDescriptor<Iterable<T>> iterables(TypeDescriptor<T> iterable) TheTypeDescriptorforIterable.static <K,V> TypeDescriptor <KV<K, V>> kvs(TypeDescriptor<K> key, TypeDescriptor<V> value) TheTypeDescriptorforKV.static <T> TypeDescriptor<List<T>> lists(TypeDescriptor<T> element) TheTypeDescriptorforList.static TypeDescriptor<Long> longs()TheTypeDescriptorfor Long.static <K,V> TypeDescriptor <Map<K, V>> maps(TypeDescriptor<K> keyType, TypeDescriptor<V> valueType) TheTypeDescriptorforMap.static TypeDescriptor<Void> nulls()TheTypeDescriptorfor nulls/Void.static <InputT,OutputT>
TypeDescriptor<OutputT> outputOf(Contextful.Fn<InputT, OutputT> fn) LikeoutputOf(ProcessFunction)but forContextful.Fn.static <InputT,OutputT>
TypeDescriptor<OutputT> outputOf(ProcessFunction<InputT, OutputT> fn) Returns a type descriptor for the output of the givenProcessFunction, subject to Java type erasure: may contain unresolved type variables if the type was erased.static <InputT,OutputT>
TypeDescriptor<OutputT> outputOf(SerializableFunction<InputT, OutputT> fn) Binary compatibility adapter foroutputOf(ProcessFunction).static TypeDescriptor<Row> rows()TheTypeDescriptorforRow.static <T> TypeDescriptor<Set<T>> sets(TypeDescriptor<T> element) TheTypeDescriptorforSet.static TypeDescriptor<Short> shorts()TheTypeDescriptorfor Short.static TypeDescriptor<String> strings()TheTypeDescriptorfor String.static TypeDescriptor<Void> voids()
-
Constructor Details
-
TypeDescriptors
public TypeDescriptors()
-
-
Method Details
-
booleans
TheTypeDescriptorfor Boolean. This is the equivalent of:new TypeDescriptor<Boolean>() {};- Returns:
- A
TypeDescriptorfor Boolean
-
doubles
TheTypeDescriptorfor Double. This is the equivalent of:new TypeDescriptor<Double>() {};- Returns:
- A
TypeDescriptorfor Double
-
floats
TheTypeDescriptorfor Float. This is the equivalent of:new TypeDescriptor<Float>() {};- Returns:
- A
TypeDescriptorfor Float
-
integers
TheTypeDescriptorfor Integer. This is the equivalent of:new TypeDescriptor<Integer>() {};- Returns:
- A
TypeDescriptorfor Integer
-
longs
TheTypeDescriptorfor Long. This is the equivalent of:new TypeDescriptor<Long>() {};- Returns:
- A
TypeDescriptorfor Long
-
shorts
TheTypeDescriptorfor Short. This is the equivalent of:new TypeDescriptor<Short>() {};- Returns:
- A
TypeDescriptorfor Short
-
bigdecimals
TheTypeDescriptorfor BigDecimal. This is the equivalent of:new TypeDescriptor<BigDecimal>() {};- Returns:
- A
TypeDescriptorfor BigDecimal
-
bigintegers
TheTypeDescriptorfor BigInteger. This is the equivalent of:new TypeDescriptor<BigInteger>() {};- Returns:
- A
TypeDescriptorfor BigInteger
-
rows
- Returns:
- A
TypeDescriptorfor Row
-
strings
TheTypeDescriptorfor String. This is the equivalent of:new TypeDescriptor<String>() {};- Returns:
- A
TypeDescriptorfor String
-
characters
TheTypeDescriptorfor Character. This is the equivalent of:new TypeDescriptor<Character>() {};- Returns:
- A
TypeDescriptorfor Character
-
bytes
TheTypeDescriptorfor Byte. This is the equivalent of:new TypeDescriptor<Byte>() {};- Returns:
- A
TypeDescriptorfor Byte
-
nulls
TheTypeDescriptorfor nulls/Void. This is the equivalent of:new TypeDescriptor<Void>() {};- Returns:
- A
TypeDescriptorfor nulls/Void
-
kvs
TheTypeDescriptorforKV. This is the equivalent of:new TypeDescriptor<KV<K,V>>() {};Example of use:
PCollection<String> words = ...; PCollection<KV<String, String>> words = words.apply(FlatMapElements .into(TypeDescriptors.kv(TypeDescriptors.strings(), TypeDescriptors.strings())) .via(...));- Parameters:
key- TheTypeDescriptorfor the keyvalue- TheTypeDescriptorfor the value- Returns:
- A
TypeDescriptorforKV
-
sets
TheTypeDescriptorforSet. This is the equivalent of:new TypeDescriptor<Set<E>>() {};Example of use:
PCollection<String> words = ...; PCollection<Set<String>> words = words.apply(FlatMapElements .into(TypeDescriptors.sets(TypeDescriptors.strings())) .via(...));- Parameters:
element- TheTypeDescriptorfor the set- Returns:
- A
TypeDescriptorforSet
-
maps
public static <K,V> TypeDescriptor<Map<K,V>> maps(TypeDescriptor<K> keyType, TypeDescriptor<V> valueType) TheTypeDescriptorforMap. -
lists
TheTypeDescriptorforList. This is the equivalent of:new TypeDescriptor<List<E>>() {};Example of use:
PCollection<String> words = ...; PCollection<List<String>> words = words.apply(FlatMapElements .into(TypeDescriptors.lists(TypeDescriptors.strings())) .via(...));- Parameters:
element- TheTypeDescriptorfor the list- Returns:
- A
TypeDescriptorforList
-
iterables
TheTypeDescriptorforIterable. This is the equivalent of:new TypeDescriptor<Iterable<E>>() {};Example of use:
PCollection<String> words = ...; PCollection<Iterable<String>> words = words.apply(FlatMapElements .into(TypeDescriptors.iterables(TypeDescriptors.strings())) .via(...));- Parameters:
iterable- TheTypeDescriptorfor the iterable- Returns:
- A
TypeDescriptorforIterable
-
voids
-
extractFromTypeParameters
public static <T,V> TypeDescriptor<V> extractFromTypeParameters(@NonNull T instance, Class<? super T> supertype, TypeDescriptors.TypeVariableExtractor<T, V> extractor) Extracts a type from the actual type parameters of a parameterized class, subject to Java type erasure. The type to extract is specified in a way that is safe w.r.t. changing the type signature of the parameterized class, as opposed to specifying the name or index of a type variable.Example of use:
class Foo<BarT> { private ProcessFunction<BarT, String> fn; TypeDescriptor<BarT> inferBarTypeDescriptorFromFn() { return TypeDescriptors.extractFromTypeParameters( fn, ProcessFunction.class, // The actual type of "fn" is matched against the input type of the extractor, // and the obtained values of type variables of the superclass are substituted // into the output type of the extractor. new TypeVariableExtractor<ProcessFunction<BarT, String>, BarT>() {}); } }- Parameters:
instance- The object being analyzedsupertype- Parameterized superclass of interestextractor- A class for specifying the type to extract from the supertype- Returns:
- A
TypeDescriptorfor the actual value of the result type of the extractor, potentially containing unresolved type variables if the type was erased.
-
extractFromTypeParameters
public static <T,V> TypeDescriptor<V> extractFromTypeParameters(TypeDescriptor<T> type, Class<? super T> supertype, TypeDescriptors.TypeVariableExtractor<T, V> extractor) LikeextractFromTypeParameters(Object, Class, TypeVariableExtractor), but takes aTypeDescriptorof the instance being analyzed rather than the instance itself. -
inputOf
Returns a type descriptor for the input of the givenProcessFunction, subject to Java type erasure: may contain unresolved type variables if the type was erased. -
inputOf
public static <InputT,OutputT> TypeDescriptor<InputT> inputOf(SerializableFunction<InputT, OutputT> fn) Binary compatibility adapter forinputOf(ProcessFunction). -
outputOf
public static <InputT,OutputT> TypeDescriptor<OutputT> outputOf(ProcessFunction<InputT, OutputT> fn) Returns a type descriptor for the output of the givenProcessFunction, subject to Java type erasure: may contain unresolved type variables if the type was erased. -
outputOf
public static <InputT,OutputT> TypeDescriptor<OutputT> outputOf(SerializableFunction<InputT, OutputT> fn) Binary compatibility adapter foroutputOf(ProcessFunction). -
inputOf
LikeinputOf(ProcessFunction)but forContextful.Fn. -
outputOf
LikeoutputOf(ProcessFunction)but forContextful.Fn.
-