Querying Pinot using the REST API
You can query your Pinot data by sending a POST request to the Pinot broker’s /query/sql
endpoint. This endpoint accepts a JSON body containing your SQL query.
The basic structure of the request involves:
- Method: POST
- Endpoint:
/query/sql
- Request Body: A JSON object with a single key,
sql
, whose value is your SQL query string. - Headers: You will typically need to set the
Content-Type
header toapplication/json
. If you are using StarTree Cloud, you will also need anAuthorization
header with a Bearer token. StarTree Trial accounts require an additionaldatabase
header.
Prerequisites
-
Obtain a service token for authentication.
Examples
Here are some examples using the curl command-line tool:
Example 1: Querying StarTree Cloud
When querying a Pinot cluster hosted on StarTree Cloud, you need to include an API token for authentication.
Remember to replace <your url>
with your specific StarTree Cloud URL and <API Token>
with your generated token.
Example 2: Querying a local Pinot broker
If you have a Pinot broker running locally (for example, on localhost:8099), you can query it directly:
Replace yourTableName
with the actual name of your table.
Obtaining a Service Token
You can cenerate an API token in the Data Portal or using the REST API.
This token is used in the Authorization header of your API requests.
Finding Your Broker URL
To find the correct Broker URL for your table in StarTree Cloud:
- Access the Data Portal.
- Click on Tables.
- Select the specific table you want to query.
- The Broker URL for that table will be displayed, and you can copy it to your clipboard.