Expressions
This expression language supports the following operators (listed in decreasing order of precedence).
Long, double, and string data types are supported. If a number contains a dot, it is interpreted as a double, otherwise it is interpreted as a long. That means, always add a ‘.’ to your number if you want it interpreted as a double value. String literals should be quoted by single quotation marks.
Expressions can contain variables. Variable names may contain letters, digits, ‘_‘ and ‘$’. Variable names must not begin with a digit. To escape other special characters, you can quote it with double quotation marks.
For logical operators, a number is true if and only if it is positive (0 or negative value means false). For string type, it’s the evaluation result of ‘Boolean.valueOf(string)’.
The following built-in functions are available.
name | description |
---|---|
cast | cast(expr,’LONG’ or ‘DOUBLE’ or ‘STRING’ or ‘LONG_ARRAY’, or ‘DOUBLE_ARRAY’ or ‘STRING_ARRAY’) returns expr with specified type. exception can be thrown. Scalar types may be cast to array types and will take the form of a single element list (null will still be null). |
if | if(predicate,then,else) returns ‘then’ if ‘predicate’ evaluates to a positive number, otherwise it returns ‘else’ |
nvl | nvl(expr,expr-for-null) returns ‘expr-for-null’ if ‘expr’ is null (or empty string for string type) |
like | like(expr, pattern[, escape]) is equivalent to SQL expr LIKE pattern |
case_searched | case_searched(expr1, result1, [[expr2, result2, …], else-result]) |
case_simple | case_simple(expr, value1, result1, [[value2, result2, …], else-result]) |
bloom_filter_test | bloom_filter_test(expr, filter) tests the value of ‘expr’ against ‘filter’, a bloom filter serialized as a base64 string. See bloom filter extension documentation for additional details. |
String functions
name | description |
---|---|
timestamp | timestamp(expr[,format-string]) parses string expr into date then returns milliseconds from java epoch. without ‘format-string’ it’s regarded as ISO datetime format |
unix_timestamp | same with ‘timestamp’ function but returns seconds instead |
timestamp_ceil | timestamp_ceil(expr, period, [origin, [timezone]]) rounds up a timestamp, returning it as a new timestamp. Period can be any ISO8601 period, like P3M (quarters) or PT12H (half-days). The time zone, if provided, should be a time zone name like “America/Los_Angeles” or offset like “-08:00”. |
timestamp_floor | timestamp_floor(expr, period, [origin, [timezone]]) rounds down a timestamp, returning it as a new timestamp. Period can be any ISO8601 period, like P3M (quarters) or PT12H (half-days). The time zone, if provided, should be a time zone name like “America/Los_Angeles” or offset like “-08:00”. |
timestamp_shift | timestamp_shift(expr, period, step, [timezone]) shifts a timestamp by a period (step times), returning it as a new timestamp. Period can be any ISO8601 period. Step may be negative. The time zone, if provided, should be a time zone name like “America/Los_Angeles” or offset like “-08:00”. |
timestamp_extract | timestamp_extract(expr, unit, [timezone]) extracts a time part from expr, returning it as a number. Unit can be EPOCH (number of seconds since 1970-01-01 00:00:00 UTC), SECOND, MINUTE, HOUR, DAY (day of month), DOW (day of week), DOY (day of year), WEEK (week of week year), MONTH (1 through 12), QUARTER (1 through 4), or YEAR. The time zone, if provided, should be a time zone name like “America/Los_Angeles” or offset like “-08:00” |
timestamp_parse | timestamp_parse(string expr, [pattern, [timezone]]) parses a string into a timestamp using a given . If the pattern is not provided, this parses time strings in either ISO8601 or SQL format. The time zone, if provided, should be a time zone name like “America/Los_Angeles” or offset like “-08:00”, and will be used as the time zone for strings that do not include a time zone offset. Pattern and time zone must be literals. Strings that cannot be parsed as timestamps will be returned as nulls. |
timestamp_format | timestamp_format(expr, [pattern, [timezone]]) formats a timestamp as a string with a given Joda DateTimeFormat pattern, or ISO8601 if the pattern is not provided. The time zone, if provided, should be a time zone name like “America/Los_Angeles” or offset like “-08:00”. Pattern and time zone must be literals. |
Math functions
See javadoc of java.lang.Math for detailed explanation for each function.
function | description |
---|---|
array(expr1,expr …) | constructs an array from the expression arguments, using the type of the first argument as the output array type |
array_length(arr) | returns length of array expression |
array_offset(arr,long) | returns the array element at the 0 based index supplied, or null for an out of range index |
array_ordinal(arr,long) | returns the array element at the 1 based index supplied, or null for an out of range index |
array_contains(arr,expr) | returns 1 if the array contains the element specified by expr, or contains all elements specified by expr if expr is an array, else 0 |
array_overlap(arr1,arr2) | returns 1 if arr1 and arr2 have any elements in common, else 0 |
array_offset_of(arr,expr) | returns the 0 based index of the first occurrence of expr in the array, or -1 or null if if no matching elements exist in the array. |
array_ordinal_of(arr,expr) | returns the 1 based index of the first occurrence of expr in the array, or -1 or null if druid.generic.useDefaultValueForNull=false if no matching elements exist in the array. |
array_prepend(expr,arr) | adds expr to arr at the beginning, the resulting array type determined by the type of the array |
array_append(arr1,expr) | appends expr to arr, the resulting array type determined by the type of the first array |
array_concat(arr1,arr2) | concatenates 2 arrays, the resulting array type determined by the type of the first array |
array_slice(arr,start,end) | return the subarray of arr from the 0 based index start(inclusive) to end(exclusive), or null , if start is less than 0, greater than length of arr or less than end |
array_to_string(arr,str) | joins all elements of arr by the delimiter specified by str |
string_to_array(str1,str2) | splits str1 into an array on the delimiter specified by str2 |
Apply functions
function | description |
---|---|
ipv4_match(address, subnet) | Returns 1 if the address belongs to the subnet literal, else 0. If address is not a valid IPv4 address, then 0 is returned. This function is more efficient if address is a long instead of a string. |
ipv4_parse(address) | Parses address into an IPv4 address stored as a long. If address is a long that is a valid IPv4 address, then it is passed through. Returns null if address cannot be represented as an IPv4 address. |
ipv4_stringify(address) | Converts address into an IPv4 address dotted-decimal string. If address is a string that is a valid IPv4 address, then it is passed through. Returns null if address cannot be represented as an IPv4 address. |