@PublicEvolving public class Types extends Object
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
and org.apache.flink.table.api.Types
)
A more convenient alternative might be a TypeHint
.
Modifier and Type | Field and Description |
---|---|
static TypeInformation<BigDecimal> |
BIG_DEC
Returns type information for
BigDecimal . |
static TypeInformation<BigInteger> |
BIG_INT
Returns type information for
BigInteger . |
static TypeInformation<Boolean> |
BOOLEAN
Returns type information for both a primitive
boolean and Boolean . |
static TypeInformation<Byte> |
BYTE
Returns type information for both a primitive
byte and Byte . |
static TypeInformation<Character> |
CHAR
Returns type information for both a primitive
char and Character . |
static TypeInformation<Double> |
DOUBLE
Returns type information for both a primitive
double and Double . |
static TypeInformation<Float> |
FLOAT
Returns type information for both a primitive
float and Float . |
static TypeInformation<Instant> |
INSTANT
Returns type information for
Instant . |
static TypeInformation<Integer> |
INT
Returns type information for both a primitive
int and Integer . |
static TypeInformation<LocalDate> |
LOCAL_DATE
Returns type information for
LocalDate . |
static TypeInformation<LocalDateTime> |
LOCAL_DATE_TIME
Returns type information for
LocalDateTime . |
static TypeInformation<LocalTime> |
LOCAL_TIME
Returns type information for
LocalTime . |
static TypeInformation<Long> |
LONG
Returns type information for both a primitive
long and Long . |
static TypeInformation<Short> |
SHORT
Returns type information for both a primitive
short and Short . |
static TypeInformation<Date> |
SQL_DATE
Returns type information for
Date . |
static TypeInformation<Time> |
SQL_TIME
Returns type information for
Time . |
static TypeInformation<Timestamp> |
SQL_TIMESTAMP
Returns type information for
Timestamp . |
static TypeInformation<String> |
STRING
Returns type information for
String . |
static TypeInformation<Void> |
VOID
Returns type information for
Void . |
Constructor and Description |
---|
Types() |
Modifier and Type | Method and Description |
---|---|
static <L,R> TypeInformation<Either<L,R>> |
EITHER(TypeInformation<L> leftType,
TypeInformation<R> rightType)
Returns type information for Flink's
Either type. |
static <E extends Enum<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 Java
List . |
static <K,V> TypeInformation<Map<K,V>> |
MAP(TypeInformation<K> keyType,
TypeInformation<V> valueType)
Returns type information for a Java
Map . |
static <E> TypeInformation<E[]> |
OBJECT_ARRAY(TypeInformation<E> elementType)
Returns type information for Java arrays of object types (such as
String[] ,
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 as
byte[] ). |
static TypeInformation<Row> |
ROW_NAMED(String[] fieldNames,
TypeInformation<?>... types)
Returns type information for
Row with fields of the given
types and with given names. |
static TypeInformation<Row> |
ROW(TypeInformation<?>... types)
Returns type information for
Row with fields of the given
types. |
static <T extends Tuple> |
TUPLE(Class<T> tupleSubclass)
Returns type information for typed subclasses of Flink's
Tuple . |
static <T extends Tuple> |
TUPLE(TypeInformation<?>... types)
|
static <V extends Value> |
VALUE(Class<V> valueType)
Returns type information for Flink value types (classes that implement
Value ). |
public static final TypeInformation<Void> VOID
Void
. Does not support a null value.public static final TypeInformation<String> STRING
String
. Supports a null value.public static final TypeInformation<Byte> BYTE
byte
and Byte
.
Does not support a null value.public static final TypeInformation<Boolean> BOOLEAN
boolean
and Boolean
. Does not support a null value.public static final TypeInformation<Short> SHORT
short
and Short
.
Does not support a null value.public static final TypeInformation<Integer> INT
int
and Integer
.
Does not support a null value.public static final TypeInformation<Long> LONG
long
and Long
.
Does not support a null value.public static final TypeInformation<Float> FLOAT
float
and Float
.
Does not support a null value.public static final TypeInformation<Double> DOUBLE
double
and Double
. Does not support a null value.public static final TypeInformation<Character> CHAR
char
and Character
. Does not support a null value.public static final TypeInformation<BigDecimal> BIG_DEC
BigDecimal
. Supports a null value.public static final TypeInformation<BigInteger> BIG_INT
BigInteger
. Supports a null value.public static final TypeInformation<Date> SQL_DATE
Date
. Supports a null value.public static final TypeInformation<Time> SQL_TIME
Time
. Supports a null value.public static final TypeInformation<Timestamp> SQL_TIMESTAMP
Timestamp
. Supports a null value.public static final TypeInformation<LocalDate> LOCAL_DATE
LocalDate
. Supports a null value.public static final TypeInformation<LocalTime> LOCAL_TIME
LocalTime
. Supports a null value.public static final TypeInformation<LocalDateTime> LOCAL_DATE_TIME
LocalDateTime
. Supports a null value.public static final TypeInformation<Instant> INSTANT
Instant
. Supports a null value.public static TypeInformation<Row> ROW(TypeInformation<?>... types)
Row
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 ..).
types
- The types of the row fields, e.g., Types.STRING, Types.INTpublic static TypeInformation<Row> ROW_NAMED(String[] fieldNames, TypeInformation<?>... types)
Row
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)
.
fieldNames
- array of field namestypes
- array of field typespublic static <T extends Tuple> TypeInformation<T> TUPLE(TypeInformation<?>... types)
Tuple
(namely Tuple0
till Tuple25
) 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.
types
- The types of the tuple fields, e.g., Types.STRING, Types.INTpublic static <T extends Tuple> TypeInformation<T> TUPLE(Class<T> tupleSubclass)
Tuple
. Typed subclassed are classes that extend Tuple0
till Tuple25
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)
public static <T> TypeInformation<T> POJO(Class<T> pojoClass)
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 use POJO(Class, Map)
to specify all fields manually.
pojoClass
- POJO class to be analyzed by Flinkpublic static <T> TypeInformation<T> POJO(Class<T> pojoClass, Map<String,TypeInformation<?>> fields)
A type is considered a FLink POJO type, if it fulfills the conditions below.
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)
.
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.public static <T> TypeInformation<T> GENERIC(Class<T> genericClass)
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).
genericClass
- any Java classpublic static TypeInformation<?> PRIMITIVE_ARRAY(TypeInformation<?> elementType)
byte[]
). The
array must not be null.elementType
- element type of the array (e.g. Types.BOOLEAN, Types.INT, Types.DOUBLE)public static <E> TypeInformation<E[]> OBJECT_ARRAY(TypeInformation<E> elementType)
String[]
,
Integer[]
). The array itself must not be null. Null values for elements are
supported.elementType
- element type of the arraypublic static <V extends Value> TypeInformation<V> VALUE(Class<V> valueType)
Value
). Built-in value types do not support null values (except for
StringValue
).
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 as
StringValue
, NullValue
, ListValue
, and MapValue
.
valueType
- class that implements Value
public static <K,V> TypeInformation<Map<K,V>> MAP(TypeInformation<K> keyType, TypeInformation<V> valueType)
Map
. 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 into HashMap
when copying or deserializing.
keyType
- type information for the map's keysvalueType
- type information for the map's valuespublic static <E> TypeInformation<List<E>> LIST(TypeInformation<E> elementType)
List
. 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 into ArrayList
when copying or deserializing.
elementType
- type information for the list's elementspublic static <E extends Enum<E>> TypeInformation<E> ENUM(Class<E> enumType)
enumType
- enumeration class extending Enum
public static <L,R> TypeInformation<Either<L,R>> EITHER(TypeInformation<L> leftType, TypeInformation<R> rightType)
Either
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)
leftType
- type information of left side / Either.Left
rightType
- type information of right side / Either.Right
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.