SQL functions
This page lists the available Apache Druid ® SQL functions in alphabetical order. For more specific information, see the following pages:
- Overview and syntax
- Aggregation functions
- Financial functions
- JSON functions
- Multi-value string functions
- Operators
- Scalar functions
- Time series functions
- Window functions
Not all Druid SQL functions are available in Imply Polaris.
ABS
ABS(<NUMERIC>)
Calculates the absolute value of a numeric expression.
ACOS
ACOS(<NUMERIC>)
Calculates the arc cosine of a numeric expression.
ANY_VALUE
ANY_VALUE(expr, [maxBytesPerValue, [aggregateMultipleValues]])
Returns any value of the specified expression.
APPROX_COUNT_DISTINCT
APPROX_COUNT_DISTINCT(expr)
Counts distinct values of a regular column or a prebuilt sketch column.
APPROX_COUNT_DISTINCT_BUILTIN(expr)
Counts distinct values of a string, numeric, or hyperUnique
column using Druid's built-in cardinality
or hyperUnique
aggregators.
APPROX_COUNT_DISTINCT_DS_HLL
APPROX_COUNT_DISTINCT_DS_HLL(expr, [<NUMERIC>, <CHARACTER>])
Counts distinct values of an HLL sketch column or a regular column.
APPROX_COUNT_DISTINCT_DS_THETA
APPROX_COUNT_DISTINCT_DS_THETA(expr, [<NUMERIC>])
Counts distinct values of a Theta sketch column or a regular column.
APPROX_QUANTILE
APPROX_QUANTILE(expr, <NUMERIC>, [<NUMERIC>])
Deprecated in favor of APPROX_QUANTILE_DS
.
APPROX_QUANTILE_DS
APPROX_QUANTILE_DS(expr, <NUMERIC>, [<NUMERIC>])
Computes approximate quantiles on a Quantiles sketch column or a regular numeric column.
APPROX_QUANTILE_FIXED_BUCKETS
APPROX_QUANTILE_FIXED_BUCKETS(expr, <NUMERIC>, <NUMERIC>, <NUMERIC>, <NUMERIC>, [<CHARACTER>])
Computes approximate quantiles on fixed buckets histogram column or a regular numeric column.
ARRAY[]
ARRAY[expr1, expr2, ...]
Constructs a SQL ARRAY literal from the expression arguments. The arguments must be of the same type.
ARRAY_AGG
ARRAY_AGG([DISTINCT] expr, [<NUMERIC>])
Returns an array of all values of the specified expression.
ARRAY_APPEND
ARRAY_APPEND(arr1, expr)
Appends expr
to arr
, the resulting array type determined by the type of arr1
.
ARRAY_CONCAT
ARRAY_CONCAT(arr1, arr2)
Concatenates arr2
to arr1
. The resulting array type is determined by the type of arr1
.|
ARRAY_CONCAT_AGG
ARRAY_CONCAT_AGG([DISTINCT] expr, [<NUMERIC>])
Concatenates array inputs into a single array.
ARRAY_CONTAINS
ARRAY_CONTAINS(arr, expr)
If expr
is a scalar type, returns true if arr
contains expr
. If expr
is an array, returns 1 if arr
contains all elements of expr
. Otherwise returns false.
ARRAY_LENGTH
ARRAY_LENGTH(arr)
Returns length of the array expression.
ARRAY_OFFSET
ARRAY_OFFSET(arr, long)
Returns the array element at the 0-based index supplied, or null for an out of range index.
ARRAY_OFFSET_OF
ARRAY_OFFSET_OF(arr, expr)
Returns the 0-based index of the first occurrence of expr
in the array. If no matching elements exist in the array, returns null
or -1
if druid.generic.useDefaultValueForNull=true
(deprecated legacy mode).
ARRAY_ORDINAL
ARRAY_ORDINAL(arr, long)
Returns the array element at the 1-based index supplied, or null for an out of range index.
ARRAY_ORDINAL_OF
ARRAY_ORDINAL_OF(arr, expr)
Returns the 1-based index of the first occurrence of expr
in the array. If no matching elements exist in the array, returns null
or -1
if druid.generic.useDefaultValueForNull=true
(deprecated legacy mode).
ARRAY_OVERLAP
ARRAY_OVERLAP(arr1, arr2)
Returns true if arr1
and arr2
have any elements in common, else false.
SCALAR_IN_ARRAY
SCALAR_IN_ARRAY(expr, arr)
Returns true if the scalar expr
is present in arr
. Otherwise, returns false if the scalar expr
is non-null or
UNKNOWN
if the scalar expr
is NULL
.
Returns UNKNOWN
if arr
is NULL
.
ARRAY_PREPEND
ARRAY_PREPEND(expr, arr)
Prepends expr
to arr
at the beginning, the resulting array type determined by the type of arr
.
ARRAY_SLICE
ARRAY_SLICE(arr, start, end)
Returns the subarray of arr
from the 0-based index start
(inclusive) to end
(exclusive). Returns null
, if start
is less than 0, greater than length of arr
, or greater than end
.
ARRAY_TO_MV
ARRAY_TO_MV(arr)
Converts an ARRAY
of any type into a multi-value string VARCHAR
.
ARRAY_TO_STRING
ARRAY_TO_STRING(arr, str)
Joins all elements of arr
by the delimiter specified by str
.
ASIN
ASIN(<NUMERIC>)
Calculates the arc sine of a numeric expression.
ATAN
ATAN(<NUMERIC>)
Calculates the arc tangent of a numeric expression.
ATAN2
ATAN2(<NUMERIC>, <NUMERIC>)
Calculates the arc tangent of the two arguments.
AVG
AVG(<NUMERIC>)
Calculates the average of a set of values.
BIT_AND
BIT_AND(expr)
Performs a bitwise AND operation on all input values.
BIT_OR
BIT_OR(expr)
Performs a bitwise OR operation on all input values.
BIT_XOR
BIT_XOR(expr)
Performs a bitwise XOR operation on all input values.
BITWISE_AND
BITWISE_AND(expr1, expr2)
Returns the bitwise AND between the two expressions, that is, expr1 & expr2
.
BITWISE_COMPLEMENT
BITWISE_COMPLEMENT(expr)
Returns the bitwise NOT for the expression, that is, ~expr
.
BITWISE_CONVERT_DOUBLE_TO_LONG_BITS
BITWISE_CONVERT_DOUBLE_TO_LONG_BITS(expr)
Converts the bits of an IEEE 754 floating-point double value to a long.
BITWISE_CONVERT_LONG_BITS_TO_DOUBLE
BITWISE_CONVERT_LONG_BITS_TO_DOUBLE(expr)
Converts a long to the IEEE 754 floating-point double specified by the bits stored in the long.
BITWISE_OR
BITWISE_OR(expr1, expr2)
Returns the bitwise OR between the two expressions, that is, expr1 | expr2
.
BITWISE_SHIFT_LEFT
BITWISE_SHIFT_LEFT(expr1, expr2)
Returns a bitwise left shift of expr1, that is, expr1 << expr2
.
BITWISE_SHIFT_RIGHT
BITWISE_SHIFT_RIGHT(expr1, expr2)
Returns a bitwise right shift of expr1, that is, expr1 >> expr2
.
BITWISE_XOR
BITWISE_XOR(expr1, expr2)
Returns the bitwise exclusive OR between the two expressions, that is, expr1 ^ expr2
.
BLOOM_FILTER
BLOOM_FILTER(expr, <NUMERIC>)
Computes a Bloom filter from values produced by the specified expression.
BLOOM_FILTER_TEST
BLOOM_FILTER_TEST(expr, <STRING>)
Returns true if the expression is contained in a Base64-serialized Bloom filter.
BTRIM
BTRIM(<CHARACTER>, [<CHARACTER>])
Trims characters from both the leading and trailing ends of an expression.
CASE
CASE expr WHEN value1 THEN result1 \[ WHEN value2 THEN result2 ... \] \[ ELSE resultN \] END
Returns a result based on a given condition.