Schema Evolution
So far, you've seen how to create a new schema for a Pinot table. In this tutorial, we'll see how to evolve the schema (e.g. add a new column to the schema). This guide assumes you have a Pinot cluster up and running (eg: as mentioned in https://docs.pinot.apache.org/basics/getting-started/running-pinot-locally). We will also assume there's an existing table baseballStats created as part of the batch quick start.
Get the existing schema
Let's begin by first fetching the existing schema. We can do this using the controller API:
$ curl localhost:9000/schemas/baseballStats > baseballStats.schemaAdd a new column
Let's add a new column at the end of the schema, something like this (by editing baseballStats.schema
{
"schemaName" : "baseballStats",
"dimensionFieldSpecs" : [ {
...
}, {
"name" : "myNewColumn",
"dataType" : "INT",
"defaultNullValue": 1
} ]
}In this example, we're adding a new column called yearsOfExperience with a default value of 1.
Update the schema
You can now update the schema using the following command
Please note: this will not be reflected immediately. You can use the following command to reload the table segments for this column to show up. This can be done as follows:
This will trigger a reload operation on each of the servers hosting the table's segemnts. The API response has a reloadJobId which can be used to monitor the status of the reload operation using the segment reload status API.
After the reload, now you can query the new column as shown below:
Derived Column
New columns can be added with ingestion transforms. If all the source columns for the new column exist in the schema, the transformed values will be generated for the new column instead of filling default values. Note that derived column as well as corresponding data type needs to be first defined in the schema before making changes in table config for ingestion transform.
Backfilling the Data
As you can observe, the current query returns the defaultNullValue for the newly added column. In order to populate this column with real values, you will need to re-run the batch ingestion job for the past dates.
Last updated
Was this helpful?

