2018-12-13 14:47:20 -05:00
|
|
|
---
|
2019-08-21 00:48:59 -04:00
|
|
|
id: sql
|
2022-02-11 17:43:30 -05:00
|
|
|
title: "Druid SQL overview"
|
|
|
|
sidebar_label: "Druid SQL overview"
|
2018-12-13 14:47:20 -05:00
|
|
|
---
|
|
|
|
|
2018-11-13 12:38:37 -05:00
|
|
|
<!--
|
|
|
|
~ Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
~ or more contributor license agreements. See the NOTICE file
|
|
|
|
~ distributed with this work for additional information
|
|
|
|
~ regarding copyright ownership. The ASF licenses this file
|
|
|
|
~ to you under the Apache License, Version 2.0 (the
|
|
|
|
~ "License"); you may not use this file except in compliance
|
|
|
|
~ with the License. You may obtain a copy of the License at
|
|
|
|
~
|
|
|
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
~
|
|
|
|
~ Unless required by applicable law or agreed to in writing,
|
|
|
|
~ software distributed under the License is distributed on an
|
|
|
|
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
~ KIND, either express or implied. See the License for the
|
|
|
|
~ specific language governing permissions and limitations
|
|
|
|
~ under the License.
|
|
|
|
-->
|
|
|
|
|
2020-04-15 19:12:20 -04:00
|
|
|
> Apache Druid supports two query languages: Druid SQL and [native queries](querying.md).
|
|
|
|
> This document describes the SQL language.
|
2016-12-16 20:15:59 -05:00
|
|
|
|
2022-02-11 17:43:30 -05:00
|
|
|
You can query data in Druid datasources using Druid SQL.
|
|
|
|
Druid uses [Apache Calcite](https://calcite.apache.org/) to parse and plan SQL queries.
|
|
|
|
Druid translates SQL statements into its native JSON-based query language.
|
|
|
|
Other than the slight overhead of translating SQL on the Broker, there isn't an
|
|
|
|
additional performance penalty to using Druid SQL compared to native queries.
|
2020-04-15 19:12:20 -04:00
|
|
|
|
2022-02-11 17:43:30 -05:00
|
|
|
Druid SQL planning occurs on the Broker.
|
|
|
|
Set [Broker runtime properties](../configuration/index.md#sql) to configure the query plan and JDBC querying.
|
2020-04-15 19:12:20 -04:00
|
|
|
|
2022-02-11 17:43:30 -05:00
|
|
|
See [Defining SQL permissions](../operations/security-user-auth.md#sql-permissions)
|
|
|
|
for information on permissions needed to make SQL queries.
|
2017-07-07 11:48:26 -04:00
|
|
|
|
2022-02-11 17:43:30 -05:00
|
|
|
## Unsupported features
|
2020-04-15 19:12:20 -04:00
|
|
|
|
|
|
|
Druid does not support all SQL features. In particular, the following features are not supported.
|
|
|
|
|
2022-02-11 17:43:30 -05:00
|
|
|
- JOIN between native datasources (table, lookup, subquery) and [system tables](sql-metadata-tables.md).
|
2020-04-15 19:12:20 -04:00
|
|
|
- JOIN conditions that are not an equality between expressions from the left- and right-hand sides.
|
2020-06-03 15:55:52 -04:00
|
|
|
- JOIN conditions containing a constant value inside the condition.
|
|
|
|
- JOIN conditions on a column which contains a multi-value dimension.
|
2020-04-15 19:12:20 -04:00
|
|
|
- OVER clauses, and analytic functions such as `LAG` and `LEAD`.
|
2020-08-21 17:11:54 -04:00
|
|
|
- ORDER BY for a non-aggregating query, except for `ORDER BY __time` or `ORDER BY __time DESC`, which are supported.
|
|
|
|
This restriction only applies to non-aggregating queries; you can ORDER BY any column in an aggregating query.
|
2020-04-15 19:12:20 -04:00
|
|
|
- DDL and DML.
|
2022-02-11 17:43:30 -05:00
|
|
|
- Using Druid-specific functions like `TIME_PARSE` and `APPROX_QUANTILE_DS` on [system tables](sql-metadata-tables.md).
|
2020-04-15 19:12:20 -04:00
|
|
|
|
|
|
|
Additionally, some Druid native query features are not supported by the SQL language. Some unsupported Druid features
|
|
|
|
include:
|
|
|
|
|
2020-12-17 16:37:43 -05:00
|
|
|
- [Inline datasources](datasource.md#inline).
|
|
|
|
- [Spatial filters](../development/geo.md).
|
2022-02-11 17:43:30 -05:00
|
|
|
- [Multi-value dimensions](sql-data-types.md#multi-value-strings) are only partially implemented in Druid SQL. There are known
|
2020-08-25 13:11:16 -04:00
|
|
|
inconsistencies between their behavior in SQL queries and in native queries due to how they are currently treated by
|
|
|
|
the SQL planner.
|