Controlling AVRO record names and namespaces
This page a tutorial to control AVRO record names and namespaces with Lenses SQL Processors.
When writing output as AVRO
, Lenses creates schemas for you, automatically generating AVRO
record names.
In this tutorial we will learn how to override the default record naming strategy.
In Lenses SQL you can use a SET
statement to control the record and namespace name generated for the AVRO schema.
Setting up our input topic
We are going to create and populate a topic that we will later use in a couple of SQL Processors.
In SQL Studio, create the topic running the following query:
For the purposes of our tutorial, it is enough to insert a single topic:
Create a simple SQL Processor
We are now going to create a processor that will show the default behavior of AVRO
record naming in Lenses.
The processor does not do much, it just reshapes the fields of the original topic, putting some of them in a nested field:
We then start the processor. Lenses will create the new topic mytopic_2
, and new schema will be created in the Schema Registry, as soon as the first (and only) record is processed.
If we inspect the value schema of mytopic_2
, we see that this is the one generated:
As we can see, each record
type has a name (it is mandatory in AVRO
), and Lenses has generated those names automatically for us (record
, record0
, record1
etc.).
Set the record name and the namespace of the value schema
We are now going to see how to override that default behavior.
Let’s create and start the new processor with the following SQL:
Notice how we added the new SET
statements to the query:
These settings are telling Lenses to set the root record name and namespace to the values specified.
If we now check the value schema for mytopic_3
we get:
As we can see, the root record
element has now name myRecordName
and namespace myNamespace
.
Notice how the settings did not affect nested records.
Set the record name and the namespace of the key schema
If the key of the generated topic has AVRO
format as well, you can use the following analogous settings to control the key record name and namespace:
More control on the topic affected by the setting
A setting like the one we used before for the value schema:
will affect all the topics used by the processor.
If you want instead to target a single topic, you can use the topic-specific version:
The setting above will override the record name only for topic mytopic_3
. Other topics will not be affected and will keep using the default naming strategy.
Last updated