Raw
Format: Serialization Schema | Deserialization Schema
Raw format reads and writes byte-based raw values as a single column. It is built into Flink—no additional dependencies are required.
Supported connectors: Apache Kafka connector, Upsert Kafka connector, and Object Storage Service (OSS) connector.
Raw format encodes null values as null of the BYTE[] type. The Upsert Kafka connector treats null values as tombstone messages and deletes the key from Kafka. If a field can be null and you are using the Upsert Kafka connector, do not set value.format to raw.
Example
The following example reads Nginx log data from a Kafka topic in Raw format and processes it as UTF-8 encoded strings.
Sample log entry:
47.xx.xx.179 - - [28/Feb/2019:13:17:10 +0000] "GET /?p=1 HTTP/2.0" 200 5316 "https://domain.com/?p=1" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.xx.xx.119 Safari/537.36" "2.75"Create a table that reads from the nginx_log Kafka topic using Raw format:
CREATE TABLE nginx_log (
log STRING
) WITH (
'connector' = 'kafka',
'topic' = 'nginx_log',
'properties.bootstrap.servers' = 'localhost:9092',
'properties.group.id' = 'testGroup',
'format' = 'raw'
);After the table is created, use a user-defined function (UDF) such as my_split to parse each log entry into structured fields:
SELECT t.hostname, t.datetime, t.url, t.browser, ...
FROM (
SELECT my_split(log) as t FROM nginx_log
);You can also write a STRING column back to a Kafka topic as a UTF-8 encoded string using the same format configuration.
Parameters
| Parameter | Required | Default value | Data type | Description |
|---|---|---|---|---|
format | Yes | None | STRING | The format to use. Set to raw. |
raw.charset | No | UTF-8 | STRING | The character set for encoding text strings. |
raw.endianness | No | big-endian | STRING | The byte order for numeric values. Valid values: big-endian, little-endian. |
Data type mappings
| Flink SQL data type | Description |
|---|---|
| CHAR, VARCHAR, STRING | UTF-8 encoded text string (default). The encoding can be configured by raw.charset. |
| BINARY, VARBINARY, BYTES | Sequence of bytes. |
| BOOLEAN | Single byte. |
| TINYINT | Single byte of a signed numeric value. |
| SMALLINT | Two bytes in big-endian encoding (default). The byte order can be configured by raw.endianness. |
| INT | Four bytes in big-endian encoding (default). The byte order can be configured by raw.endianness. |
| BIGINT | Eight bytes in big-endian encoding (default). The byte order can be configured by raw.endianness. |
| FLOAT | Four bytes in big-endian encoding and IEEE 754 format (default). The byte order can be configured by raw.endianness. |
| DOUBLE | Eight bytes in big-endian encoding and IEEE 754 format (default). The byte order can be configured by raw.endianness. |
| RAW | Sequence of bytes serialized by the underlying TypeSerializer of the RAW data type. |