Class TypeInformation<T>
- Type Parameters:
T- The type represented by this type information.
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
SqlTimeTypeInfo
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:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract booleanReturns true if the given object can be equaled with this object.abstract org.apache.flink.api.common.typeutils.TypeSerializer<T>createSerializer(org.apache.flink.api.common.serialization.SerializerConfig config) Creates a serializer for the type.abstract booleanabstract intgetArity()Gets the arity of this type - the number of fields without nesting.Map<String,TypeInformation<?>> 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.abstract intGets the number of logical fields in this type.Gets the class of the type represented by this type information.abstract inthashCode()abstract booleanChecks if this type information represents a basic type.abstract booleanChecks whether this type can be used as a key.booleanChecks whether this type can be used as a key for sorting.abstract booleanChecks if this type information represents a Tuple type.static <T> TypeInformation<T>Creates a TypeInformation for the type described by the given class.static <T> TypeInformation<T>of(org.apache.flink.api.common.typeinfo.TypeHint<T> typeHint) Creates a TypeInformation for a generic type via a utility "type hint".abstract StringtoString()
-
Constructor Details
-
TypeInformation
public TypeInformation()
-
-
Method Details
-
isBasicType
Checks if this type information represents a basic type. Basic types are defined inBasicTypeInfoand are primitives, their boxing types, Strings, Date, Void, ...- Returns:
- True, if this type information describes a basic type, false otherwise.
-
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
Gets the arity of this type - the number of fields without nesting.- Returns:
- Gets the number of fields in this type without nesting.
-
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
Gets the class of the type represented by this type information.- Returns:
- The class of the type represented by this type information.
-
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
Tuple2would 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
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
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 org.apache.flink.api.common.typeutils.TypeSerializer<T> createSerializer(org.apache.flink.api.common.serialization.SerializerConfig 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.
-
toString
-
equals
-
hashCode
public abstract int hashCode() -
canEqual
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
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
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.
-