Skip to main content
In this recipe we’ll learn how to handle null or missing values in Apache Pinot tables.

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 the following JSON file:
data/import.json The Ugly Truth and Dear John are both missing a value for genre, which we’ll explore in this guide.

Pinot Schema and Table

Now let’s create a couple of Pinot Schemas and Table. We’re going to create one table where nulls are allowed and one where they aren’t. We need to create one schema per table even though they will be identical except for the name.
config/schema.json And the schema for the no-nulls table:
config/schema.json We’re also going to create two tables: one that allows null values and one that doesn’t. This table doesn’t handle null values:
config/table_no_nulls.json You can create the table by running the following command:`
And this table allows null values:
config/table_nulls.json The highlighted config is how we indicate that we want this table to have null values. You can create the table by running the following command:`

Ingestion Job

Now we’re going to import the JSON file into these tables. We’ll do this with the following ingestion spec:
config/job-spec.yml The import job will map fields in each JSON document to a corresponding column in the movies schema. You can run the following command to run the import on the movies_no_null table:
And the following to run the import on the movies_nuls table:

Querying

Once that’s completed, navigate to localhost:9000/#/query and run the following query to return the rows that have a genre and year in the movies_no_nulls table:
You will see the following output: Query Results We can see from the results that the null genres and null years haven’t been filtered out for the movies_no_nulls table. The genre and year columns in the movies_nulls table, on the other hand, supports null values, which we can see by running the following query:
You will see the following output: Query Results Pinot still stores the same default values for those columns, but when null handling is enabled the query engine filters them out of the result set when evaluating the IS NOT NULL clause.