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.Typesandorg.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_DECReturns type information forBigDecimal.static TypeInformation<BigInteger>BIG_INTReturns type information forBigInteger.static TypeInformation<Boolean>BOOLEANReturns type information for both a primitivebooleanandBoolean.static TypeInformation<Byte>BYTEReturns type information for both a primitivebyteandByte.static TypeInformation<Character>CHARReturns type information for both a primitivecharandCharacter.static TypeInformation<Double>DOUBLEReturns type information for both a primitivedoubleandDouble.static TypeInformation<Float>FLOATReturns type information for both a primitivefloatandFloat.static TypeInformation<java.time.Instant>INSTANTReturns type information forInstant.static TypeInformation<Integer>INTReturns type information for both a primitiveintandInteger.static TypeInformation<java.time.LocalDate>LOCAL_DATEReturns type information forLocalDate.static TypeInformation<java.time.LocalDateTime>LOCAL_DATE_TIMEReturns type information forLocalDateTime.static TypeInformation<java.time.LocalTime>LOCAL_TIMEReturns type information forLocalTime.static TypeInformation<Long>LONGReturns type information for both a primitivelongandLong.static TypeInformation<Short>SHORTReturns type information for both a primitiveshortandShort.static TypeInformation<Date>SQL_DATEReturns type information forDate.static TypeInformation<Time>SQL_TIMEReturns type information forTime.static TypeInformation<Timestamp>SQL_TIMESTAMPReturns type information forTimestamp.static TypeInformation<String>STRINGReturns type information forString.static TypeInformation<Void>VOIDReturns 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'sEithertype.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 forRowwith fields of the given types.static TypeInformation<Row>ROW_NAMED(String[] fieldNames, TypeInformation<?>... types)Returns type information forRowwith 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 primitivebyteandByte. Does not support a null value.
-
BOOLEAN
public static final TypeInformation<Boolean> BOOLEAN
Returns type information for both a primitivebooleanandBoolean. Does not support a null value.
-
SHORT
public static final TypeInformation<Short> SHORT
Returns type information for both a primitiveshortandShort. Does not support a null value.
-
INT
public static final TypeInformation<Integer> INT
Returns type information for both a primitiveintandInteger. Does not support a null value.
-
LONG
public static final TypeInformation<Long> LONG
Returns type information for both a primitivelongandLong. Does not support a null value.
-
FLOAT
public static final TypeInformation<Float> FLOAT
Returns type information for both a primitivefloatandFloat. Does not support a null value.
-
DOUBLE
public static final TypeInformation<Double> DOUBLE
Returns type information for both a primitivedoubleandDouble. Does not support a null value.
-
CHAR
public static final TypeInformation<Character> CHAR
Returns type information for both a primitivecharandCharacter. 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<java.time.LocalDate> LOCAL_DATE
Returns type information forLocalDate. Supports a null value.
-
LOCAL_TIME
public static final TypeInformation<java.time.LocalTime> LOCAL_TIME
Returns type information forLocalTime. Supports a null value.
-
LOCAL_DATE_TIME
public static final TypeInformation<java.time.LocalDateTime> LOCAL_DATE_TIME
Returns type information forLocalDateTime. Supports a null value.
-
INSTANT
public static final TypeInformation<java.time.Instant> INSTANT
Returns type information forInstant. Supports a null value.
-
-
Method Detail
-
ROW
public static TypeInformation<Row> ROW(TypeInformation<?>... types)
Returns type information forRowwith 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_VALUEfields, 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 forRowwith 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_VALUEfields, 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(namelyTuple0tillTuple25) 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 extendTuple0tillTuple25to 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
InvalidTypesExceptionis 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.
If Flink's type analyzer is unable to extract a valid POJO type information with type information for all fields, an
InvalidTypesExceptionis 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
InvalidTypesExceptionis 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
Maptype. It converts a map intoHashMapwhen 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
Listtype. It converts a list intoArrayListwhen 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'sEithertype. 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.LeftrightType- type information of right side /Either.Right
-
-