Skip to main content
To learn how to store Geospatial data in Apache Pinot, watch the following video, or complete the tutorial below.
To learn about geospatial indexing, see the Geospatial indexing developer guide.

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, Kafka, and Zookeeper. You can find the docker-compose.yml file on GitHub.

Generating Geospatial data

This recipe contains a data generator that produces JSON documents that contain various geospatial objects in Well-known text (WKT) format. You’ll need to first install the following dependencies:
Once that’s done you can run the data generator and grab just the first generated document, by running the following command:
Output is shown below:
You can see from this output that we have three geospatial objects - a polygon, a multi polygon, and a point. Pinot also supports line strings, multi points, multi line strings, and geometry collections. You can read more about this in the Geospatial documention.

Kafka ingestion

We’re going to ingest this data into an Apache Kafka topic using the kcat command line tool. We’ll also use jq to structure the data in the key:payload structure that Kafka expects:
We can check that Kafka has some data by running the following command:
We’ll see something like the following:

Pinot Schema and Table

Now let’s create a Pinot Schema and Table. First, the schema:
Note that the columns for polygon, multiPolygon, and point all have have a data type of BYTES. Geospatial columns must use the BYTES type because Pinot will serialize the Geospatial objects into bytes for storage purposes. Now for the table config:
The most important lines in this file are the highlighted transform config functions. The ST_GeomFromText function creates a geometry object from a WKT representation. We then use toSphericalGeography to convert the geometry object to a geography object. We do this conversion because some of the other spatial functions only work on geography objects. We’ll create the table by running the following:

Geospatial Querying

Once that’s been created, we can head over to the Pinot UI and run some queries. The following query returns three records where the point geometry object fits inside the polygon:
You will see something like the following output: Query Results We could also write another query to find the points that are within 500km of the centre of San Francisco:
You will see something like the following output: Query Results