Data Serialization

Changing Data Serialization Format from Avro to CSV

KSQL provides a powerful way for developers to reserialize the data in a Kafka topic by defining new streams with the desired serialization of the new topic, populated by the streaming events of the original topic. Here, we convert a stream of Avro-formatted data into CSV.

The fantastic thing here is that these are streaming transformations, so not only does all existing data on the topic get converted, but so do every single message that subsequently arrives on the source topic.

Directions

1. Define the source topic’s schema:

CREATE STREAM source_avro \
WITH (KAFKA_TOPIC='mysql_users_avro', VALUE_FORMAT='AVRO');

2. Create a derived topic in delimited (CSV) format:

CREATE STREAM target_delim WITH (KAFKA_TOPIC='mysql_users_delim',VALUE_FORMAT='DELIMITED') AS \
SELECT * FROM source_avro;
You will get the resulting data:
$ kafkacat -C -b localhost:9092 -t mysql_users_delim
1,Cliff,en_US,St Louis,P
< Back to the Stream Processing Cookbook

Nous utilisons des cookies afin de comprendre comment vous utilisez notre site et améliorer votre expérience. Cliquez ici pour en apprendre davantage ou pour modifier vos paramètres de cookies. En poursuivant la navigation, vous consentez à ce que nous utilisions des cookies.