Apache Druid supports two query languages: Druid SQL and native queries. This document describes the SQL language.
Operators in Druid SQL typically operate on one or two values and return a result based on the values. Types of operators in Druid SQL include arithmetic, comparison, logical, and more, as described here.
When performing math operations, Druid uses 64-bit integer (long) data type unless there are double or float values. If an operation uses float or double values, then the result is a double, which is a 64-bit float. The precision of float and double values is defined by Java and the IEEE standard.
Keep the following guidelines in mind to help you manage precision issues:
- Long values can store up to 2^63 accurately with an additional bit used for the sign.
- Float values use 32 bits, and doubles use 64 bits. Both types are impacted by floating point precision. If you need exact decimal values, consider storing the number in a non-decimal format as a long value (up to the limit for longs). For example, if you need three decimal places, store the number multiplied by 1000 and then divide by 1000 when querying.
Datetime arithmetic operators
For the datetime arithmetic operators,
interval_expr can include interval literals like
INTERVAL '2' HOUR.
This operator treats days as uniformly 86400 seconds long, and does not take into account daylight savings time.
To account for daylight savings time, use the
TIMESTAMPADD for datetime arithmetic.
|Add an amount of time to a timestamp.|
|Subtract an amount of time from a timestamp.|
Also see the CONCAT function.
|Concatenate strings |
|Equal to, considering |
|Not equal to|
|Not equal to, considering |
|Greater than or equal to|
|Less than or equal to|
|True if x is NULL or empty string|
|True if x is neither NULL nor empty string|
|True if x is true|
|True if x is not true|
|True if x is false|
|True if x is not false|
|Equivalent to |
|Equivalent to |
|True if x matches a SQL LIKE pattern (with an optional escape)|
|True if x does not match a SQL LIKE pattern (with an optional escape)|
|True if x is one of the listed values|
|True if x is not one of the listed values|
|True if x is returned by the subquery. This will be translated into a join; see Query translation for details.|
|True if x is not returned by the subquery. This will be translated into a join; see Query translation for details.|