Class TypeInformation<T>

  • Type Parameters:
    T - The type represented by this type information.
    All Implemented Interfaces:
    Serializable
    Direct Known Subclasses:
    BasicArrayTypeInfo, BasicTypeInfo, CompositeType, EitherTypeInfo, EnumTypeInfo, GenericTypeInfo, ListTypeInfo, LocalTimeTypeInfo, MapTypeInfo, MissingTypeInfo, NothingTypeInfo, ObjectArrayTypeInfo, PrimitiveArrayTypeInfo, SqlTimeTypeInfo, ValueTypeInfo

    @Public
    public abstract class TypeInformation<T>
    extends Object
    implements Serializable
    TypeInformation is the core class of Flink's type system. Flink requires a type information for all types that are used as input or return type of a user function. This type information class acts as the tool to generate serializers and comparators, and to perform semantic checks such as whether the fields that are used as join/grouping keys actually exist.

    The type information also bridges between the programming languages object model and a logical flat schema. It maps fields from the types to columns (fields) in a flat schema. Not all fields from a type are mapped to a separate fields in the flat schema and often, entire types are mapped to one field. It is important to notice that the schema must hold for all instances of a type. For that reason, elements in lists and arrays are not assigned to individual fields, but the lists and arrays are considered to be one field in total, to account for different lengths in the arrays.

    • Basic types are indivisible and are considered a single field.
    • Arrays and collections are one field
    • Tuples and case classes represent as many fields as the class has fields

    To represent this properly, each type has an arity (the number of fields it contains directly), and a total number of fields (number of fields in the entire schema of this type, including nested types).

    Consider the example below:

    
     public class InnerType {
       public int id;
       public String text;
     }
    
     public class OuterType {
       public long timestamp;
       public InnerType nestedType;
     }
     

    The types "id", "text", and "timestamp" are basic types that take up one field. The "InnerType" has an arity of two, and also two fields totally. The "OuterType" has an arity of two fields, and a total number of three fields ( it contains "id", "text", and "timestamp" through recursive flattening).

    See Also:
    Serialized Form
    • Constructor Detail

      • TypeInformation

        public TypeInformation()
    • Method Detail

      • isBasicType

        @PublicEvolving
        public abstract boolean isBasicType()
        Checks if this type information represents a basic type. Basic types are defined in BasicTypeInfo and are primitives, their boxing types, Strings, Date, Void, ...
        Returns:
        True, if this type information describes a basic type, false otherwise.
      • isTupleType

        @PublicEvolving
        public abstract boolean isTupleType()
        Checks if this type information represents a Tuple type. Tuple types are subclasses of the Java API tuples.
        Returns:
        True, if this type information describes a tuple type, false otherwise.
      • getArity

        @PublicEvolving
        public abstract int getArity()
        Gets the arity of this type - the number of fields without nesting.
        Returns:
        Gets the number of fields in this type without nesting.
      • getTotalFields

        @PublicEvolving
        public abstract int getTotalFields()
        Gets the number of logical fields in this type. This includes its nested and transitively nested fields, in the case of composite types. In the example above, the OuterType type has three fields in total.

        The total number of fields must be at least 1.

        Returns:
        The number of fields in this type, including its sub-fields (for composite types)
      • getTypeClass

        @PublicEvolving
        public abstract Class<T> getTypeClass()
        Gets the class of the type represented by this type information.
        Returns:
        The class of the type represented by this type information.
      • getGenericParameters

        @PublicEvolving
        public Map<String,​TypeInformation<?>> getGenericParameters()
        Optional method for giving Flink's type extraction system information about the mapping of a generic type parameter to the type information of a subtype. This information is necessary in cases where type information should be deduced from an input type.

        For instance, a method for a Tuple2 would look like this: Map m = new HashMap(); m.put("T0", this.getTypeAt(0)); m.put("T1", this.getTypeAt(1)); return m;

        Returns:
        map of inferred subtypes; it does not have to contain all generic parameters as key; values may be null if type could not be inferred
      • isKeyType

        @PublicEvolving
        public abstract boolean isKeyType()
        Checks whether this type can be used as a key. As a bare minimum, types have to be hashable and comparable to be keys.
        Returns:
        True, if the type can be used as a key, false otherwise.
      • isSortKeyType

        @PublicEvolving
        public boolean isSortKeyType()
        Checks whether this type can be used as a key for sorting. The order produced by sorting this type must be meaningful.
      • createSerializer

        @PublicEvolving
        public abstract TypeSerializer<T> createSerializer​(ExecutionConfig config)
        Creates a serializer for the type. The serializer may use the ExecutionConfig for parameterization.
        Parameters:
        config - The config used to parameterize the serializer.
        Returns:
        A serializer for this type.
      • equals

        public abstract boolean equals​(Object obj)
        Overrides:
        equals in class Object
      • hashCode

        public abstract int hashCode()
        Overrides:
        hashCode in class Object
      • canEqual

        public abstract boolean canEqual​(Object obj)
        Returns true if the given object can be equaled with this object. If not, it returns false.
        Parameters:
        obj - Object which wants to take part in the equality relation
        Returns:
        true if obj can be equaled with this, otherwise false
      • of

        public static <T> TypeInformation<T> of​(Class<T> typeClass)
        Creates a TypeInformation for the type described by the given class.

        This method only works for non-generic types. For generic types, use the of(TypeHint) method.

        Type Parameters:
        T - The generic type.
        Parameters:
        typeClass - The class of the type.
        Returns:
        The TypeInformation object for the type described by the hint.
      • of

        public static <T> TypeInformation<T> of​(TypeHint<T> typeHint)
        Creates a TypeInformation for a generic type via a utility "type hint". This method can be used as follows:
        
         TypeInformation<Tuple2<String, Long>> info = TypeInformation.of(new TypeHint<Tuple2<String, Long>>(){});
         
        Type Parameters:
        T - The generic type.
        Parameters:
        typeHint - The hint for the generic type.
        Returns:
        The TypeInformation object for the type described by the hint.