The Apache Avro format reads and writes Avro-encoded data. The Avro schema is automatically derived from the Flink table schema—you do not define an Avro schema file separately. Avro is a serialization schema (for sinks) and a deserialization schema (for sources).Documentation Index
Fetch the complete documentation index at: https://mintlify.com/apache/flink/llms.txt
Use this file to discover all available pages before exploring further.
Dependency
Usage with Kafka
Usage with Filesystem
Format options
| Option | Required | Default | Description |
|---|---|---|---|
format | Yes | — | Must be 'avro'. |
avro.encoding | No | binary | Serialization encoding. binary produces compact messages; json produces human-readable messages. |
avro.codec | No | (none) | Compression codec. Only applies to the Filesystem connector. Valid values: null, deflate, snappy, bzip2, xz. |
avro.timestamp_mapping.legacy | No | true | Use legacy timestamp mapping. Before Flink 1.19, both TIMESTAMP and TIMESTAMP_LTZ were incorrectly mapped to Avro TIMESTAMP. Set to false for correct behavior: TIMESTAMP → Avro LOCAL TIMESTAMP, TIMESTAMP_LTZ → Avro TIMESTAMP. |
If you are upgrading from Flink 1.18 or earlier and your data contains timestamps, set
avro.timestamp_mapping.legacy = 'false' to use correct timezone-aware mappings. Changing this option on existing data may require a schema migration.Data type mapping
The Avro schema is always derived from the Flink table schema. The following table shows the mapping:| Flink SQL type | Avro type | Avro logical type |
|---|---|---|
CHAR / VARCHAR / STRING | string | — |
BOOLEAN | boolean | — |
BINARY / VARBINARY | bytes | — |
DECIMAL | fixed | decimal |
TINYINT | int | — |
SMALLINT | int | — |
INT | int | — |
BIGINT | long | — |
FLOAT | float | — |
DOUBLE | double | — |
DATE | int | date |
TIME | int | time-millis |
TIMESTAMP | long | timestamp-millis (legacy) or local-timestamp-millis |
TIMESTAMP_LTZ | long | local-timestamp-millis (legacy) or timestamp-millis |
ARRAY | array | — |
MAP (string keys) | map | — |
MULTISET (string elements) | map | — |
ROW | record | — |
union(T, null) where T is the non-nullable Avro equivalent.
Writing Avro with the DataStream API
To write Avro files from a DataStream job, useAvroWriters with FileSink:
AvroBuilder:

