Skip to main content
In this recipe we’ll learn how to query a table to find out which records are in a particular segment.

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, and Zookeeper. You can find the docker-compose.yml file on GitHub.

Data generator

This recipe contains a data generator that creates events with a timestamp, count, and UUID. You can generate data by running the following command:
Output is shown below:

Kafka ingestion

We’re going to ingest this data into an Apache Kafka topic using the kcat command line tool. We’ll also use jq to structure the data in the key:payload structure that Kafka expects:
We can check that Kafka has some data by running the following command:
We’ll see something like the following:

Pinot Schema and Table

Now let’s create a Pinot Schema and Table. First, the schema:
Now for the table config:
This highlighted section indicates that we’re going to create new segments after every 100,000 rows. We’ll create the table by running the following:

Querying by segment

Once that’s been created, we can head over to the Pinot UI and run some queries. Pinot has several built-in virtual columns inside every schema that can be used for debugging purposes: The one that’s useful for us is $segmentName, which we can use like this to count the number of records in each segment:
Query Results We can then pick one of those segments and see what records are stored in that segment:
Query Results