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.

    namedescription
    castcast(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).
    ifif(predicate,then,else) returns ‘then’ if ‘predicate’ evaluates to a positive number, otherwise it returns ‘else’
    nvlnvl(expr,expr-for-null) returns ‘expr-for-null’ if ‘expr’ is null (or empty string for string type)
    likelike(expr, pattern[, escape]) is equivalent to SQL expr LIKE pattern
    case_searchedcase_searched(expr1, result1, [[expr2, result2, …], else-result])
    case_simplecase_simple(expr, value1, result1, [[value2, result2, …], else-result])
    bloom_filter_testbloom_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

    namedescription
    timestamptimestamp(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_timestampsame with ‘timestamp’ function but returns seconds instead
    timestamp_ceiltimestamp_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_floortimestamp_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_shifttimestamp_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_extracttimestamp_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_parsetimestamp_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_formattimestamp_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.

    functiondescription
    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

    functiondescription
    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.