Apache Druid supports two query languages: Druid SQL and native queries. This document describes the SQL API.
Query from Historicals
Submit a query
Submits a SQL query in JSON or text format. Returns query results with optional metadata. Each query has an associated SQL query ID. You can set this manually using thesqlQueryId context parameter, or Druid will generate one automatically and return it in the X-Druid-SQL-Query-Id response header.
SQL query string. You can include multiple SET statements to assign SQL query context parameters.
Format for query results. Options:
object: JSON array of objectsarray: JSON array of arraysobjectLines: Newline-delimited JSON objectsarrayLines: Newline-delimited JSON arrayscsv: Comma-separated values
When true, returns column names as the first row of results.
Adds Druid runtime type information in the header. Requires
header to be true.Adds SQL type information in the header. Requires
header to be true.JSON object containing optional SQL query context parameters like query ID, time zone, and approximation settings.
List of query parameters for parameterized queries. Each parameter should be a JSON object with SQL data type and value.
Query results in the format specified by
resultFormat.Text Format Requests
You can also submit queries in plain text by settingContent-Type to text/plain:
Cancel a query
Cancels a query with the specifiedsqlQueryId. Druid handles cancellation in a best-effort manner.
The ID of the query to cancel.
Query from deep storage
Thesql/statements endpoint allows you to query segments that exist only in deep storage.
Submit a query
Submit a query for data stored in deep storage. At least part of a datasource must be available on a Historical process for Druid to plan your query.Determines how query results are fetched. Currently only supports
ASYNC.Where final results are written. Set to
durableStorage for large result sets (>3000 rows).Unique identifier for the submitted query.
Initial state of the query (typically “ACCEPTED”).
Array of column definitions with name, type, and nativeType.
Get query status
Retrieves the status of a query, including results information for completed queries.The query ID to check status for.
Include detailed information about stages, counters, and warnings.
Current query state: ACCEPTED, RUNNING, SUCCESS, or FAILED.
Summary of query results including row count, size, and sample records.
Information about each page of results including row count, size, and page ID.
Get query results
Retrieves results for completed queries. Results are separated into pages.The query ID to retrieve results for.
Specific page number to retrieve. If not specified, all results are returned.
Format for results:
arrayLines, objectLines, array, object, or csv.