Class Types
- java.lang.Object
-
- org.apache.flink.api.common.typeinfo.Types
-
@PublicEvolving public class Types extends Object
This class gives access to the type information of the most common types for which Flink has built-in serializers and comparators.In many cases, Flink tries to analyze generic signatures of functions to determine return types automatically. This class is intended for cases where type information has to be supplied manually or cases where automatic type inference results in an inefficient type.
Please note that the Scala API and Table API have dedicated Types classes. (See
org.apache.flink.api.scala.Types
andorg.apache.flink.table.api.Types
)A more convenient alternative might be a
TypeHint
.
-
-
Field Summary
Fields Modifier and Type Field Description static TypeInformation<BigDecimal>
BIG_DEC
Returns type information forBigDecimal
.static TypeInformation<BigInteger>
BIG_INT
Returns type information forBigInteger
.static TypeInformation<Boolean>
BOOLEAN
Returns type information for both a primitiveboolean
andBoolean
.static TypeInformation<Byte>
BYTE
Returns type information for both a primitivebyte
andByte
.static TypeInformation<Character>
CHAR
Returns type information for both a primitivechar
andCharacter
.static TypeInformation<Double>
DOUBLE
Returns type information for both a primitivedouble
andDouble
.static TypeInformation<Float>
FLOAT
Returns type information for both a primitivefloat
andFloat
.static TypeInformation<Instant>
INSTANT
Returns type information forInstant
.static TypeInformation<Integer>
INT
Returns type information for both a primitiveint
andInteger
.static TypeInformation<LocalDate>
LOCAL_DATE
Returns type information forLocalDate
.static TypeInformation<LocalDateTime>
LOCAL_DATE_TIME
Returns type information forLocalDateTime
.static TypeInformation<LocalTime>
LOCAL_TIME
Returns type information forLocalTime
.static TypeInformation<Long>
LONG
Returns type information for both a primitivelong
andLong
.static TypeInformation<Short>
SHORT
Returns type information for both a primitiveshort
andShort
.static TypeInformation<Date>
SQL_DATE
Returns type information forDate
.static TypeInformation<Time>
SQL_TIME
Returns type information forTime
.static TypeInformation<Timestamp>
SQL_TIMESTAMP
Returns type information forTimestamp
.static TypeInformation<String>
STRING
Returns type information forString
.static TypeInformation<Void>
VOID
Returns type information forVoid
.
-
Constructor Summary
Constructors Constructor Description Types()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <L,R>
TypeInformation<Either<L,R>>EITHER(TypeInformation<L> leftType, TypeInformation<R> rightType)
Returns type information for Flink'sEither
type.static <E extends Enum<E>>
TypeInformation<E>ENUM(Class<E> enumType)
Returns type information for Java enumerations.static <T> TypeInformation<T>
GENERIC(Class<T> genericClass)
Returns generic type information for any Java object.static <E> TypeInformation<List<E>>
LIST(TypeInformation<E> elementType)
Returns type information for a JavaList
.static <K,V>
TypeInformation<Map<K,V>>MAP(TypeInformation<K> keyType, TypeInformation<V> valueType)
Returns type information for a JavaMap
.static <E> TypeInformation<E[]>
OBJECT_ARRAY(TypeInformation<E> elementType)
Returns type information for Java arrays of object types (such asString[]
,Integer[]
).static <T> TypeInformation<T>
POJO(Class<T> pojoClass)
Returns type information for a POJO (Plain Old Java Object).static <T> TypeInformation<T>
POJO(Class<T> pojoClass, Map<String,TypeInformation<?>> fields)
Returns type information for a POJO (Plain Old Java Object) and allows to specify all fields manually.static TypeInformation<?>
PRIMITIVE_ARRAY(TypeInformation<?> elementType)
Returns type information for Java arrays of primitive type (such asbyte[]
).static TypeInformation<Row>
ROW(TypeInformation<?>... types)
Returns type information forRow
with fields of the given types.static TypeInformation<Row>
ROW_NAMED(String[] fieldNames, TypeInformation<?>... types)
Returns type information forRow
with fields of the given types and with given names.static <T extends Tuple>
TypeInformation<T>TUPLE(Class<T> tupleSubclass)
Returns type information for typed subclasses of Flink'sTuple
.static <T extends Tuple>
TypeInformation<T>TUPLE(TypeInformation<?>... types)
static <V extends Value>
TypeInformation<V>VALUE(Class<V> valueType)
Returns type information for Flink value types (classes that implementValue
).
-
-
-
Field Detail
-
VOID
public static final TypeInformation<Void> VOID
Returns type information forVoid
. Does not support a null value.
-
STRING
public static final TypeInformation<String> STRING
Returns type information forString
. Supports a null value.
-
BYTE
public static final TypeInformation<Byte> BYTE
Returns type information for both a primitivebyte
andByte
. Does not support a null value.
-
BOOLEAN
public static final TypeInformation<Boolean> BOOLEAN
Returns type information for both a primitiveboolean
andBoolean
. Does not support a null value.
-
SHORT
public static final TypeInformation<Short> SHORT
Returns type information for both a primitiveshort
andShort
. Does not support a null value.
-
INT
public static final TypeInformation<Integer> INT
Returns type information for both a primitiveint
andInteger
. Does not support a null value.
-
LONG
public static final TypeInformation<Long> LONG
Returns type information for both a primitivelong
andLong
. Does not support a null value.
-
FLOAT
public static final TypeInformation<Float> FLOAT
Returns type information for both a primitivefloat
andFloat
. Does not support a null value.
-
DOUBLE
public static final TypeInformation<Double> DOUBLE
Returns type information for both a primitivedouble
andDouble
. Does not support a null value.
-
CHAR
public static final TypeInformation<Character> CHAR
Returns type information for both a primitivechar
andCharacter
. Does not support a null value.
-
BIG_DEC
public static final TypeInformation<BigDecimal> BIG_DEC
Returns type information forBigDecimal
. Supports a null value.
-
BIG_INT
public static final TypeInformation<BigInteger> BIG_INT
Returns type information forBigInteger
. Supports a null value.
-
SQL_DATE
public static final TypeInformation<Date> SQL_DATE
Returns type information forDate
. Supports a null value.
-
SQL_TIME
public static final TypeInformation<Time> SQL_TIME
Returns type information forTime
. Supports a null value.
-
SQL_TIMESTAMP
public static final TypeInformation<Timestamp> SQL_TIMESTAMP
Returns type information forTimestamp
. Supports a null value.
-
LOCAL_DATE
public static final TypeInformation<LocalDate> LOCAL_DATE
Returns type information forLocalDate
. Supports a null value.
-
LOCAL_TIME
public static final TypeInformation<LocalTime> LOCAL_TIME
Returns type information forLocalTime
. Supports a null value.
-
LOCAL_DATE_TIME
public static final TypeInformation<LocalDateTime> LOCAL_DATE_TIME
Returns type information forLocalDateTime
. Supports a null value.
-
INSTANT
public static final TypeInformation<Instant> INSTANT
Returns type information forInstant
. Supports a null value.
-
-
Method Detail
-
ROW
public static TypeInformation<Row> ROW(TypeInformation<?>... types)
Returns type information forRow
with fields of the given types. A row itself must not be null.A row is a fixed-length, null-aware composite type for storing multiple values in a deterministic field order. Every field can be null regardless of the field's type. The type of row fields cannot be automatically inferred; therefore, it is required to provide type information whenever a row is produced.
The schema of rows can have up to
Integer.MAX_VALUE
fields, however, all row instances must strictly adhere to the schema defined by the type info.This method generates type information with fields of the given types; the fields have the default names (f0, f1, f2 ..).
- Parameters:
types
- The types of the row fields, e.g., Types.STRING, Types.INT
-
ROW_NAMED
public static TypeInformation<Row> ROW_NAMED(String[] fieldNames, TypeInformation<?>... types)
Returns type information forRow
with fields of the given types and with given names. A row must not be null.A row is a fixed-length, null-aware composite type for storing multiple values in a deterministic field order. Every field can be null independent of the field's type. The type of row fields cannot be automatically inferred; therefore, it is required to provide type information whenever a row is used.
The schema of rows can have up to
Integer.MAX_VALUE
fields, however, all row instances must strictly adhere to the schema defined by the type info.Example use:
ROW_NAMED(new String[]{"name", "number"}, Types.STRING, Types.INT)
.- Parameters:
fieldNames
- array of field namestypes
- array of field types
-
TUPLE
public static <T extends Tuple> TypeInformation<T> TUPLE(TypeInformation<?>... types)
Returns type information for subclasses of Flink'sTuple
(namelyTuple0
tillTuple25
) with fields of the given types. A tuple must not be null.A tuple is a fixed-length composite type for storing multiple values in a deterministic field order. Fields of a tuple are typed. Tuples are the most efficient composite type; a tuple does not support null-valued fields unless the type of the field supports nullability.
- Parameters:
types
- The types of the tuple fields, e.g., Types.STRING, Types.INT
-
TUPLE
public static <T extends Tuple> TypeInformation<T> TUPLE(Class<T> tupleSubclass)
Returns type information for typed subclasses of Flink'sTuple
. Typed subclassed are classes that extendTuple0
tillTuple25
to provide types for all fields and might add additional getters and setters for better readability. Additional member fields must not be added. A tuple must not be null.A tuple is a fixed-length composite type for storing multiple values in a deterministic field order. Fields of a tuple are typed. Tuples are the most efficient composite type; a tuple does not support null-valued fields unless the type of the field supports nullability.
The generic types for all fields of the tuple can be defined in a hierarchy of subclasses.
If Flink's type analyzer is unable to extract a tuple type information with type information for all fields, an
InvalidTypesException
is thrown.Example use:
class MyTuple extends Tuple2<Integer, String> { public int getId() { return f0; } public String getName() { return f1; } }
Types.TUPLE(MyTuple.class)
-
POJO
public static <T> TypeInformation<T> POJO(Class<T> pojoClass)
Returns type information for a POJO (Plain Old Java Object).A POJO class is public and standalone (no non-static inner class). It has a public no-argument constructor. All non-static, non-transient fields in the class (and all superclasses) are either public (and non-final) or have a public getter and a setter method that follows the Java beans naming conventions for getters and setters.
A POJO is a fixed-length and null-aware composite type. Every field can be null independent of the field's type.
The generic types for all fields of the POJO can be defined in a hierarchy of subclasses.
Java Record classes can also be used as valid POJOs (even though they don't fulfill some of the above criteria). In this case Flink will use the record canonical constructor to create the objects.
If Flink's type analyzer is unable to extract a valid POJO type information with type information for all fields, an
InvalidTypesException
is thrown. Alternatively, you can usePOJO(Class, Map)
to specify all fields manually.- Parameters:
pojoClass
- POJO class to be analyzed by Flink
-
POJO
public static <T> TypeInformation<T> POJO(Class<T> pojoClass, Map<String,TypeInformation<?>> fields)
Returns type information for a POJO (Plain Old Java Object) and allows to specify all fields manually.A type is considered a FLink POJO type, if it fulfills the conditions below.
- It is a public class, and standalone (not a non-static inner class)
- It has a public no-argument constructor.
- All non-static, non-transient fields in the class (and all superclasses) are either public (and non-final) or have a public getter and a setter method that follows the Java beans naming conventions for getters and setters.
- It is a fixed-length, null-aware composite type with non-deterministic field order. Every field can be null independent of the field's type.
The generic types for all fields of the POJO can be defined in a hierarchy of subclasses.
If Flink's type analyzer is unable to extract a POJO field, an
InvalidTypesException
is thrown.Note: In most cases the type information of fields can be determined automatically, we recommend to use
POJO(Class)
.- Parameters:
pojoClass
- POJO classfields
- map of fields that map a name to type information. The map key is the name of the field and the value is its type.
-
GENERIC
public static <T> TypeInformation<T> GENERIC(Class<T> genericClass)
Returns generic type information for any Java object. The serialization logic will use the general purpose serializer Kryo.Generic types are black-boxes for Flink, but allow any object and null values in fields.
By default, serialization of this type is not very efficient. Please read the documentation about how to improve efficiency (namely by pre-registering classes).
- Parameters:
genericClass
- any Java class
-
PRIMITIVE_ARRAY
public static TypeInformation<?> PRIMITIVE_ARRAY(TypeInformation<?> elementType)
Returns type information for Java arrays of primitive type (such asbyte[]
). The array must not be null.- Parameters:
elementType
- element type of the array (e.g. Types.BOOLEAN, Types.INT, Types.DOUBLE)
-
OBJECT_ARRAY
public static <E> TypeInformation<E[]> OBJECT_ARRAY(TypeInformation<E> elementType)
Returns type information for Java arrays of object types (such asString[]
,Integer[]
). The array itself must not be null. Null values for elements are supported.- Parameters:
elementType
- element type of the array
-
VALUE
public static <V extends Value> TypeInformation<V> VALUE(Class<V> valueType)
Returns type information for Flink value types (classes that implementValue
). Built-in value types do not support null values (except forStringValue
).Value types describe their serialization and deserialization manually. Instead of going through a general purpose serialization framework. A value type is reasonable when general purpose serialization would be highly inefficient. The wrapped value can be altered, allowing programmers to reuse objects and take pressure off the garbage collector.
Flink provides built-in value types for all Java primitive types (such as
BooleanValue
,IntValue
) as well asStringValue
,NullValue
,ListValue
, andMapValue
.- Parameters:
valueType
- class that implementsValue
-
MAP
public static <K,V> TypeInformation<Map<K,V>> MAP(TypeInformation<K> keyType, TypeInformation<V> valueType)
Returns type information for a JavaMap
. A map must not be null. Null values in keys are not supported. An entry's value can be null.By default, maps are untyped and treated as a generic type in Flink; therefore, it is useful to pass type information whenever a map is used.
Note: Flink does not preserve the concrete
Map
type. It converts a map intoHashMap
when copying or deserializing.- Parameters:
keyType
- type information for the map's keysvalueType
- type information for the map's values
-
LIST
public static <E> TypeInformation<List<E>> LIST(TypeInformation<E> elementType)
Returns type information for a JavaList
. A list must not be null. Null values in elements are not supported.By default, lists are untyped and treated as a generic type in Flink; therefore, it is useful to pass type information whenever a list is used.
Note: Flink does not preserve the concrete
List
type. It converts a list intoArrayList
when copying or deserializing.- Parameters:
elementType
- type information for the list's elements
-
ENUM
public static <E extends Enum<E>> TypeInformation<E> ENUM(Class<E> enumType)
Returns type information for Java enumerations. Null values are not supported.- Parameters:
enumType
- enumeration class extendingEnum
-
EITHER
public static <L,R> TypeInformation<Either<L,R>> EITHER(TypeInformation<L> leftType, TypeInformation<R> rightType)
Returns type information for Flink'sEither
type. Null values are not supported.Either type can be used for a value of two possible types.
Example use:
Types.EITHER(Types.VOID, Types.INT)
- Parameters:
leftType
- type information of left side /Either.Left
rightType
- type information of right side /Either.Right
-
-