blob: d34056d301b94791cdd6b60b25927b1b0cf51b2d [file] [log] [blame]
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[9461],{3905:(e,t,a)=>{a.d(t,{Zo:()=>d,kt:()=>N});var n=a(67294);function r(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function i(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function l(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?i(Object(a),!0).forEach((function(t){r(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):i(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function o(e,t){if(null==e)return{};var a,n,r=function(e,t){if(null==e)return{};var a,n,r={},i=Object.keys(e);for(n=0;n<i.length;n++)a=i[n],t.indexOf(a)>=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)a=i[n],t.indexOf(a)>=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}var p=n.createContext({}),s=function(e){var t=n.useContext(p),a=t;return e&&(a="function"==typeof e?e(t):l(l({},t),e)),a},d=function(e){var t=s(e.components);return n.createElement(p.Provider,{value:t},e.children)},m="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},k=n.forwardRef((function(e,t){var a=e.components,r=e.mdxType,i=e.originalType,p=e.parentName,d=o(e,["components","mdxType","originalType","parentName"]),m=s(a),k=r,N=m["".concat(p,".").concat(k)]||m[k]||u[k]||i;return a?n.createElement(N,l(l({ref:t},d),{},{components:a})):n.createElement(N,l({ref:t},d))}));function N(e,t){var a=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var i=a.length,l=new Array(i);l[0]=k;var o={};for(var p in t)hasOwnProperty.call(t,p)&&(o[p]=t[p]);o.originalType=e,o[m]="string"==typeof e?e:r,l[1]=o;for(var s=2;s<i;s++)l[s]=a[s];return n.createElement.apply(null,l)}return n.createElement.apply(null,a)}k.displayName="MDXCreateElement"},90831:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>d,contentTitle:()=>p,default:()=>N,frontMatter:()=>o,metadata:()=>s,toc:()=>m});var n=a(87462),r=a(63366),i=(a(67294),a(3905)),l=["components"],o={id:"math-expr",title:"Expressions"},p=void 0,s={unversionedId:"misc/math-expr",id:"misc/math-expr",title:"Expressions",description:"\x3c!--",source:"@site/docs/latest/misc/math-expr.md",sourceDirName:"misc",slug:"/misc/math-expr",permalink:"/docs/latest/misc/math-expr",draft:!1,tags:[],version:"current",frontMatter:{id:"math-expr",title:"Expressions"}},d={},m=[{value:"General functions",id:"general-functions",level:2},{value:"String functions",id:"string-functions",level:2},{value:"Time functions",id:"time-functions",level:2},{value:"Math functions",id:"math-functions",level:2},{value:"Array functions",id:"array-functions",level:2},{value:"Apply functions",id:"apply-functions",level:2},{value:"Lambda expressions syntax",id:"lambda-expressions-syntax",level:3},{value:"JSON functions",id:"json-functions",level:2},{value:"JSONPath syntax",id:"jsonpath-syntax",level:3},{value:"Reduction functions",id:"reduction-functions",level:2},{value:"IP address functions",id:"ip-address-functions",level:2},{value:"Other functions",id:"other-functions",level:2},{value:"Vectorization support",id:"vectorization-support",level:2},{value:"Logical operator modes",id:"logical-operator-modes",level:2}],u={toc:m},k="wrapper";function N(e){var t=e.components,a=(0,r.Z)(e,l);return(0,i.kt)(k,(0,n.Z)({},u,a,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("blockquote",null,(0,i.kt)("p",{parentName:"blockquote"},"Apache Druid supports two query languages: ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/querying/"},"native queries")," and ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/querying/sql"},"Druid SQL"),".\nThis document describes the native language. For information about functions available in SQL, refer to the\n",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/querying/sql-scalar"},"SQL documentation"),".")),(0,i.kt)("p",null,"Expressions are used in various places in the native query language, including\n",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/querying/virtual-columns"},"virtual columns")," and ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/querying/datasource#join"},"join conditions"),". They are\nalso generated by most ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/querying/sql-scalar"},"Druid SQL functions")," during the\n",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/querying/sql-translation"},"query translation")," process."),(0,i.kt)("p",null,"Expressions are also used at ingestion time inside ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/ingestion/ingestion-spec#transforms"},"transformations"),"."),(0,i.kt)("p",null,"This expression language supports the following operators (listed in decreasing order of precedence)."),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:null},"Operators"),(0,i.kt)("th",{parentName:"tr",align:null},"Description"))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"!, -"),(0,i.kt)("td",{parentName:"tr",align:null},"Unary NOT and Minus")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"^"),(0,i.kt)("td",{parentName:"tr",align:null},"Binary power op")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"*, /, %"),(0,i.kt)("td",{parentName:"tr",align:null},"Binary multiplicative")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"+, -"),(0,i.kt)("td",{parentName:"tr",align:null},"Binary additive")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"<, <=, >, >=, ==, !="),(0,i.kt)("td",{parentName:"tr",align:null},"Binary Comparison")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"&&, ","|","|"),(0,i.kt)("td",{parentName:"tr",align:null},"Binary Logical AND, OR")))),(0,i.kt)("p",null,"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."),(0,i.kt)("p",null,"Additionally, the expression language supports long, double, and string arrays. Array literals are created by wrapping square brackets around a list of scalar literals values delimited by a comma or space character. All values in an array literal must be the same type, however null values are accepted. Typed empty arrays may be defined by prefixing with their type in angle brackets: ",(0,i.kt)("inlineCode",{parentName:"p"},"<STRING>[]"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"<DOUBLE>[]"),", or ",(0,i.kt)("inlineCode",{parentName:"p"},"<LONG>[]"),"."),(0,i.kt)("p",null,"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."),(0,i.kt)("p",null,"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)'."),(0,i.kt)("p",null,(0,i.kt)("a",{parentName:"p",href:"/docs/latest/querying/multi-value-dimensions"},"Multi-value string dimensions")," are supported and may be treated as either scalar or array typed values, as follows: "),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"When treated as a scalar type, the expression is automatically transformed so that the scalar operation is applied across all values of the multi-valued type, mimicking Druid's native behavior. "),(0,i.kt)("li",{parentName:"ul"},"Druid coerces values that result in arrays back into the native Druid string type for grouping and aggregation. Grouping on multi-value string dimensions in Druid groups by the individual values,\xa0not\xa0the 'array'. This behavior produces results similar to an implicit SQL ",(0,i.kt)("inlineCode",{parentName:"li"},"UNNEST")," operation. Alternatively, you can use the ",(0,i.kt)("inlineCode",{parentName:"li"},"array_to_string")," function to perform the aggregation on a ",(0,i.kt)("em",{parentName:"li"},"stringified")," version of the complete array and therefore preserve the complete row. To transform the stringified dimension back into the true native array type, use ",(0,i.kt)("inlineCode",{parentName:"li"},"string_to_array")," in an expression post-aggregator.")),(0,i.kt)("p",null,"The following built-in functions are available."),(0,i.kt)("h2",{id:"general-functions"},"General functions"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:null},"name"),(0,i.kt)("th",{parentName:"tr",align:null},"description"))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"cast"),(0,i.kt)("td",{parentName:"tr",align:null},"cast(expr,LONG or DOUBLE or STRING or ARRAY<LONG",">",", or ARRAY<DOUBLE",">"," or ARRAY<STRING",">",") 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).")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"if"),(0,i.kt)("td",{parentName:"tr",align:null},"if(predicate,then,else) returns 'then' if 'predicate' evaluates to a positive number, otherwise it returns 'else'")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"nvl"),(0,i.kt)("td",{parentName:"tr",align:null},"nvl(expr,expr-for-null) returns 'expr-for-null' if 'expr' is null (or empty string for string type)")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"like"),(0,i.kt)("td",{parentName:"tr",align:null},"like(expr, pattern","[, escape]",") is equivalent to SQL ",(0,i.kt)("inlineCode",{parentName:"td"},"expr LIKE pattern"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"case_searched"),(0,i.kt)("td",{parentName:"tr",align:null},"case_searched(expr1, result1, ","[","[","expr2, result2, ...","]",", else-result","]",") is similar to ",(0,i.kt)("inlineCode",{parentName:"td"},"CASE WHEN expr1 THEN result1 [ELSE else_result] END")," in SQL")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"case_simple"),(0,i.kt)("td",{parentName:"tr",align:null},"case_simple(expr, value1, result1, ","[","[","value2, result2, ...","]",", else-result","]",") is similar to ",(0,i.kt)("inlineCode",{parentName:"td"},"CASE expr WHEN value THEN result [ELSE else_result] END")," in SQL")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"isnull"),(0,i.kt)("td",{parentName:"tr",align:null},"isnull(expr) returns 1 if the value is null, else 0")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"notnull"),(0,i.kt)("td",{parentName:"tr",align:null},"notnull(expr) returns 1 if the value is not null, else 0")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"bloom_filter_test"),(0,i.kt)("td",{parentName:"tr",align:null},"bloom_filter_test(expr, filter) tests the value of 'expr' against 'filter', a bloom filter serialized as a base64 string. See ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/development/extensions-core/bloom-filter"},"bloom filter extension")," documentation for additional details.")))),(0,i.kt)("h2",{id:"string-functions"},"String functions"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:null},"name"),(0,i.kt)("th",{parentName:"tr",align:null},"description"))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"concat"),(0,i.kt)("td",{parentName:"tr",align:null},"concat(expr, expr...) concatenate a list of strings")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"format"),(0,i.kt)("td",{parentName:"tr",align:null},"format(pattern","[, args...]",") returns a string formatted in the manner of Java's ",(0,i.kt)("a",{parentName:"td",href:"https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#format-java.lang.String-java.lang.Object...-"},"String.format"),".")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"like"),(0,i.kt)("td",{parentName:"tr",align:null},"like(expr, pattern","[, escape]",") is equivalent to SQL ",(0,i.kt)("inlineCode",{parentName:"td"},"expr LIKE pattern"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"lookup"),(0,i.kt)("td",{parentName:"tr",align:null},"lookup(expr, lookup-name) looks up expr in a registered ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/querying/lookups"},"query-time lookup"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"parse_long"),(0,i.kt)("td",{parentName:"tr",align:null},"parse_long(string","[, radix]",") parses a string as a long with the given radix, or 10 (decimal) if a radix is not provided.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"regexp_extract"),(0,i.kt)("td",{parentName:"tr",align:null},"regexp_extract(expr, pattern","[, index]",") applies a regular expression pattern and extracts a capture group index, or null if there is no match. If index is unspecified or zero, returns the substring that matched the pattern. The pattern may match anywhere inside ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),"; if you want to match the entire string instead, use the ",(0,i.kt)("inlineCode",{parentName:"td"},"^")," and ",(0,i.kt)("inlineCode",{parentName:"td"},"$")," markers at the start and end of your pattern.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"regexp_like"),(0,i.kt)("td",{parentName:"tr",align:null},"regexp_like(expr, pattern) returns whether ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," matches regular expression ",(0,i.kt)("inlineCode",{parentName:"td"},"pattern"),". The pattern may match anywhere inside ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),"; if you want to match the entire string instead, use the ",(0,i.kt)("inlineCode",{parentName:"td"},"^")," and ",(0,i.kt)("inlineCode",{parentName:"td"},"$")," markers at the start and end of your pattern.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"contains_string"),(0,i.kt)("td",{parentName:"tr",align:null},"contains_string(expr, string) returns whether ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," contains ",(0,i.kt)("inlineCode",{parentName:"td"},"string")," as a substring. This method is case-sensitive.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"icontains_string"),(0,i.kt)("td",{parentName:"tr",align:null},"contains_string(expr, string) returns whether ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," contains ",(0,i.kt)("inlineCode",{parentName:"td"},"string")," as a substring. This method is case-insensitive.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"replace"),(0,i.kt)("td",{parentName:"tr",align:null},"replace(expr, pattern, replacement) replaces pattern with replacement")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"substring"),(0,i.kt)("td",{parentName:"tr",align:null},"substring(expr, index, length) behaves like java.lang.String's substring")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"right"),(0,i.kt)("td",{parentName:"tr",align:null},"right(expr, length) returns the rightmost length characters from a string")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"left"),(0,i.kt)("td",{parentName:"tr",align:null},"left(expr, length) returns the leftmost length characters from a string")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"strlen"),(0,i.kt)("td",{parentName:"tr",align:null},"strlen(expr) returns length of a string in UTF-16 code units")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"strpos"),(0,i.kt)("td",{parentName:"tr",align:null},"strpos(haystack, needle","[, fromIndex]",") returns the position of the needle within the haystack, with indexes starting from 0. The search will begin at fromIndex, or 0 if fromIndex is not specified. If the needle is not found then the function returns -1.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"trim"),(0,i.kt)("td",{parentName:"tr",align:null},"trim(expr","[, chars]",") remove leading and trailing characters from ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," if they are present in ",(0,i.kt)("inlineCode",{parentName:"td"},"chars"),". ",(0,i.kt)("inlineCode",{parentName:"td"},"chars")," defaults to ' ' (space) if not provided.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"ltrim"),(0,i.kt)("td",{parentName:"tr",align:null},"ltrim(expr","[, chars]",") remove leading characters from ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," if they are present in ",(0,i.kt)("inlineCode",{parentName:"td"},"chars"),". ",(0,i.kt)("inlineCode",{parentName:"td"},"chars")," defaults to ' ' (space) if not provided.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"rtrim"),(0,i.kt)("td",{parentName:"tr",align:null},"rtrim(expr","[, chars]",") remove trailing characters from ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," if they are present in ",(0,i.kt)("inlineCode",{parentName:"td"},"chars"),". ",(0,i.kt)("inlineCode",{parentName:"td"},"chars")," defaults to ' ' (space) if not provided.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"lower"),(0,i.kt)("td",{parentName:"tr",align:null},"lower(expr) converts a string to lowercase")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"upper"),(0,i.kt)("td",{parentName:"tr",align:null},"upper(expr) converts a string to uppercase")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"reverse"),(0,i.kt)("td",{parentName:"tr",align:null},"reverse(expr) reverses a string")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"repeat"),(0,i.kt)("td",{parentName:"tr",align:null},"repeat(expr, N) repeats a string N times")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"lpad"),(0,i.kt)("td",{parentName:"tr",align:null},"lpad(expr, length, chars) returns a string of ",(0,i.kt)("inlineCode",{parentName:"td"},"length")," from ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," left-padded with ",(0,i.kt)("inlineCode",{parentName:"td"},"chars"),". If ",(0,i.kt)("inlineCode",{parentName:"td"},"length")," is shorter than the length of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),", the result is ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," which is truncated to ",(0,i.kt)("inlineCode",{parentName:"td"},"length"),". The result will be null if either ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," or ",(0,i.kt)("inlineCode",{parentName:"td"},"chars")," is null. If ",(0,i.kt)("inlineCode",{parentName:"td"},"chars")," is an empty string, no padding is added, however ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," may be trimmed if necessary.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"rpad"),(0,i.kt)("td",{parentName:"tr",align:null},"rpad(expr, length, chars) returns a string of ",(0,i.kt)("inlineCode",{parentName:"td"},"length")," from ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," right-padded with ",(0,i.kt)("inlineCode",{parentName:"td"},"chars"),". If ",(0,i.kt)("inlineCode",{parentName:"td"},"length")," is shorter than the length of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),", the result is ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," which is truncated to ",(0,i.kt)("inlineCode",{parentName:"td"},"length"),". The result will be null if either ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," or ",(0,i.kt)("inlineCode",{parentName:"td"},"chars")," is null. If ",(0,i.kt)("inlineCode",{parentName:"td"},"chars")," is an empty string, no padding is added, however ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," may be trimmed if necessary.")))),(0,i.kt)("h2",{id:"time-functions"},"Time functions"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:null},"name"),(0,i.kt)("th",{parentName:"tr",align:null},"description"))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"timestamp"),(0,i.kt)("td",{parentName:"tr",align:null},"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")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"unix_timestamp"),(0,i.kt)("td",{parentName:"tr",align:null},"same with 'timestamp' function but returns seconds instead")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"timestamp_ceil"),(0,i.kt)("td",{parentName:"tr",align:null},"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".')),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"timestamp_floor"),(0,i.kt)("td",{parentName:"tr",align:null},"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".')),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"timestamp_shift"),(0,i.kt)("td",{parentName:"tr",align:null},"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".')),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"timestamp_extract"),(0,i.kt)("td",{parentName:"tr",align:null},"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 ",(0,i.kt)("a",{parentName:"td",href:"https://en.wikipedia.org/wiki/ISO_week_date"},"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"')),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"timestamp_parse"),(0,i.kt)("td",{parentName:"tr",align:null},"timestamp_parse(string expr, ","[","pattern, [timezone","]","]",") parses a string into a timestamp using a given ",(0,i.kt)("a",{parentName:"td",href:"http://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat"},"Joda DateTimeFormat pattern"),'. 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.')),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"timestamp_format"),(0,i.kt)("td",{parentName:"tr",align:null},"timestamp_format(expr, ","[","pattern, ","[","timezone","]","]",") formats a timestamp as a string with a given ",(0,i.kt)("a",{parentName:"td",href:"http://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat"},"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.')))),(0,i.kt)("h2",{id:"math-functions"},"Math functions"),(0,i.kt)("p",null,"See javadoc of java.lang.Math for detailed explanation for each function."),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:null},"name"),(0,i.kt)("th",{parentName:"tr",align:null},"description"))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"abs"),(0,i.kt)("td",{parentName:"tr",align:null},"abs(x) returns the absolute value of x")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"acos"),(0,i.kt)("td",{parentName:"tr",align:null},"acos(x) returns the arc cosine of x")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"asin"),(0,i.kt)("td",{parentName:"tr",align:null},"asin(x) returns the arc sine of x")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"atan"),(0,i.kt)("td",{parentName:"tr",align:null},"atan(x) returns the arc tangent of x")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"bitwiseAnd"),(0,i.kt)("td",{parentName:"tr",align:null},"bitwiseAnd(x,y) returns the result of x & y. Double values will be implicitly cast to longs, use ",(0,i.kt)("inlineCode",{parentName:"td"},"bitwiseConvertDoubleToLongBits")," to perform bitwise operations directly with doubles")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"bitwiseComplement"),(0,i.kt)("td",{parentName:"tr",align:null},"bitwiseComplement(x) returns the result of ~x. Double values will be implicitly cast to longs, use ",(0,i.kt)("inlineCode",{parentName:"td"},"bitwiseConvertDoubleToLongBits")," to perform bitwise operations directly with doubles")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"bitwiseConvertDoubleToLongBits"),(0,i.kt)("td",{parentName:"tr",align:null},"bitwiseConvertDoubleToLongBits(x) converts the bits of an IEEE 754 floating-point double value to a long. If the input is not a double, it is implicitly cast to a double prior to conversion")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"bitwiseConvertLongBitsToDouble"),(0,i.kt)("td",{parentName:"tr",align:null},"bitwiseConvertLongBitsToDouble(x) converts a long to the IEEE 754 floating-point double specified by the bits stored in the long. If the input is not a long, it is implicitly cast to a long prior to conversion")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"bitwiseOr"),(0,i.kt)("td",{parentName:"tr",align:null},"bitwiseOr(x,y) returns the result of x ","[PIPE]"," y. Double values will be implicitly cast to longs, use ",(0,i.kt)("inlineCode",{parentName:"td"},"bitwiseConvertDoubleToLongBits")," to perform bitwise operations directly with doubles")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"bitwiseShiftLeft"),(0,i.kt)("td",{parentName:"tr",align:null},"bitwiseShiftLeft(x,y) returns the result of x << y. Double values will be implicitly cast to longs, use ",(0,i.kt)("inlineCode",{parentName:"td"},"bitwiseConvertDoubleToLongBits")," to perform bitwise operations directly with doubles")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"bitwiseShiftRight"),(0,i.kt)("td",{parentName:"tr",align:null},"bitwiseShiftRight(x,y) returns the result of x >> y. Double values will be implicitly cast to longs, use ",(0,i.kt)("inlineCode",{parentName:"td"},"bitwiseConvertDoubleToLongBits")," to perform bitwise operations directly with doubles")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"bitwiseXor"),(0,i.kt)("td",{parentName:"tr",align:null},"bitwiseXor(x,y) returns the result of x ^ y. Double values will be implicitly cast to longs, use ",(0,i.kt)("inlineCode",{parentName:"td"},"bitwiseConvertDoubleToLongBits")," to perform bitwise operations directly with doubles")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"atan2"),(0,i.kt)("td",{parentName:"tr",align:null},"atan2(y, x) returns the angle theta from the conversion of rectangular coordinates (x, y) to polar * coordinates (r, theta)")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"cbrt"),(0,i.kt)("td",{parentName:"tr",align:null},"cbrt(x) returns the cube root of x")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"ceil"),(0,i.kt)("td",{parentName:"tr",align:null},"ceil(x) returns the smallest (closest to negative infinity) double value that is greater than or equal to x and is equal to a mathematical integer")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"copysign"),(0,i.kt)("td",{parentName:"tr",align:null},"copysign(x) returns the first floating-point argument with the sign of the second floating-point argument")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"cos"),(0,i.kt)("td",{parentName:"tr",align:null},"cos(x) returns the trigonometric cosine of x")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"cosh"),(0,i.kt)("td",{parentName:"tr",align:null},"cosh(x) returns the hyperbolic cosine of x")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"cot"),(0,i.kt)("td",{parentName:"tr",align:null},"cot(x) returns the trigonometric cotangent of an angle x")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"div"),(0,i.kt)("td",{parentName:"tr",align:null},"div(x,y) is integer division of x by y")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"exp"),(0,i.kt)("td",{parentName:"tr",align:null},"exp(x) returns Euler's number raised to the power of x")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"expm1"),(0,i.kt)("td",{parentName:"tr",align:null},"expm1(x) returns e^x-1")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"floor"),(0,i.kt)("td",{parentName:"tr",align:null},"floor(x) returns the largest (closest to positive infinity) double value that is less than or equal to x and is equal to a mathematical integer")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"getExponent"),(0,i.kt)("td",{parentName:"tr",align:null},"getExponent(x) returns the unbiased exponent used in the representation of x")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"hypot"),(0,i.kt)("td",{parentName:"tr",align:null},"hypot(x, y) returns sqrt(x^2+y^2) without intermediate overflow or underflow")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"log"),(0,i.kt)("td",{parentName:"tr",align:null},"log(x) returns the natural logarithm of x")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"log10"),(0,i.kt)("td",{parentName:"tr",align:null},"log10(x) returns the base 10 logarithm of x")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"log1p"),(0,i.kt)("td",{parentName:"tr",align:null},"log1p(x) will the natural logarithm of x + 1")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"max"),(0,i.kt)("td",{parentName:"tr",align:null},"max(x, y) returns the greater of two values")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"min"),(0,i.kt)("td",{parentName:"tr",align:null},"min(x, y) returns the smaller of two values")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"nextafter"),(0,i.kt)("td",{parentName:"tr",align:null},"nextafter(x, y) returns the floating-point number adjacent to the x in the direction of the y")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"nextUp"),(0,i.kt)("td",{parentName:"tr",align:null},"nextUp(x) returns the floating-point value adjacent to x in the direction of positive infinity")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"pi"),(0,i.kt)("td",{parentName:"tr",align:null},"pi returns the constant value of the \u03c0")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"pow"),(0,i.kt)("td",{parentName:"tr",align:null},"pow(x, y) returns the value of the x raised to the power of y")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"remainder"),(0,i.kt)("td",{parentName:"tr",align:null},"remainder(x, y) returns the remainder operation on two arguments as prescribed by the IEEE 754 standard")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"rint"),(0,i.kt)("td",{parentName:"tr",align:null},"rint(x) returns value that is closest in value to x and is equal to a mathematical integer")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"round"),(0,i.kt)("td",{parentName:"tr",align:null},"round(x, y) returns the value of the x rounded to the y decimal places. While x can be an integer or floating-point number, y must be an integer. The type of the return value is specified by that of x. y defaults to 0 if omitted. When y is negative, x is rounded on the left side of the y decimal points. If x is ",(0,i.kt)("inlineCode",{parentName:"td"},"NaN"),", x returns 0. If x is infinity, x will be converted to the nearest finite double.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"safe_divide"),(0,i.kt)("td",{parentName:"tr",align:null},"safe_divide(x,y) returns the division of x by y if y is not equal to 0. In case y is 0 it returns 0 or ",(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"scalb"),(0,i.kt)("td",{parentName:"tr",align:null},"scalb(d, sf) returns d * 2^sf rounded as if performed by a single correctly rounded floating-point multiply to a member of the double value set")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"signum"),(0,i.kt)("td",{parentName:"tr",align:null},"signum(x) returns the signum function of the argument x")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"sin"),(0,i.kt)("td",{parentName:"tr",align:null},"sin(x) returns the trigonometric sine of an angle x")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"sinh"),(0,i.kt)("td",{parentName:"tr",align:null},"sinh(x) returns the hyperbolic sine of x")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"sqrt"),(0,i.kt)("td",{parentName:"tr",align:null},"sqrt(x) returns the correctly rounded positive square root of x")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"tan"),(0,i.kt)("td",{parentName:"tr",align:null},"tan(x) returns the trigonometric tangent of an angle x")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"tanh"),(0,i.kt)("td",{parentName:"tr",align:null},"tanh(x) returns the hyperbolic tangent of x")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"todegrees"),(0,i.kt)("td",{parentName:"tr",align:null},"todegrees(x) converts an angle measured in radians to an approximately equivalent angle measured in degrees")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"toradians"),(0,i.kt)("td",{parentName:"tr",align:null},"toradians(x) converts an angle measured in degrees to an approximately equivalent angle measured in radians")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"ulp"),(0,i.kt)("td",{parentName:"tr",align:null},"ulp(x) returns the size of an ulp of the argument x")))),(0,i.kt)("h2",{id:"array-functions"},"Array functions"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:null},"function"),(0,i.kt)("th",{parentName:"tr",align:null},"description"))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"array(expr1,expr ...)"),(0,i.kt)("td",{parentName:"tr",align:null},"constructs an array from the expression arguments, using the type of the first argument as the output array type")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"array_length(arr)"),(0,i.kt)("td",{parentName:"tr",align:null},"returns length of array expression")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"array_offset(arr,long)"),(0,i.kt)("td",{parentName:"tr",align:null},"returns the array element at the 0 based index supplied, or null for an out of range index")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"array_ordinal(arr,long)"),(0,i.kt)("td",{parentName:"tr",align:null},"returns the array element at the 1 based index supplied, or null for an out of range index")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"array_contains(arr,expr)"),(0,i.kt)("td",{parentName:"tr",align:null},"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")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"array_overlap(arr1,arr2)"),(0,i.kt)("td",{parentName:"tr",align:null},"returns 1 if arr1 and arr2 have any elements in common, else 0")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"array_offset_of(arr,expr)"),(0,i.kt)("td",{parentName:"tr",align:null},"returns the 0 based index of the first occurrence of expr in the array, or ",(0,i.kt)("inlineCode",{parentName:"td"},"-1")," or ",(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),"if no matching elements exist in the array.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"array_ordinal_of(arr,expr)"),(0,i.kt)("td",{parentName:"tr",align:null},"returns the 1 based index of the first occurrence of expr in the array, or ",(0,i.kt)("inlineCode",{parentName:"td"},"-1")," or ",(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false")," if no matching elements exist in the array.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"array_prepend(expr,arr)"),(0,i.kt)("td",{parentName:"tr",align:null},"adds expr to arr at the beginning, the resulting array type determined by the type of the array")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"array_append(arr,expr)"),(0,i.kt)("td",{parentName:"tr",align:null},"appends expr to arr, the resulting array type determined by the type of the first array")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"array_concat(arr1,arr2)"),(0,i.kt)("td",{parentName:"tr",align:null},"concatenates 2 arrays, the resulting array type determined by the type of the first array")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"array_set_add(arr,expr)"),(0,i.kt)("td",{parentName:"tr",align:null},"adds expr to arr and converts the array to a new array composed of the unique set of elements. The resulting array type determined by the type of the array")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"array_set_add_all(arr1,arr2)"),(0,i.kt)("td",{parentName:"tr",align:null},"combines the unique set of elements of 2 arrays, the resulting array type determined by the type of the first array")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"array_slice(arr,start,end)"),(0,i.kt)("td",{parentName:"tr",align:null},"return the subarray of arr from the 0 based index start(inclusive) to end(exclusive), or ",(0,i.kt)("inlineCode",{parentName:"td"},"null"),", if start is less than 0, greater than length of arr or less than end")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"array_to_string(arr,str)"),(0,i.kt)("td",{parentName:"tr",align:null},"joins all elements of arr by the delimiter specified by str")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"string_to_array(str1,str2)"),(0,i.kt)("td",{parentName:"tr",align:null},"splits str1 into an array on the delimiter specified by str2")))),(0,i.kt)("h2",{id:"apply-functions"},"Apply functions"),(0,i.kt)("p",null,"Apply functions allow for special 'lambda' expressions to be defined and applied to array inputs to enable free-form transformations."),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:null},"function"),(0,i.kt)("th",{parentName:"tr",align:null},"description"))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"map(lambda,arr)"),(0,i.kt)("td",{parentName:"tr",align:null},"applies a transform specified by a single argument lambda expression to all elements of arr, returning a new array")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"cartesian_map(lambda,arr1,arr2,...)"),(0,i.kt)("td",{parentName:"tr",align:null},"applies a transform specified by a multi argument lambda expression to all elements of the Cartesian product of all input arrays, returning a new array; the number of lambda arguments and array inputs must be the same")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"filter(lambda,arr)"),(0,i.kt)("td",{parentName:"tr",align:null},"filters arr by a single argument lambda, returning a new array with all matching elements, or null if no elements match")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"fold(lambda,arr,acc)"),(0,i.kt)("td",{parentName:"tr",align:null},"folds a 2 argument lambda across arr using acc as the initial input value. The first argument of the lambda is the array element and the second the accumulator, returning a single accumulated value.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"cartesian_fold(lambda,arr1,arr2,...,acc)"),(0,i.kt)("td",{parentName:"tr",align:null},"folds a multi argument lambda across the Cartesian product of all input arrays using acc as the initial input value. The first arguments of the lambda are the array elements of each array and the last is the accumulator, returning a single accumulated value.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"any(lambda,arr)"),(0,i.kt)("td",{parentName:"tr",align:null},"returns 1 if any element in the array matches the lambda expression, else 0")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"all(lambda,arr)"),(0,i.kt)("td",{parentName:"tr",align:null},"returns 1 if all elements in the array matches the lambda expression, else 0")))),(0,i.kt)("h3",{id:"lambda-expressions-syntax"},"Lambda expressions syntax"),(0,i.kt)("p",null,"Lambda expressions are a sort of function definition, where new identifiers can be defined and passed as input to the expression body"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"(identifier1 ...) -> expr\n")),(0,i.kt)("p",null,"e.g."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"(x, y) -> x + y \n")),(0,i.kt)("p",null,"The identifier arguments of a lambda expression correspond to the elements of the array it is being applied to. For example:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"map((x) -> x + 1, some_multi_value_column)\n")),(0,i.kt)("p",null,"will map each element of ",(0,i.kt)("inlineCode",{parentName:"p"},"some_multi_value_column")," to the identifier ",(0,i.kt)("inlineCode",{parentName:"p"},"x")," so that the lambda expression body can be evaluated for each ",(0,i.kt)("inlineCode",{parentName:"p"},"x"),". The scoping rules are that lambda arguments will override identifiers which are defined externally from the lambda expression body. Using the same example:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"map((x) -> x + 1, x)\n")),(0,i.kt)("p",null,"in this case, the ",(0,i.kt)("inlineCode",{parentName:"p"},"x")," when evaluating ",(0,i.kt)("inlineCode",{parentName:"p"},"x + 1")," is the lambda argument, thus an element of the multi-valued column ",(0,i.kt)("inlineCode",{parentName:"p"},"x"),", rather than the column ",(0,i.kt)("inlineCode",{parentName:"p"},"x")," itself."),(0,i.kt)("h2",{id:"json-functions"},"JSON functions"),(0,i.kt)("p",null,"JSON functions provide facilities to extract, transform, and create ",(0,i.kt)("inlineCode",{parentName:"p"},"COMPLEX<json>")," values. "),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:null},"function"),(0,i.kt)("th",{parentName:"tr",align:null},"description"))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"json_value(expr, path","[, type]",")"),(0,i.kt)("td",{parentName:"tr",align:null},"Extract a Druid literal (",(0,i.kt)("inlineCode",{parentName:"td"},"STRING"),", ",(0,i.kt)("inlineCode",{parentName:"td"},"LONG"),", ",(0,i.kt)("inlineCode",{parentName:"td"},"DOUBLE"),") value from ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," using JSONPath syntax of ",(0,i.kt)("inlineCode",{parentName:"td"},"path"),". The optional ",(0,i.kt)("inlineCode",{parentName:"td"},"type")," argument can be set to ",(0,i.kt)("inlineCode",{parentName:"td"},"'LONG'"),",",(0,i.kt)("inlineCode",{parentName:"td"},"'DOUBLE'")," or ",(0,i.kt)("inlineCode",{parentName:"td"},"'STRING'")," to cast values to that type.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"json_query(expr, path)"),(0,i.kt)("td",{parentName:"tr",align:null},"Extract a ",(0,i.kt)("inlineCode",{parentName:"td"},"COMPLEX<json>")," value from ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," using JSONPath syntax of ",(0,i.kt)("inlineCode",{parentName:"td"},"path"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"json_object(expr1, expr2","[, expr3, expr4 ...]",")"),(0,i.kt)("td",{parentName:"tr",align:null},"Construct a ",(0,i.kt)("inlineCode",{parentName:"td"},"COMPLEX<json>")," with alternating 'key' and 'value' arguments")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"parse_json(expr)"),(0,i.kt)("td",{parentName:"tr",align:null},"Deserialize a JSON ",(0,i.kt)("inlineCode",{parentName:"td"},"STRING")," into a ",(0,i.kt)("inlineCode",{parentName:"td"},"COMPLEX<json>"),". If the input is not a ",(0,i.kt)("inlineCode",{parentName:"td"},"STRING")," or it is invalid JSON, this function will result in an error.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"try_parse_json(expr)"),(0,i.kt)("td",{parentName:"tr",align:null},"Deserialize a JSON ",(0,i.kt)("inlineCode",{parentName:"td"},"STRING")," into a ",(0,i.kt)("inlineCode",{parentName:"td"},"COMPLEX<json>"),". If the input is not a ",(0,i.kt)("inlineCode",{parentName:"td"},"STRING")," or it is invalid JSON, this function will result in a ",(0,i.kt)("inlineCode",{parentName:"td"},"NULL")," value.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"to_json_string(expr)"),(0,i.kt)("td",{parentName:"tr",align:null},"Convert ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," into a JSON ",(0,i.kt)("inlineCode",{parentName:"td"},"STRING")," value")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"json_keys(expr, path)"),(0,i.kt)("td",{parentName:"tr",align:null},"Get array of field names from ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," at the specified JSONPath ",(0,i.kt)("inlineCode",{parentName:"td"},"path"),", or null if the data does not exist or have any fields")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"json_paths(expr)"),(0,i.kt)("td",{parentName:"tr",align:null},"Get array of all JSONPath paths available from ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"))))),(0,i.kt)("h3",{id:"jsonpath-syntax"},"JSONPath syntax"),(0,i.kt)("p",null,"Druid supports a small, simplified subset of the ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/json-path/JsonPath/blob/master/README.md"},"JSONPath syntax")," operators, primarily limited to extracting individual values from nested data structures."),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:null},"Operator"),(0,i.kt)("th",{parentName:"tr",align:null},"Description"))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"$")),(0,i.kt)("td",{parentName:"tr",align:null},"Root element. All JSONPath expressions start with this operator.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},".<name>")),(0,i.kt)("td",{parentName:"tr",align:null},"Child element in dot notation.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"['<name>']")),(0,i.kt)("td",{parentName:"tr",align:null},"Child element in bracket notation.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"[<number>]")),(0,i.kt)("td",{parentName:"tr",align:null},"Array index.")))),(0,i.kt)("p",null,"See ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/querying/sql-json-functions#jsonpath-syntax"},"SQL JSON documentation")," for examples and ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/querying/nested-columns"},"Nested columns")," for more information on ingesting and storing nested data."),(0,i.kt)("h2",{id:"reduction-functions"},"Reduction functions"),(0,i.kt)("p",null,"Reduction functions operate on zero or more expressions and return a single expression. If no expressions are passed as\narguments, then the result is ",(0,i.kt)("inlineCode",{parentName:"p"},"NULL"),". The expressions must all be convertible to a common data type, which will be the\ntype of the result:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"If all arguments are ",(0,i.kt)("inlineCode",{parentName:"li"},"NULL"),", the result is ",(0,i.kt)("inlineCode",{parentName:"li"},"NULL"),". Otherwise, ",(0,i.kt)("inlineCode",{parentName:"li"},"NULL")," arguments are ignored."),(0,i.kt)("li",{parentName:"ul"},"If the arguments comprise a mix of numbers and strings, the arguments are interpreted as strings."),(0,i.kt)("li",{parentName:"ul"},"If all arguments are integer numbers, the arguments are interpreted as longs."),(0,i.kt)("li",{parentName:"ul"},"If all arguments are numbers and at least one argument is a double, the arguments are interpreted as doubles. ")),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:null},"function"),(0,i.kt)("th",{parentName:"tr",align:null},"description"))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"greatest(","[expr1, ...]",")"),(0,i.kt)("td",{parentName:"tr",align:null},"Evaluates zero or more expressions and returns the maximum value based on comparisons as described above.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"least(","[expr1, ...]",")"),(0,i.kt)("td",{parentName:"tr",align:null},"Evaluates zero or more expressions and returns the minimum value based on comparisons as described above.")))),(0,i.kt)("h2",{id:"ip-address-functions"},"IP address functions"),(0,i.kt)("p",null,"For the IPv4 address functions, the ",(0,i.kt)("inlineCode",{parentName:"p"},"address"),' argument accepts either an IPv4 dotted-decimal string (e.g., "192.168.0.1") or an IP address represented as a long (e.g., 3232235521). Format the ',(0,i.kt)("inlineCode",{parentName:"p"},"subnet"),' argument as an IPv4 address subnet in CIDR notation (e.g., "192.168.0.0/16").'),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:null},"function"),(0,i.kt)("th",{parentName:"tr",align:null},"description"))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"ipv4_match(address, subnet)"),(0,i.kt)("td",{parentName:"tr",align:null},"Returns 1 if the ",(0,i.kt)("inlineCode",{parentName:"td"},"address")," belongs to the ",(0,i.kt)("inlineCode",{parentName:"td"},"subnet")," literal, else 0. If ",(0,i.kt)("inlineCode",{parentName:"td"},"address")," is not a valid IPv4 address, then 0 is returned. This function is more efficient if ",(0,i.kt)("inlineCode",{parentName:"td"},"address")," is a long instead of a string.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"ipv4_parse(address)"),(0,i.kt)("td",{parentName:"tr",align:null},"Parses ",(0,i.kt)("inlineCode",{parentName:"td"},"address")," into an IPv4 address stored as a long. Returns ",(0,i.kt)("inlineCode",{parentName:"td"},"address")," if it is already a valid IPv4 integer address. Returns null if ",(0,i.kt)("inlineCode",{parentName:"td"},"address")," cannot be represented as an IPv4 address.")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"ipv4_stringify(address)"),(0,i.kt)("td",{parentName:"tr",align:null},"Converts ",(0,i.kt)("inlineCode",{parentName:"td"},"address")," into an IPv4 address dotted-decimal string. Returns ",(0,i.kt)("inlineCode",{parentName:"td"},"address")," if it is already a valid IPv4 dotted-decimal string. Returns null if ",(0,i.kt)("inlineCode",{parentName:"td"},"address")," cannot be represented as an IPv4 address.")))),(0,i.kt)("h2",{id:"other-functions"},"Other functions"),(0,i.kt)("table",null,(0,i.kt)("thead",{parentName:"table"},(0,i.kt)("tr",{parentName:"thead"},(0,i.kt)("th",{parentName:"tr",align:null},"function"),(0,i.kt)("th",{parentName:"tr",align:null},"description"))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"human_readable_binary_byte_format(value","[, precision]",")"),(0,i.kt)("td",{parentName:"tr",align:null},"Format a number in human-readable ",(0,i.kt)("a",{parentName:"td",href:"https://en.wikipedia.org/wiki/Binary_prefix"},"IEC")," format. ",(0,i.kt)("inlineCode",{parentName:"td"},"precision")," must be in the range of ","[0,3]"," (default: 2). For example:",(0,i.kt)("li",null," human_readable_binary_byte_format(1048576) returns ",(0,i.kt)("inlineCode",{parentName:"td"},"1.00 MiB")),(0,i.kt)("li",null,"human_readable_binary_byte_format(1048576, 3) returns ",(0,i.kt)("inlineCode",{parentName:"td"},"1.000 MiB")))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"human_readable_decimal_byte_format(value","[, precision]",")"),(0,i.kt)("td",{parentName:"tr",align:null},"Format a number in human-readable ",(0,i.kt)("a",{parentName:"td",href:"https://en.wikipedia.org/wiki/Binary_prefix"},"SI")," format. ",(0,i.kt)("inlineCode",{parentName:"td"},"precision")," must be in the range of ","[0,3]"," (default: 2). For example:",(0,i.kt)("li",null," human_readable_decimal_byte_format(1000000) returns ",(0,i.kt)("inlineCode",{parentName:"td"},"1.00 MB")),(0,i.kt)("li",null,"human_readable_decimal_byte_format(1000000, 3) returns ",(0,i.kt)("inlineCode",{parentName:"td"},"1.000 MB")))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"human_readable_decimal_format(value","[, precision]",")"),(0,i.kt)("td",{parentName:"tr",align:null},"Format a number in human-readable SI format. ",(0,i.kt)("inlineCode",{parentName:"td"},"precision")," must be in the range of ","[0,3]"," (default: 2). For example:",(0,i.kt)("li",null,"human_readable_decimal_format(1000000) returns ",(0,i.kt)("inlineCode",{parentName:"td"},"1.00 M")),(0,i.kt)("li",null,"human_readable_decimal_format(1000000, 3) returns ",(0,i.kt)("inlineCode",{parentName:"td"},"1.000 M")))))),(0,i.kt)("h2",{id:"vectorization-support"},"Vectorization support"),(0,i.kt)("p",null,"A number of expressions support ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/querying/query-context#vectorization-parameters"},"'vectorized' query engines")),(0,i.kt)("p",null,"Supported features:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"constants and identifiers are supported for any column type"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"cast")," is supported for numeric and string types"),(0,i.kt)("li",{parentName:"ul"},"math operators: ",(0,i.kt)("inlineCode",{parentName:"li"},"+"),",",(0,i.kt)("inlineCode",{parentName:"li"},"-"),",",(0,i.kt)("inlineCode",{parentName:"li"},"*"),",",(0,i.kt)("inlineCode",{parentName:"li"},"/"),",",(0,i.kt)("inlineCode",{parentName:"li"},"%"),",",(0,i.kt)("inlineCode",{parentName:"li"},"^")," are supported for numeric types"),(0,i.kt)("li",{parentName:"ul"},"logical operators: ",(0,i.kt)("inlineCode",{parentName:"li"},"!"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"&&"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"||"),", are supported for string and numeric types (if ",(0,i.kt)("inlineCode",{parentName:"li"},"druid.expressions.useStrictBooleans=true"),")"),(0,i.kt)("li",{parentName:"ul"},"comparison operators: ",(0,i.kt)("inlineCode",{parentName:"li"},"="),", ",(0,i.kt)("inlineCode",{parentName:"li"},"!="),", ",(0,i.kt)("inlineCode",{parentName:"li"},">"),", ",(0,i.kt)("inlineCode",{parentName:"li"},">="),", ",(0,i.kt)("inlineCode",{parentName:"li"},"<"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"<=")," are supported for string and numeric types"),(0,i.kt)("li",{parentName:"ul"},"math functions: ",(0,i.kt)("inlineCode",{parentName:"li"},"abs"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"acos"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"asin"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"atan"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"cbrt"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"ceil"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"cos"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"cosh"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"cot"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"exp"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"expm1"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"floor"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"getExponent"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"log"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"log10"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"log1p"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"nextUp"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"rint"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"signum"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"sin"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"sinh"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"sqrt"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"tan"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"tanh"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"toDegrees"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"toRadians"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"ulp"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"atan2"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"copySign"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"div"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"hypot"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"max"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"min"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"nextAfter"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"pow"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"remainder"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"scalb")," are supported for numeric types"),(0,i.kt)("li",{parentName:"ul"},"time functions: ",(0,i.kt)("inlineCode",{parentName:"li"},"timestamp_floor")," (with constant granularity argument) is supported for numeric types"),(0,i.kt)("li",{parentName:"ul"},"boolean functions: ",(0,i.kt)("inlineCode",{parentName:"li"},"isnull"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"notnull")," are supported for string and numeric types"),(0,i.kt)("li",{parentName:"ul"},"conditional functions: ",(0,i.kt)("inlineCode",{parentName:"li"},"nvl")," is supported for string and numeric types"),(0,i.kt)("li",{parentName:"ul"},"string functions: the concatenation operator (",(0,i.kt)("inlineCode",{parentName:"li"},"+"),") and ",(0,i.kt)("inlineCode",{parentName:"li"},"concat")," function are supported for string and numeric types"),(0,i.kt)("li",{parentName:"ul"},"other: ",(0,i.kt)("inlineCode",{parentName:"li"},"parse_long")," is supported for numeric and string types")),(0,i.kt)("h2",{id:"logical-operator-modes"},"Logical operator modes"),(0,i.kt)("p",null,"Prior to the 0.23 release of Apache Druid, boolean function expressions have inconsistent handling of true and false values, and the logical 'and' and 'or' operators behave in a manner that is incompatible with SQL, even if SQL compatible null handling mode (",(0,i.kt)("inlineCode",{parentName:"p"},"druid.generic.useDefaultValueForNull=false"),") is enabled. Logical operators also pass through their input values similar to many scripting languages, and treat ",(0,i.kt)("inlineCode",{parentName:"p"},"null")," as false, which can result in some rather strange behavior. Other boolean operations, such as comparisons and equality, retain their input types (e.g. ",(0,i.kt)("inlineCode",{parentName:"p"},"DOUBLE")," comparison would produce ",(0,i.kt)("inlineCode",{parentName:"p"},"1.0")," for true and ",(0,i.kt)("inlineCode",{parentName:"p"},"0.0")," for false), while many other boolean functions strictly produce ",(0,i.kt)("inlineCode",{parentName:"p"},"LONG")," typed values of ",(0,i.kt)("inlineCode",{parentName:"p"},"1")," for true and ",(0,i.kt)("inlineCode",{parentName:"p"},"0")," for false. "),(0,i.kt)("p",null,"After 0.23, while the inconsistent legacy behavior is still the default, it can be optionally be changed by setting ",(0,i.kt)("inlineCode",{parentName:"p"},"druid.expressions.useStrictBooleans=true"),", so that these operations will allow correctly treating ",(0,i.kt)("inlineCode",{parentName:"p"},"null"),' values as "unknown" for SQL compatible behavior, and ',(0,i.kt)("em",{parentName:"p"},"all boolean output functions")," will output 'homogeneous' ",(0,i.kt)("inlineCode",{parentName:"p"},"LONG")," typed boolean values of ",(0,i.kt)("inlineCode",{parentName:"p"},"1")," for ",(0,i.kt)("inlineCode",{parentName:"p"},"true")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"0")," for ",(0,i.kt)("inlineCode",{parentName:"p"},"false"),". Additionally, "),(0,i.kt)("p",null,'For the "or" operator:'),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"true || null"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"null || true"),", -> ",(0,i.kt)("inlineCode",{parentName:"li"},"1")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"false || null"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"null || false"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"null || null"),"-> ",(0,i.kt)("inlineCode",{parentName:"li"},"null"))),(0,i.kt)("p",null,'For the "and" operator:'),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"true && null"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"null && true"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"null && null")," -> ",(0,i.kt)("inlineCode",{parentName:"li"},"null")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"false && null"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"null && false")," -> ",(0,i.kt)("inlineCode",{parentName:"li"},"0"))),(0,i.kt)("p",null,"Druid currently still retains implicit conversion of ",(0,i.kt)("inlineCode",{parentName:"p"},"LONG"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"DOUBLE"),", and ",(0,i.kt)("inlineCode",{parentName:"p"},"STRING")," types into boolean values in both modes: "),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"LONG")," or ",(0,i.kt)("inlineCode",{parentName:"li"},"DOUBLE")," - any value greater than 0 is considered ",(0,i.kt)("inlineCode",{parentName:"li"},"true"),", else ",(0,i.kt)("inlineCode",{parentName:"li"},"false")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"STRING")," - the value ",(0,i.kt)("inlineCode",{parentName:"li"},"'true'")," (case insensitive) is considered ",(0,i.kt)("inlineCode",{parentName:"li"},"true"),", everything else is ",(0,i.kt)("inlineCode",{parentName:"li"},"false"),". ")),(0,i.kt)("p",null,"Legacy behavior:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"100 && 11")," -> ",(0,i.kt)("inlineCode",{parentName:"li"},"11")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"0.7 || 0.3")," -> ",(0,i.kt)("inlineCode",{parentName:"li"},"0.3")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"100 && 0")," -> ",(0,i.kt)("inlineCode",{parentName:"li"},"0")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"'troo' && 'true'")," -> ",(0,i.kt)("inlineCode",{parentName:"li"},"'troo'")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"'troo' || 'true'")," -> ",(0,i.kt)("inlineCode",{parentName:"li"},"'true'"))),(0,i.kt)("p",null,"SQL compatible behavior:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"100 && 11")," -> ",(0,i.kt)("inlineCode",{parentName:"li"},"1")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"0.7 || 0.3")," -> ",(0,i.kt)("inlineCode",{parentName:"li"},"1")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"100 && 0")," -> ",(0,i.kt)("inlineCode",{parentName:"li"},"0")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"'troo' && 'true'")," -> ",(0,i.kt)("inlineCode",{parentName:"li"},"0")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"'troo' || 'true'")," -> ",(0,i.kt)("inlineCode",{parentName:"li"},"1"))))}N.isMDXComponent=!0}}]);