T
- The type represented by this type information.@Public public abstract class TypeInformation<T> extends Object implements Serializable
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.
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).
Constructor and Description |
---|
TypeInformation() |
Modifier and Type | Method and Description |
---|---|
abstract boolean |
canEqual(Object obj)
Returns true if the given object can be equaled with this object.
|
abstract TypeSerializer<T> |
createSerializer(ExecutionConfig config)
Creates a serializer for the type.
|
abstract boolean |
equals(Object obj) |
abstract int |
getArity()
Gets the arity of this type - the number of fields without nesting.
|
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.
|
abstract int |
getTotalFields()
Gets the number of logical fields in this type.
|
abstract Class<T> |
getTypeClass()
Gets the class of the type represented by this type information.
|
abstract int |
hashCode() |
abstract boolean |
isBasicType()
Checks if this type information represents a basic type.
|
abstract boolean |
isKeyType()
Checks whether this type can be used as a key.
|
boolean |
isSortKeyType()
Checks whether this type can be used as a key for sorting.
|
abstract boolean |
isTupleType()
Checks if this type information represents a Tuple type.
|
static <T> TypeInformation<T> |
of(Class<T> typeClass)
Creates a TypeInformation for the type described by the given class.
|
static <T> TypeInformation<T> |
of(TypeHint<T> typeHint)
Creates a TypeInformation for a generic type via a utility "type hint".
|
abstract String |
toString() |
@PublicEvolving public abstract boolean isBasicType()
BasicTypeInfo
and are primitives, their boxing types, Strings, Date, Void, ...@PublicEvolving public abstract boolean isTupleType()
@PublicEvolving public abstract int getArity()
@PublicEvolving public abstract int getTotalFields()
The total number of fields must be at least 1.
@PublicEvolving public abstract Class<T> getTypeClass()
@PublicEvolving public Map<String,TypeInformation<?>> getGenericParameters()
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;
@PublicEvolving public abstract boolean isKeyType()
@PublicEvolving public boolean isSortKeyType()
@PublicEvolving public abstract TypeSerializer<T> createSerializer(ExecutionConfig config)
config
- The config used to parameterize the serializer.public abstract boolean canEqual(Object obj)
obj
- Object which wants to take part in the equality relationpublic static <T> TypeInformation<T> of(Class<T> typeClass)
This method only works for non-generic types. For generic types, use the of(TypeHint)
method.
T
- The generic type.typeClass
- The class of the type.public static <T> TypeInformation<T> of(TypeHint<T> typeHint)
TypeInformation<Tuple2<String, Long>> info = TypeInformation.of(new TypeHint<Tuple2<String, Long>>(){});
T
- The generic type.typeHint
- The hint for the generic type.Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.