Skip to main content
In this recipe we’ll learn how to merge small segments into larger ones. By doing this, Pinot can benefit from disk storage and query performance. This is done using the Minion merge rollup task.
You can only merge segments in offline tables that have a time column.
You can also merge segments in real-time tables. For more information see the merge segments in real-time tables guide

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

Dataset

We’re going to import a couple of CSVs that contain results from the Australian Open tennis tournament that was held in January 2022. The contents of the files are shown below:
input/matches0.csv
input/matches1.csv

Pinot Schema and Table

Now let’s create a Pinot Schema and Table. First, the schema:
config/schema.json We’ll also have the following table config:
config/table.json
Our table must specify segmentsConfig.timeColumnName, otherwise the merge process won’t merge any segments.
The main thing that we’re interested in is the MergeRollupTask, which is extracted below:
This configuration will bucket records from the same 1 day period into the same segment. It will only process records with a timestamp from more than 5 minutes ago. You can create the table and schema by running the following command:`
Remove the -arm64 suffix if you’re not using a Mac M1/M2.

Import Data

Now let’s import those CSV files into Pinot, using the following ingestion spec:
config/job-spec.yml You can run the following command to run the import:
Once this job has run, we can list the created segments by running the following command:
Output
Let’s wrap this command in a function so that we can use it again later:
We could then call the function like this:
We can check the contents of these segments by writing the following function:
We can call it like this:
Output

Merge segments

Now we’re going to merge these segments using the Minion merge rollup task. The configuration that we defined in the matches table is going to bucket records from a 1 day period into the same bucket. Since our events all happened on the same day, we would expect that all records will be merge into a single segment. We can run the merge rollup task by running the following:
Output
We can then check the Pinot Controller logs to see that it’s been triggered:
Output
And we can check the Pinot Minion logs to see if the job has run:
Output
Let’s now check the list of segments again:
Output
We can see the new segment, but the initial segments are still there as well. The Pinot broker knows to use the new segment when it processes queries, so this isn’t a problem. We can confirm this by running the following query on the Pinot UI:
Also, Pinot’s retention manager will take care of removing the old segments the next time that it runs. We’ll see the following messages in the Pinot Controller’s logs when the retention manager has run:
Output
We can then check the contents of that segment by running the following:
Output
We now have a single segment that contains all the records from the two CSV files that we ingested.

Automatic scheduling

We can also automatically schedule the merge task by adding the following configuration to the Pinot Controller:
Controller configuration