Tutorial on how to change the format of data in a Kafka topic from JSON to AVRO with Lenses SQL Processors.
In this example, we will show how to create an AVRO topic from an existing JSON topic.
For this to work, Lenses has to know what the source topic schema is. Lenses can do this in one of three ways:
through direct user action where the schema is manually set
through inference; Lenses will try to infer the schema of a topic by looking at the topic data
and lastly, if the topic is created through Lenses, the schema will be automatically set
With the following SQL we can create our intial JSON topic:
to which we can add data using:
It can be quickly verified that the format of our newly created topic is JSON for both key and value by searching our topic car_speed_events_json
in our explore view:
To create a new topic with format AVRO, we can create a processor that will copy the data from our original topic to a new topic changing the format in the process.
To do this, we start by going to “SQL Processor”, clicking: “New SQL Processor” and defining our processor with the following code:
Notice the addition of STORE KEY AS AVRO VALULE AS AVRO
. This statement will tell our processor which format we want each facet (key or value) to be stored as.
Hitting “Create New Processor” will start a new processor
We can see the events were added and from now on, Lenses will keep pushing any new events added to car_speed_events_avro
into car_speed_events_avro
.
We can also verify that the topic format of our new topic is also AVRO for both the key and value facets: