@Public public class TypeExtractor extends Object
NOTES FOR USERS OF THIS CLASS: Automatic type extraction is a hacky business that depends on a
lot of variables such as generics, compiler, interfaces, etc. The type extraction fails regularly
with either MissingTypeInfo
or hard exceptions. Whenever you use methods of this class,
make sure to provide a way to pass custom type information as a fallback.
Modifier and Type | Field and Description |
---|---|
static int[] |
NO_INDEX |
Modifier | Constructor and Description |
---|---|
protected |
TypeExtractor() |
Modifier and Type | Method and Description |
---|---|
protected <OUT,IN1,IN2> |
analyzePojo(Type type,
List<Type> typeHierarchy,
TypeInformation<IN1> in1Type,
TypeInformation<IN2> in2Type) |
static <T> TypeInformation<T> |
createHadoopWritableTypeInfo(Class<T> clazz) |
static <IN1,IN2,OUT> |
createTypeInfo(Class<?> baseClass,
Class<?> clazz,
int returnParamPos,
TypeInformation<IN1> in1Type,
TypeInformation<IN2> in2Type) |
static <T> TypeInformation<T> |
createTypeInfo(Class<T> type) |
static <OUT> TypeInformation<OUT> |
createTypeInfo(Object instance,
Class<?> baseClass,
Class<?> clazz,
int returnParamPos)
Creates a
TypeInformation from the given parameters. |
static TypeInformation<?> |
createTypeInfo(Type t) |
static <IN,ACC> TypeInformation<ACC> |
getAggregateFunctionAccumulatorType(AggregateFunction<IN,ACC,?> function,
TypeInformation<IN> inType,
String functionName,
boolean allowMissing) |
static <IN,OUT> TypeInformation<OUT> |
getAggregateFunctionReturnType(AggregateFunction<IN,?,OUT> function,
TypeInformation<IN> inType,
String functionName,
boolean allowMissing) |
static List<Field> |
getAllDeclaredFields(Class<?> clazz,
boolean ignoreDuplicates)
Recursively determine all declared fields This is required because class.getFields() is not
returning fields defined in parent classes.
|
static <IN1,IN2,OUT> |
getBinaryOperatorReturnType(Function function,
Class<?> baseClass,
int input1TypeArgumentIndex,
int input2TypeArgumentIndex,
int outputTypeArgumentIndex,
int[] lambdaOutputTypeArgumentIndices,
TypeInformation<IN1> in1Type,
TypeInformation<IN2> in2Type,
String functionName,
boolean allowMissing)
Returns the binary operator's return type.
|
static <IN1,IN2,OUT> |
getCoGroupReturnTypes(CoGroupFunction<IN1,IN2,OUT> coGroupInterface,
TypeInformation<IN1> in1Type,
TypeInformation<IN2> in2Type) |
static <IN1,IN2,OUT> |
getCoGroupReturnTypes(CoGroupFunction<IN1,IN2,OUT> coGroupInterface,
TypeInformation<IN1> in1Type,
TypeInformation<IN2> in2Type,
String functionName,
boolean allowMissing) |
static <IN1,IN2,OUT> |
getCrossReturnTypes(CrossFunction<IN1,IN2,OUT> crossInterface,
TypeInformation<IN1> in1Type,
TypeInformation<IN2> in2Type) |
static <IN1,IN2,OUT> |
getCrossReturnTypes(CrossFunction<IN1,IN2,OUT> crossInterface,
TypeInformation<IN1> in1Type,
TypeInformation<IN2> in2Type,
String functionName,
boolean allowMissing) |
static Field |
getDeclaredField(Class<?> clazz,
String name) |
static <IN1,IN2,OUT> |
getFlatJoinReturnTypes(FlatJoinFunction<IN1,IN2,OUT> joinInterface,
TypeInformation<IN1> in1Type,
TypeInformation<IN2> in2Type) |
static <IN1,IN2,OUT> |
getFlatJoinReturnTypes(FlatJoinFunction<IN1,IN2,OUT> joinInterface,
TypeInformation<IN1> in1Type,
TypeInformation<IN2> in2Type,
String functionName,
boolean allowMissing) |
static <IN,OUT> TypeInformation<OUT> |
getFlatMapReturnTypes(FlatMapFunction<IN,OUT> flatMapInterface,
TypeInformation<IN> inType) |
static <IN,OUT> TypeInformation<OUT> |
getFlatMapReturnTypes(FlatMapFunction<IN,OUT> flatMapInterface,
TypeInformation<IN> inType,
String functionName,
boolean allowMissing) |
static <X> TypeInformation<X> |
getForClass(Class<X> clazz)
Creates type information from a given Class such as Integer, String[] or POJOs.
|
static <X> TypeInformation<X> |
getForObject(X value) |
static <IN,OUT> TypeInformation<OUT> |
getGroupCombineReturnTypes(GroupCombineFunction<IN,OUT> combineInterface,
TypeInformation<IN> inType) |
static <IN,OUT> TypeInformation<OUT> |
getGroupCombineReturnTypes(GroupCombineFunction<IN,OUT> combineInterface,
TypeInformation<IN> inType,
String functionName,
boolean allowMissing) |
static <IN,OUT> TypeInformation<OUT> |
getGroupReduceReturnTypes(GroupReduceFunction<IN,OUT> groupReduceInterface,
TypeInformation<IN> inType) |
static <IN,OUT> TypeInformation<OUT> |
getGroupReduceReturnTypes(GroupReduceFunction<IN,OUT> groupReduceInterface,
TypeInformation<IN> inType,
String functionName,
boolean allowMissing) |
static <IN> TypeInformation<IN> |
getInputFormatTypes(InputFormat<IN,?> inputFormatInterface) |
static <IN1,IN2,OUT> |
getJoinReturnTypes(JoinFunction<IN1,IN2,OUT> joinInterface,
TypeInformation<IN1> in1Type,
TypeInformation<IN2> in2Type) |
static <IN1,IN2,OUT> |
getJoinReturnTypes(JoinFunction<IN1,IN2,OUT> joinInterface,
TypeInformation<IN1> in1Type,
TypeInformation<IN2> in2Type,
String functionName,
boolean allowMissing) |
static <IN,OUT> TypeInformation<OUT> |
getKeySelectorTypes(KeySelector<IN,OUT> selectorInterface,
TypeInformation<IN> inType) |
static <IN,OUT> TypeInformation<OUT> |
getKeySelectorTypes(KeySelector<IN,OUT> selectorInterface,
TypeInformation<IN> inType,
String functionName,
boolean allowMissing) |
static <IN,OUT> TypeInformation<OUT> |
getMapPartitionReturnTypes(MapPartitionFunction<IN,OUT> mapPartitionInterface,
TypeInformation<IN> inType) |
static <IN,OUT> TypeInformation<OUT> |
getMapPartitionReturnTypes(MapPartitionFunction<IN,OUT> mapPartitionInterface,
TypeInformation<IN> inType,
String functionName,
boolean allowMissing) |
static <IN,OUT> TypeInformation<OUT> |
getMapReturnTypes(MapFunction<IN,OUT> mapInterface,
TypeInformation<IN> inType) |
static <IN,OUT> TypeInformation<OUT> |
getMapReturnTypes(MapFunction<IN,OUT> mapInterface,
TypeInformation<IN> inType,
String functionName,
boolean allowMissing) |
static Type |
getParameterType(Class<?> baseClass,
Class<?> clazz,
int pos) |
static <T> TypeInformation<T> |
getPartitionerTypes(Partitioner<T> partitioner) |
static <T> TypeInformation<T> |
getPartitionerTypes(Partitioner<T> partitioner,
String functionName,
boolean allowMissing) |
static <OUT> TypeInfoFactory<OUT> |
getTypeInfoFactory(Field field)
Returns the type information factory for an annotated field.
|
static <OUT> TypeInfoFactory<OUT> |
getTypeInfoFactory(Type t)
Returns the type information factory for a type using the factory registry or annotations.
|
static <IN,OUT> TypeInformation<OUT> |
getUnaryOperatorReturnType(Function function,
Class<?> baseClass,
int inputTypeArgumentIndex,
int outputTypeArgumentIndex,
int[] lambdaOutputTypeArgumentIndices,
TypeInformation<IN> inType,
String functionName,
boolean allowMissing)
Returns the unary operator's return type.
|
@PublicEvolving public static <IN,OUT> TypeInformation<OUT> getMapReturnTypes(MapFunction<IN,OUT> mapInterface, TypeInformation<IN> inType)
@PublicEvolving public static <IN,OUT> TypeInformation<OUT> getMapReturnTypes(MapFunction<IN,OUT> mapInterface, TypeInformation<IN> inType, String functionName, boolean allowMissing)
@PublicEvolving public static <IN,OUT> TypeInformation<OUT> getFlatMapReturnTypes(FlatMapFunction<IN,OUT> flatMapInterface, TypeInformation<IN> inType)
@PublicEvolving public static <IN,OUT> TypeInformation<OUT> getFlatMapReturnTypes(FlatMapFunction<IN,OUT> flatMapInterface, TypeInformation<IN> inType, String functionName, boolean allowMissing)
@PublicEvolving public static <IN,ACC> TypeInformation<ACC> getAggregateFunctionAccumulatorType(AggregateFunction<IN,ACC,?> function, TypeInformation<IN> inType, String functionName, boolean allowMissing)
@PublicEvolving public static <IN,OUT> TypeInformation<OUT> getAggregateFunctionReturnType(AggregateFunction<IN,?,OUT> function, TypeInformation<IN> inType, String functionName, boolean allowMissing)
@PublicEvolving public static <IN,OUT> TypeInformation<OUT> getMapPartitionReturnTypes(MapPartitionFunction<IN,OUT> mapPartitionInterface, TypeInformation<IN> inType)
@PublicEvolving public static <IN,OUT> TypeInformation<OUT> getMapPartitionReturnTypes(MapPartitionFunction<IN,OUT> mapPartitionInterface, TypeInformation<IN> inType, String functionName, boolean allowMissing)
@PublicEvolving public static <IN,OUT> TypeInformation<OUT> getGroupReduceReturnTypes(GroupReduceFunction<IN,OUT> groupReduceInterface, TypeInformation<IN> inType)
@PublicEvolving public static <IN,OUT> TypeInformation<OUT> getGroupReduceReturnTypes(GroupReduceFunction<IN,OUT> groupReduceInterface, TypeInformation<IN> inType, String functionName, boolean allowMissing)
@PublicEvolving public static <IN,OUT> TypeInformation<OUT> getGroupCombineReturnTypes(GroupCombineFunction<IN,OUT> combineInterface, TypeInformation<IN> inType)
@PublicEvolving public static <IN,OUT> TypeInformation<OUT> getGroupCombineReturnTypes(GroupCombineFunction<IN,OUT> combineInterface, TypeInformation<IN> inType, String functionName, boolean allowMissing)
@PublicEvolving public static <IN1,IN2,OUT> TypeInformation<OUT> getFlatJoinReturnTypes(FlatJoinFunction<IN1,IN2,OUT> joinInterface, TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type)
@PublicEvolving public static <IN1,IN2,OUT> TypeInformation<OUT> getFlatJoinReturnTypes(FlatJoinFunction<IN1,IN2,OUT> joinInterface, TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type, String functionName, boolean allowMissing)
@PublicEvolving public static <IN1,IN2,OUT> TypeInformation<OUT> getJoinReturnTypes(JoinFunction<IN1,IN2,OUT> joinInterface, TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type)
@PublicEvolving public static <IN1,IN2,OUT> TypeInformation<OUT> getJoinReturnTypes(JoinFunction<IN1,IN2,OUT> joinInterface, TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type, String functionName, boolean allowMissing)
@PublicEvolving public static <IN1,IN2,OUT> TypeInformation<OUT> getCoGroupReturnTypes(CoGroupFunction<IN1,IN2,OUT> coGroupInterface, TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type)
@PublicEvolving public static <IN1,IN2,OUT> TypeInformation<OUT> getCoGroupReturnTypes(CoGroupFunction<IN1,IN2,OUT> coGroupInterface, TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type, String functionName, boolean allowMissing)
@PublicEvolving public static <IN1,IN2,OUT> TypeInformation<OUT> getCrossReturnTypes(CrossFunction<IN1,IN2,OUT> crossInterface, TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type)
@PublicEvolving public static <IN1,IN2,OUT> TypeInformation<OUT> getCrossReturnTypes(CrossFunction<IN1,IN2,OUT> crossInterface, TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type, String functionName, boolean allowMissing)
@PublicEvolving public static <IN,OUT> TypeInformation<OUT> getKeySelectorTypes(KeySelector<IN,OUT> selectorInterface, TypeInformation<IN> inType)
@PublicEvolving public static <IN,OUT> TypeInformation<OUT> getKeySelectorTypes(KeySelector<IN,OUT> selectorInterface, TypeInformation<IN> inType, String functionName, boolean allowMissing)
@PublicEvolving public static <T> TypeInformation<T> getPartitionerTypes(Partitioner<T> partitioner)
@PublicEvolving public static <T> TypeInformation<T> getPartitionerTypes(Partitioner<T> partitioner, String functionName, boolean allowMissing)
@PublicEvolving public static <IN> TypeInformation<IN> getInputFormatTypes(InputFormat<IN,?> inputFormatInterface)
@PublicEvolving public static <IN,OUT> TypeInformation<OUT> getUnaryOperatorReturnType(Function function, Class<?> baseClass, int inputTypeArgumentIndex, int outputTypeArgumentIndex, int[] lambdaOutputTypeArgumentIndices, TypeInformation<IN> inType, String functionName, boolean allowMissing)
This method can extract a type in 4 different ways:
1. By using the generics of the base class like MyFunction 2. By using input type inference SubMyFunction 3. By using the static method that a compiler generates for Java lambdas. This is what
lambdaOutputTypeArgumentIndices is good for. Given that MyFunction has the following single
abstract method:
Lambda type indices allow the extraction of a type from lambdas. To extract the output
type OUT from the function one should pass 4. By using interfaces such as See also comments in the header of this class.
void apply(IN value, Collector
new int[] {1, 0}
. "1" for selecting
the parameter and 0 for the first generic in this type. Use TypeExtractor.NO_INDEX
for selecting the return type of the lambda for extraction or if the class cannot be a lambda
because it is not a single abstract method interface.
TypeInfoFactory
or ResultTypeQueryable
.
IN
- Input typeOUT
- Output typefunction
- Function to extract the return type frombaseClass
- Base class of the functioninputTypeArgumentIndex
- Index of input generic type in the base class specification
(ignored if inType is null)outputTypeArgumentIndex
- Index of output generic type in the base class specificationlambdaOutputTypeArgumentIndices
- Table of indices of the type argument specifying the
input type. See example.inType
- Type of the input elements (In case of an iterable, it is the element type) or
nullfunctionName
- Function nameallowMissing
- Can the type information be missing (this generates a MissingTypeInfo for
postponing an exception)@PublicEvolving public static <IN1,IN2,OUT> TypeInformation<OUT> getBinaryOperatorReturnType(Function function, Class<?> baseClass, int input1TypeArgumentIndex, int input2TypeArgumentIndex, int outputTypeArgumentIndex, int[] lambdaOutputTypeArgumentIndices, TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type, String functionName, boolean allowMissing)
This method can extract a type in 4 different ways:
1. By using the generics of the base class like MyFunction 2. By using input type inference SubMyFunction 3. By using the static method that a compiler generates for Java lambdas. This is what
lambdaOutputTypeArgumentIndices is good for. Given that MyFunction has the following single
abstract method:
Lambda type indices allow the extraction of a type from lambdas. To extract the output
type OUT from the function one should pass 4. By using interfaces such as See also comments in the header of this class.
void apply(IN value, Collector
new int[] {1, 0}
. "1" for selecting
the parameter and 0 for the first generic in this type. Use TypeExtractor.NO_INDEX
for selecting the return type of the lambda for extraction or if the class cannot be a lambda
because it is not a single abstract method interface.
TypeInfoFactory
or ResultTypeQueryable
.
IN1
- Left side input typeIN2
- Right side input typeOUT
- Output typefunction
- Function to extract the return type frombaseClass
- Base class of the functioninput1TypeArgumentIndex
- Index of first input generic type in the class specification
(ignored if in1Type is null)input2TypeArgumentIndex
- Index of second input generic type in the class specification
(ignored if in2Type is null)outputTypeArgumentIndex
- Index of output generic type in the class specificationlambdaOutputTypeArgumentIndices
- Table of indices of the type argument specifying the
output type. See example.in1Type
- Type of the left side input elements (In case of an iterable, it is the
element type)in2Type
- Type of the right side input elements (In case of an iterable, it is the
element type)functionName
- Function nameallowMissing
- Can the type information be missing (this generates a MissingTypeInfo for
postponing an exception)public static <T> TypeInformation<T> createTypeInfo(Class<T> type)
public static TypeInformation<?> createTypeInfo(Type t)
@PublicEvolving public static <OUT> TypeInformation<OUT> createTypeInfo(Object instance, Class<?> baseClass, Class<?> clazz, int returnParamPos)
TypeInformation
from the given parameters.
If the given instance
implements ResultTypeQueryable
, its information is
used to determine the type information. Otherwise, the type information is derived based on
the given class information.
OUT
- output typeinstance
- instance to determine type information forbaseClass
- base class of instance
clazz
- class of instance
returnParamPos
- index of the return type in the type arguments of clazz
@PublicEvolving public static <IN1,IN2,OUT> TypeInformation<OUT> createTypeInfo(Class<?> baseClass, Class<?> clazz, int returnParamPos, TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type)
@PublicEvolving public static Type getParameterType(Class<?> baseClass, Class<?> clazz, int pos)
@Internal public static <OUT> TypeInfoFactory<OUT> getTypeInfoFactory(Type t)
@Internal public static <OUT> TypeInfoFactory<OUT> getTypeInfoFactory(Field field)
public static <X> TypeInformation<X> getForClass(Class<X> clazz)
This method does not support ParameterizedTypes such as Tuples or complex type
hierarchies. In most cases createTypeInfo(Type)
is the recommended
method for type extraction (a Class is a child of Type).
clazz
- a Class to create TypeInformation forprotected <OUT,IN1,IN2> TypeInformation<OUT> analyzePojo(Type type, List<Type> typeHierarchy, TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type)
@PublicEvolving public static List<Field> getAllDeclaredFields(Class<?> clazz, boolean ignoreDuplicates)
clazz
- class to be analyzedignoreDuplicates
- if true, in case of duplicate field names only the lowest one in a
hierarchy will be returned; throws an exception otherwise@PublicEvolving public static Field getDeclaredField(Class<?> clazz, String name)
public static <X> TypeInformation<X> getForObject(X value)
public static <T> TypeInformation<T> createHadoopWritableTypeInfo(Class<T> clazz)
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.