Skip to main content
Version: 0.0.1

Submit an SQL Query

This API submits an SQL query.

Syntax

{{< codeheader "Method and URL" >}}

POST /api/v3/sql

Request Input

{{< codeheader "Request input" >}}

{
"sql": String,
"context": [String] [optional]
}
ParameterDescription
sqlRepresents the SQL query you want to run.
context(Optional) Path for the query to run in.

Response Output

Returns a Jobs ID for the query. Monitoring of the job status and fetching results needs to be completed using the Jobs endpoint.

{{< codeheader "Response output" >}}

{
"id": String
}

Example: Query the dataset and receive a Job ID

Querying a dataset (with SQL) and returning the query status and results is a two-part process that involves both the SQL API and the Job API.

  1. You submit your SQL query with the SQL API and receive a Job ID for the query.
  2. You then submit the Job ID with the Job API to get the query status and/or results.

In this example, a weapons_laws dataset was created in the SFIncidents space from the provided SF_Incidents2016.json Sample. Only Weapons Laws incidents are in the dataset.

For this example, the following equivalent Dremio UI query on the weapons_laws dataset is used:

{{< codeheader "Example dataset query" >}}

SELECT * FROM weapons_laws WHERE PdDistrict = 'CENTRAL' LIMIT 3

Note:
Postman was used to generate samples.

HTTP request

{{< codeheader "HTTP request example" >}}

POST localhost:9047/apiv3/sql

Body Raw Input: {{< codeheader "HTTP request example raw input" >}}

{
"sql": "SELECT * FROM SFIncidents.weapons_laws WHERE PdDistrict = 'CENTRAL' LIMIT 3"
}

Curl

{{< codeheader "curl request example" >}}

curl -X POST \
http://localhost:9047/api/v3/sql \
-H 'Authorization: _dremioicmqi0aoro8o0el8rj0jfjh6n0' \
-H 'Content-Type: application/json' \
-d '{
"sql": "SELECT * FROM SFIncidents.weapons_laws WHERE PdDistrict = '\''CENTRAL'\'' LIMIT 3"
}'

Python

{{< codeheader "Python request example" >}}

import requests

url = "http://localhost:9047/api/v3/sql"

payload = "{\n\t\"sql\": \"SELECT * FROM SFIncidents.weapons_laws WHERE PdDistrict = 'CENTRAL' LIMIT 3\"\n}"
headers = {
'Authorization': "_dremioicmqi0aoro8o0el8rj0jfjh6n0",
'Content-Type': "application/json"
}

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)

Response

The request example, returns a Job ID. This ID is used with JOB API to retrieve the query status and results.

{{< codeheader "Example response" >}}

{
"id": "23a4bf43-52aa-5d29-c473-0083c44fe700"
}

Example: Using the Job API

The following requests use the Job API and the returned Job ID, 23a4bf43-52aa-5d29-c473-0083c44fe700, to retrieve the query status and results. See the Job API GET /job/{id} for detailed request inputs and response outputs.

HTTP request for status

{{< codeheader "HTTP request for job status" >}}

GET localhost:9047/api/v3/job/23a4bf43-52aa-5d29-c473-0083c44fe700

HTTP request for results

{{< codeheader "HTTP request for job results" >}}

GET localhost:9047/api/v3/job/23a4bf43-52aa-5d29-c473-0083c44fe700/results