Schema Evolution
Schema evolution occurs over time. As business requirements evolve, and data formats or structures need to change, use Pinot to keep your schemas up-to-date. If you're just starting out with schemas in Pinot, see how to create a new schema for a Pinot table.
In this tutorial, you'll learn how to add a new column to your schema, load data to the updated schema, run a query to test the updated schema, and backfill data.
Prerequisites
Before you get started, you must have a Pinot cluster up and running, and a baseballStats table (created when you set up a Pinot cluster using the Quickstart option). For more information, see how to start running Pinot and set up a cluster using the Quickstart option.
Add a new column to your schema
Fetch the existing schema using the controller API:
$ curl localhost:9000/schemas/baseballStats > baseballStats.schemaEdit the
baseballStats.schemafile to include a new column at the end of the schema. For example, here we're adding a new column calledyearsOfExperiencewith adataTypeofINTanddefaultNullValueof1.
{
"schemaName" : "baseballStats",
"dimensionFieldSpecs" : [ {
...
}, {
"name" : "yearsOfExperience",
"dataType" : "INT",
"defaultNullValue": 1
} ]
}Update the schema using the following command:
Reload table segments
After you add the new column to your schema, reload the table segments so completed segments expose the new field and realtime consumers pick up the schema on a fresh consuming segment.
(Real-time tables) Keep
pinot.server.instance.reload.consumingSegmentat its defaulttrue(see Server config) so reload requests a force commit for consuming segments when consistency mode allows it. Servers then seal the current mutable segment asynchronously and start a new consumer with the latest schema/table config. You can also callPOST /tables/{tableName}/forceCommitexplicitly and poll it; see the force commit API.To ensure the new
baseballStatscolumn shows up on completed segments, reload the table — replace the samplereloadJobIdbelow with yours when polling status:
Command
Response
This triggers a reload operation on each of the servers hosting the table's segments. The API response has a reloadJobId that you can use to monitor the status of the reload operation using the segment reload status API.
Command
Response
Query and backfill data
After reloading the segments, run the the following to query the new column:
Command
Response
As you can see, the query returns the
defaultNullValuefor the newly added column. To populate this column with real values, re-run the batch ingestion job for the past datesBackfill data.
Backfilling data does not work for real-time tables. You can convert a real-time table to a hybrid table by adding an offline table that uses the same counterpart, and then backfilling the offline table to fill in values for the newly added column. For more information, see hybrid tables.
Last updated
Was this helpful?

