In Apache Flink’s Python DataStream API, a data type describes the type of a value in the DataStream ecosystem. It can be used to declare input and output types of operations and informs the system how to serailize elements.
If the type has not been declared, data would be serialized or deserialized using Pickle. For example, the program below specifies no data types.
However, types need to be specified when:
Since Java operators or functions can not identify Python data, types need to be provided to help to convert Python types to Java types for processing. For example, types need to be provided if you want to output data using the StreamingFileSink which is implemented in Java.
Even though data can be serialized and deserialized through Pickle, performance will be better if types are provided. Explicit types allow PyFlink to use efficient serializers when moving records through the pipeline.
You can use pyflink.common.typeinfo.Types
to specify types in Python DataStream API.
The table below shows the type supported now and how to define them:
PyFlink Type | Usage | Corresponding Python Type |
---|---|---|
BOOLEAN |
Types.BOOLEAN() |
bool |
SHORT |
Types.SHORT() |
int |
INT |
Types.INT() |
int |
LONG |
Types.LONG() |
int |
FLOAT |
Types.FLOAT() |
float |
DOUBLE |
Types.DOUBLE() |
float |
CHAR |
Types.CHAR() |
str |
BIG_INT |
Types.BIG_INT() |
bytes |
BIG_DEC |
Types.BIG_DEC() |
decimal.Decimal |
STRING |
Types.STRING() |
str |
BYTE |
Types.BYTE() |
int |
TUPLE |
Types.TUPLE() |
tuple |
PRIMITIVE_ARRAY |
Types.PRIMITIVE_ARRAY() |
list |
ROW |
Types.ROW() |
dict |