Ingesting JSON files from Kafka
In this recipe, we’ll learn how to ingest JSON documents from Apache Kafka into Apache Pinot.
To learn how to ingest JSON files from Apache Kafka into Pinot, watch the following video, or complete the tutorial below.
Mark Needham shows how to ingest JSON files
If you have complex JSON documents with a nested structure, see how to ingest complex JSON documents with a nested structure from Kafka into Pinot.
Pinot Version | 0.10.0 |
---|---|
Code | startreedata/pinot-recipes/ingest-json-files-kafka |
Prerequisites
To follow the code examples in this guide, you must install Docker locally and download recipes.
Navigate to recipe
- If you haven’t already, download recipes.
- 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, Kafka, and Zookeeper. You can find the docker-compose.yml file on GitHub.
Dataset
We’re going to import the following JSON files:
data/import1.jsonl
data/import2.jsonl
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
We need to tell Pinot where our Kafka cluster lives as well as the topic that we wish to pull events from. Finally, we need to specify an offset value, which indicates where Pinot should start pulling data in each topic partition. A value of smallest
means it will start from the earliest offset.
A value of largest
means it will start from the latest offset.
You can create the table and schema by running the following command:`
Importing data
Now we’re going to import the JSON files into Kafka:
Querying
Once that’s completed, navigate to localhost:9000/#/query and click on the movies
table or copy/paste the following query:
You will see the following output:
boxOffice | budget | genre | releaseDate | title | year |
---|---|---|---|---|---|
216500000 | 52000000 | Comedy | 2010-02-12 00:00:00.0 | Valentine’s Day | 2010 |
205300000 | 38000000 | Comedy | 2010-04-14 00:00:00.0 | The Ugly Truth | 2009 |
156800000 | 30000000 | Romance | 2007-12-21 00:00:00.0 | P.S. I Love You | 2007 |
115000000 | 25000000 | Drama | 2010-04-14 00:00:00.0 | Dear John | 2010 |
335800000 | 167000000 | Fantasy | 2008-12-25 00:00:00.0 | The Curious Case of Benjamin Button | 2008 |
794881442 | 230000000 | Action | 2017-05-26 00:00:00.0 | Pirates of the Caribbean: Salazar’s Revenge | 2017 |
694394724 | 78000000 | Action | 2012-03-23 00:00:00.0 | The Hunger Games | 2012 |
121616555 | 28000000 | Romance | 2005-09-16 00:00:00.0 | Pride & Prejudice | 2005 |
Query Results