Raw

Updated at:

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.

Note

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

ParameterRequiredDefault valueData typeDescription
formatYesNoneSTRINGThe format to use. Set to raw.
raw.charsetNoUTF-8STRINGThe character set for encoding text strings.
raw.endiannessNobig-endianSTRINGThe byte order for numeric values. Valid values: big-endian, little-endian.

Data type mappings

Flink SQL data typeDescription
CHAR, VARCHAR, STRINGUTF-8 encoded text string (default). The encoding can be configured by raw.charset.
BINARY, VARBINARY, BYTESSequence of bytes.
BOOLEANSingle byte.
TINYINTSingle byte of a signed numeric value.
SMALLINTTwo bytes in big-endian encoding (default). The byte order can be configured by raw.endianness.
INTFour bytes in big-endian encoding (default). The byte order can be configured by raw.endianness.
BIGINTEight bytes in big-endian encoding (default). The byte order can be configured by raw.endianness.
FLOATFour bytes in big-endian encoding and IEEE 754 format (default). The byte order can be configured by raw.endianness.
DOUBLEEight bytes in big-endian encoding and IEEE 754 format (default). The byte order can be configured by raw.endianness.
RAWSequence of bytes serialized by the underlying TypeSerializer of the RAW data type.