Package org.apache.beam.sdk.values
Class TypeDescriptors
- java.lang.Object
-
- org.apache.beam.sdk.values.TypeDescriptors
-
public class TypeDescriptors extends java.lang.Object
A utility class for creatingTypeDescriptor
objects for different types, such as Java primitive types, containers andKVs
of otherTypeDescriptor
objects, and extracting type variables of parameterized types (e.g. extracting theOutputT
type variable of aDoFn<InputT, OutputT>
).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
TypeDescriptors.TypeVariableExtractor<InputT,OutputT>
A helper interface for use withextractFromTypeParameters(Object, Class, TypeVariableExtractor)
.
-
Constructor Summary
Constructors Constructor Description TypeDescriptors()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static TypeDescriptor<java.math.BigDecimal>
bigdecimals()
TheTypeDescriptor
for BigDecimal.static TypeDescriptor<java.math.BigInteger>
bigintegers()
TheTypeDescriptor
for BigInteger.static TypeDescriptor<java.lang.Boolean>
booleans()
TheTypeDescriptor
for Boolean.static TypeDescriptor<java.lang.Byte>
bytes()
TheTypeDescriptor
for Byte.static TypeDescriptor<java.lang.Character>
characters()
TheTypeDescriptor
for Character.static TypeDescriptor<java.lang.Double>
doubles()
TheTypeDescriptor
for Double.static <T,V>
TypeDescriptor<V>extractFromTypeParameters(@NonNull T instance, java.lang.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, java.lang.Class<? super T> supertype, TypeDescriptors.TypeVariableExtractor<T,V> extractor)
LikeextractFromTypeParameters(Object, Class, TypeVariableExtractor)
, but takes aTypeDescriptor
of the instance being analyzed rather than the instance itself.static TypeDescriptor<java.lang.Float>
floats()
TheTypeDescriptor
for 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<java.lang.Integer>
integers()
TheTypeDescriptor
for Integer.static <T> TypeDescriptor<java.lang.Iterable<T>>
iterables(TypeDescriptor<T> iterable)
TheTypeDescriptor
forIterable
.static <K,V>
TypeDescriptor<KV<K,V>>kvs(TypeDescriptor<K> key, TypeDescriptor<V> value)
TheTypeDescriptor
forKV
.static <T> TypeDescriptor<java.util.List<T>>
lists(TypeDescriptor<T> element)
TheTypeDescriptor
forList
.static TypeDescriptor<java.lang.Long>
longs()
TheTypeDescriptor
for Long.static <K,V>
TypeDescriptor<java.util.Map<K,V>>maps(TypeDescriptor<K> keyType, TypeDescriptor<V> valueType)
TheTypeDescriptor
forMap
.static TypeDescriptor<java.lang.Void>
nulls()
TheTypeDescriptor
for 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()
TheTypeDescriptor
forRow
.static <T> TypeDescriptor<java.util.Set<T>>
sets(TypeDescriptor<T> element)
TheTypeDescriptor
forSet
.static TypeDescriptor<java.lang.Short>
shorts()
TheTypeDescriptor
for Short.static TypeDescriptor<java.lang.String>
strings()
TheTypeDescriptor
for String.static TypeDescriptor<java.lang.Void>
voids()
-
-
-
Method Detail
-
booleans
public static TypeDescriptor<java.lang.Boolean> booleans()
TheTypeDescriptor
for Boolean. This is the equivalent of:new TypeDescriptor<Boolean>() {};
- Returns:
- A
TypeDescriptor
for Boolean
-
doubles
public static TypeDescriptor<java.lang.Double> doubles()
TheTypeDescriptor
for Double. This is the equivalent of:new TypeDescriptor<Double>() {};
- Returns:
- A
TypeDescriptor
for Double
-
floats
public static TypeDescriptor<java.lang.Float> floats()
TheTypeDescriptor
for Float. This is the equivalent of:new TypeDescriptor<Float>() {};
- Returns:
- A
TypeDescriptor
for Float
-
integers
public static TypeDescriptor<java.lang.Integer> integers()
TheTypeDescriptor
for Integer. This is the equivalent of:new TypeDescriptor<Integer>() {};
- Returns:
- A
TypeDescriptor
for Integer
-
longs
public static TypeDescriptor<java.lang.Long> longs()
TheTypeDescriptor
for Long. This is the equivalent of:new TypeDescriptor<Long>() {};
- Returns:
- A
TypeDescriptor
for Long
-
shorts
public static TypeDescriptor<java.lang.Short> shorts()
TheTypeDescriptor
for Short. This is the equivalent of:new TypeDescriptor<Short>() {};
- Returns:
- A
TypeDescriptor
for Short
-
bigdecimals
public static TypeDescriptor<java.math.BigDecimal> bigdecimals()
TheTypeDescriptor
for BigDecimal. This is the equivalent of:new TypeDescriptor<BigDecimal>() {};
- Returns:
- A
TypeDescriptor
for BigDecimal
-
bigintegers
public static TypeDescriptor<java.math.BigInteger> bigintegers()
TheTypeDescriptor
for BigInteger. This is the equivalent of:new TypeDescriptor<BigInteger>() {};
- Returns:
- A
TypeDescriptor
for BigInteger
-
rows
public static TypeDescriptor<Row> rows()
- Returns:
- A
TypeDescriptor
for Row
-
strings
public static TypeDescriptor<java.lang.String> strings()
TheTypeDescriptor
for String. This is the equivalent of:new TypeDescriptor<String>() {};
- Returns:
- A
TypeDescriptor
for String
-
characters
public static TypeDescriptor<java.lang.Character> characters()
TheTypeDescriptor
for Character. This is the equivalent of:new TypeDescriptor<Character>() {};
- Returns:
- A
TypeDescriptor
for Character
-
bytes
public static TypeDescriptor<java.lang.Byte> bytes()
TheTypeDescriptor
for Byte. This is the equivalent of:new TypeDescriptor<Byte>() {};
- Returns:
- A
TypeDescriptor
for Byte
-
nulls
public static TypeDescriptor<java.lang.Void> nulls()
TheTypeDescriptor
for nulls/Void. This is the equivalent of:new TypeDescriptor<Void>() {};
- Returns:
- A
TypeDescriptor
for nulls/Void
-
kvs
public static <K,V> TypeDescriptor<KV<K,V>> kvs(TypeDescriptor<K> key, TypeDescriptor<V> value)
TheTypeDescriptor
forKV
. 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
- TheTypeDescriptor
for the keyvalue
- TheTypeDescriptor
for the value- Returns:
- A
TypeDescriptor
forKV
-
sets
public static <T> TypeDescriptor<java.util.Set<T>> sets(TypeDescriptor<T> element)
TheTypeDescriptor
forSet
. 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
- TheTypeDescriptor
for the set- Returns:
- A
TypeDescriptor
forSet
-
maps
public static <K,V> TypeDescriptor<java.util.Map<K,V>> maps(TypeDescriptor<K> keyType, TypeDescriptor<V> valueType)
TheTypeDescriptor
forMap
.
-
lists
public static <T> TypeDescriptor<java.util.List<T>> lists(TypeDescriptor<T> element)
TheTypeDescriptor
forList
. 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
- TheTypeDescriptor
for the list- Returns:
- A
TypeDescriptor
forList
-
iterables
public static <T> TypeDescriptor<java.lang.Iterable<T>> iterables(TypeDescriptor<T> iterable)
TheTypeDescriptor
forIterable
. 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
- TheTypeDescriptor
for the iterable- Returns:
- A
TypeDescriptor
forIterable
-
voids
public static TypeDescriptor<java.lang.Void> voids()
-
extractFromTypeParameters
public static <T,V> TypeDescriptor<V> extractFromTypeParameters(@NonNull T instance, java.lang.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
TypeDescriptor
for 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, java.lang.Class<? super T> supertype, TypeDescriptors.TypeVariableExtractor<T,V> extractor)
LikeextractFromTypeParameters(Object, Class, TypeVariableExtractor)
, but takes aTypeDescriptor
of the instance being analyzed rather than the instance itself.
-
inputOf
public 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.
-
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
public static <InputT,OutputT> TypeDescriptor<InputT> inputOf(Contextful.Fn<InputT,OutputT> fn)
LikeinputOf(ProcessFunction)
but forContextful.Fn
.
-
outputOf
public static <InputT,OutputT> TypeDescriptor<OutputT> outputOf(Contextful.Fn<InputT,OutputT> fn)
LikeoutputOf(ProcessFunction)
but forContextful.Fn
.
-
-