Skip to main content
In this recipe we’ll learn how to import CSV files from different directories.

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 CSV files:

input/2000_2009/2000_2009.csv

input/2010_2019/2010_2019.csv

input/2020_present/2020_present.csv

Pinot Schema and Table

Now let’s create a Pinot Schema and Table. A common pattern when creating a schema is to create columns that map directly to the names of the fields in our data source. We can’t do that in this case since column names can’t contain spaces, so instead we’ll have the following:

config/schema.json

We’ll also have the following table config:

config/table.json*

You can create the table and schema by running the following command:
You should see a message similar to the following if everything is working correctly:

Ingestion Job

Now we’re going to import the CSV file into Pinot. We’ll do this with the following ingestion spec:

config/job-spec.yml

The part of this file that we’re most interested in is the following section:
This config makes sure that the segment id (that’s used in the segment name) is incremented globally across all directories, rather than being incremented on a directory by directory basis. If we don’t set this config, every segment that’s created from a CSV file will be replaced by the segment created from the next CSV file. We would end up with only one segment that contained the rows from the last CSV that got processed.
We only need to use this config when importing data for tables that don’t have a timestamp field. If a timestamp field is specified, timestamps are used in the segment name and the likelihood of segments being overridden is reduced.
You can run the following command to run the import:

Querying

Once that’s completed, navigate to localhost:9000/#/query and click on the crimes table or copy/paste the following query:
You will see the following output: Query Results