Search in sources :

Example 1 with TypeInfo

use of org.apache.flink.api.common.typeinfo.TypeInfo in project flink by apache.

the class TypeExtractor method getTypeInfoFactory.

// --------------------------------------------------------------------------------------------
//  Utility methods
// --------------------------------------------------------------------------------------------
/**
	 * Returns the type information factory for a type using the factory registry or annotations.
	 */
@Internal
public static <OUT> TypeInfoFactory<OUT> getTypeInfoFactory(Type t) {
    final Class<?> factoryClass;
    if (registeredTypeInfoFactories.containsKey(t)) {
        factoryClass = registeredTypeInfoFactories.get(t);
    } else {
        if (!isClassType(t) || !typeToClass(t).isAnnotationPresent(TypeInfo.class)) {
            return null;
        }
        final TypeInfo typeInfoAnnotation = typeToClass(t).getAnnotation(TypeInfo.class);
        factoryClass = typeInfoAnnotation.value();
        // check for valid factory class
        if (!TypeInfoFactory.class.isAssignableFrom(factoryClass)) {
            throw new InvalidTypesException("TypeInfo annotation does not specify a valid TypeInfoFactory.");
        }
    }
    // instantiate
    return (TypeInfoFactory<OUT>) InstantiationUtil.instantiate(factoryClass);
}
Also used : InvalidTypesException(org.apache.flink.api.common.functions.InvalidTypesException) BasicArrayTypeInfo(org.apache.flink.api.common.typeinfo.BasicArrayTypeInfo) BasicTypeInfo(org.apache.flink.api.common.typeinfo.BasicTypeInfo) SqlTimeTypeInfo(org.apache.flink.api.common.typeinfo.SqlTimeTypeInfo) PrimitiveArrayTypeInfo(org.apache.flink.api.common.typeinfo.PrimitiveArrayTypeInfo) TypeInfo(org.apache.flink.api.common.typeinfo.TypeInfo) TypeInfoFactory(org.apache.flink.api.common.typeinfo.TypeInfoFactory) Internal(org.apache.flink.annotation.Internal)

Aggregations

Internal (org.apache.flink.annotation.Internal)1 InvalidTypesException (org.apache.flink.api.common.functions.InvalidTypesException)1 BasicArrayTypeInfo (org.apache.flink.api.common.typeinfo.BasicArrayTypeInfo)1 BasicTypeInfo (org.apache.flink.api.common.typeinfo.BasicTypeInfo)1 PrimitiveArrayTypeInfo (org.apache.flink.api.common.typeinfo.PrimitiveArrayTypeInfo)1 SqlTimeTypeInfo (org.apache.flink.api.common.typeinfo.SqlTimeTypeInfo)1 TypeInfo (org.apache.flink.api.common.typeinfo.TypeInfo)1 TypeInfoFactory (org.apache.flink.api.common.typeinfo.TypeInfoFactory)1