Skip to main content
In this recipe we’ll learn how to ingest Avro messages from Apache Kafka into Apache Pinot. The Avro schema will be stored in the Confluent Schema Registry, so we’ll learn how to integrate with that as well. Watch the following video about ingesting Avro encoded messages into Apache Pinot, or follow the tutorial below.

Prerequisites

To follow the code examples in this guide, you must install Docker locally and download recipes.
  1. If you haven’t already, download recipes.
  2. In terminal, go to the recipe by running the following command:

Launch Pinot Cluster

You can spin up a Pinot Cluster by running the following command:
This command will run a single instance of the Pinot Controller, Pinot Server, Pinot Broker, Kafka, Zookeeper, and the Confluent Schema Registry. You can find the docker-compose.yml file on GitHub.

Data Generator

This recipe contains a data generator that creates events with data about people. It uses the Faker library, so you’ll first need to install that:
You can generate data by running the following command:
Output is shown below:

Avro Schema

The Avro schema for our messages is described below:
avro/person-topic-value.avsc

Kafka ingestion

We’re going to ingest the stream of people into Kafka using the Kafka Python client. We’ll need to install the following libraries:
We’re going to stream the messages produced by datagen.py into the following script:
kafkaproducer.py This script first creates a Kafka producer that knows about the Avro schema and schema registry. It then infinitely ingests an infinite stream from stdin and writes Avro messages to Kafka. We can combine the data generator script with this one by running the following code:
Once we’ve done that, let’s check the messages are being ingested into the person-topic using kcat:
The output is shown below:
Next, we’re going to ingest the stream into Pinot.

Pinot schema and table

Our Pinot schema is shown below:
schema.json And the table config is below:
table.json The highlighted section defines a decoder for processing Avro messages via the schema registry. The URL for the schema registry is defined along with the Avro schema name. We can create the table and schema by running the following command:

Querying Pinot

We can then run the following query via the Pinot UI:
The output will look something like this: Query Results