blob: 23c4419012f7ca127024986a5799c7a017f40372 [file] [log] [blame]
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[2124],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>N});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function l(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?i(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function o(e,t){if(null==e)return{};var n,a,r=function(e,t){if(null==e)return{};var n,a,r={},i=Object.keys(e);for(a=0;a<i.length;a++)n=i[a],t.indexOf(n)>=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(a=0;a<i.length;a++)n=i[a],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var d=a.createContext({}),s=function(e){var t=a.useContext(d),n=t;return e&&(n="function"==typeof e?e(t):l(l({},t),e)),n},p=function(e){var t=s(e.components);return a.createElement(d.Provider,{value:t},e.children)},u="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},k=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,i=e.originalType,d=e.parentName,p=o(e,["components","mdxType","originalType","parentName"]),u=s(n),k=r,N=u["".concat(d,".").concat(k)]||u[k]||m[k]||i;return n?a.createElement(N,l(l({ref:t},p),{},{components:n})):a.createElement(N,l({ref:t},p))}));function N(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var i=n.length,l=new Array(i);l[0]=k;var o={};for(var d in t)hasOwnProperty.call(t,d)&&(o[d]=t[d]);o.originalType=e,o[u]="string"==typeof e?e:r,l[1]=o;for(var s=2;s<i;s++)l[s]=n[s];return a.createElement.apply(null,l)}return a.createElement.apply(null,n)}k.displayName="MDXCreateElement"},1018:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>p,contentTitle:()=>d,default:()=>N,frontMatter:()=>o,metadata:()=>s,toc:()=>u});var a=n(7462),r=n(3366),i=(n(7294),n(3905)),l=["components"],o={id:"sql-aggregations",title:"SQL aggregation functions",sidebar_label:"Aggregation functions"},d=void 0,s={unversionedId:"querying/sql-aggregations",id:"querying/sql-aggregations",title:"SQL aggregation functions",description:"\x3c!--",source:"@site/docs/latest/querying/sql-aggregations.md",sourceDirName:"querying",slug:"/querying/sql-aggregations",permalink:"/docs/latest/querying/sql-aggregations",draft:!1,tags:[],version:"current",frontMatter:{id:"sql-aggregations",title:"SQL aggregation functions",sidebar_label:"Aggregation functions"},sidebar:"docs",previous:{title:"Scalar functions",permalink:"/docs/latest/querying/sql-scalar"},next:{title:"Array functions",permalink:"/docs/latest/querying/sql-array-functions"}},p={},u=[{value:"Sketch functions",id:"sketch-functions",level:2},{value:"HLL sketch functions",id:"hll-sketch-functions",level:3},{value:"Theta sketch functions",id:"theta-sketch-functions",level:3},{value:"Quantiles sketch functions",id:"quantiles-sketch-functions",level:3},{value:"Tuple sketch functions",id:"tuple-sketch-functions",level:3},{value:"T-Digest sketch functions",id:"t-digest-sketch-functions",level:3}],m={toc:u},k="wrapper";function N(e){var t=e.components,n=(0,r.Z)(e,l);return(0,i.kt)(k,(0,a.Z)({},m,n,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("blockquote",null,(0,i.kt)("p",{parentName:"blockquote"},"Apache Druid supports two query languages: Druid SQL and ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/querying/"},"native queries"),".\nThis document describes the SQL language.")),(0,i.kt)("p",null,"You can use aggregation functions in the SELECT clause of any ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/querying/sql"},"Druid SQL")," query."),(0,i.kt)("p",null,"Filter any aggregator using the FILTER clause, for example:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"SELECT \n SUM(added) FILTER(WHERE channel = '#en.wikipedia')\nFROM wikipedia\n")),(0,i.kt)("p",null,"The FILTER clause limits an aggregation query to only the rows that match the filter.\nDruid translates the FILTER clause to a native ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/querying/aggregations#filtered-aggregator"},"filtered aggregator"),".\nTwo aggregators in the same SQL query may have different filters."),(0,i.kt)("p",null,"When no rows are selected, aggregation functions return their initial value. This can occur from the following:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"When no rows match the filter while aggregating values across an entire table without a grouping, or"),(0,i.kt)("li",{parentName:"ul"},"When using filtered aggregations within a grouping.")),(0,i.kt)("p",null,"The initial value varies by aggregator. ",(0,i.kt)("inlineCode",{parentName:"p"},"COUNT")," and the approximate count distinct sketch functions\nalways return 0 as the initial value."),(0,i.kt)("p",null,"In the aggregation functions supported by Druid, only ",(0,i.kt)("inlineCode",{parentName:"p"},"COUNT"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"ARRAY_AGG"),", and ",(0,i.kt)("inlineCode",{parentName:"p"},"STRING_AGG")," accept the DISTINCT keyword."),(0,i.kt)("blockquote",null,(0,i.kt)("p",{parentName:"blockquote"},"The order of aggregation operations across segments is not deterministic. This means that non-commutative aggregation\nfunctions can produce inconsistent results across the same query. "),(0,i.kt)("p",{parentName:"blockquote"},'Functions that operate on an input type of "float" or "double" may also see these differences in aggregation\nresults across multiple query runs because of this. If precisely the same value is desired across multiple query runs,\nconsider using the ',(0,i.kt)("inlineCode",{parentName:"p"},"ROUND")," function to smooth out the inconsistencies between queries.")),(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},"Notes"),(0,i.kt)("th",{parentName:"tr",align:null},"Default"))),(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"},"COUNT(*)")),(0,i.kt)("td",{parentName:"tr",align:null},"Counts the number of rows."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"0"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"COUNT(DISTINCT expr)")),(0,i.kt)("td",{parentName:"tr",align:null},"Counts distinct values of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),".",(0,i.kt)("br",null),(0,i.kt)("br",null),"When ",(0,i.kt)("inlineCode",{parentName:"td"},"useApproximateCountDistinct"),' is set to "true" (the default), this is an alias for ',(0,i.kt)("inlineCode",{parentName:"td"},"APPROX_COUNT_DISTINCT"),". The specific algorithm depends on the value of ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/configuration/#sql"},(0,i.kt)("inlineCode",{parentName:"a"},"druid.sql.approxCountDistinct.function")),". In this mode, you can use strings, numbers, or prebuilt sketches. If counting prebuilt sketches, the prebuilt sketch type must match the selected algorithm.",(0,i.kt)("br",null),(0,i.kt)("br",null),"When ",(0,i.kt)("inlineCode",{parentName:"td"},"useApproximateCountDistinct"),' is set to "false", the computation will be exact. In this case, ',(0,i.kt)("inlineCode",{parentName:"td"},"expr")," must be string or numeric, since exact counts are not possible using prebuilt sketches. In exact mode, only one distinct count per query is permitted unless ",(0,i.kt)("inlineCode",{parentName:"td"},"useGroupingSetForExactDistinct")," is enabled.",(0,i.kt)("br",null),(0,i.kt)("br",null),"Counts each distinct value in a ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/querying/multi-value-dimensions"},(0,i.kt)("inlineCode",{parentName:"a"},"multi-value")),"-row separately."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"0"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"SUM(expr)")),(0,i.kt)("td",{parentName:"tr",align:null},"Sums numbers."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"0"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"MIN(expr)")),(0,i.kt)("td",{parentName:"tr",align:null},"Takes the minimum of numbers."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"9223372036854775807")," (maximum LONG value)")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"MAX(expr)")),(0,i.kt)("td",{parentName:"tr",align:null},"Takes the maximum of numbers."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"-9223372036854775808")," (minimum LONG value)")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"AVG(expr)")),(0,i.kt)("td",{parentName:"tr",align:null},"Averages numbers."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"0"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"APPROX_COUNT_DISTINCT(expr)")),(0,i.kt)("td",{parentName:"tr",align:null},"Counts distinct values of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," using an approximate algorithm. The ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," can be a regular column or a prebuilt sketch column.",(0,i.kt)("br",null),(0,i.kt)("br",null),"The specific algorithm depends on the value of ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/configuration/#sql"},(0,i.kt)("inlineCode",{parentName:"a"},"druid.sql.approxCountDistinct.function")),". By default, this is ",(0,i.kt)("inlineCode",{parentName:"td"},"APPROX_COUNT_DISTINCT_BUILTIN"),". If the ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/development/extensions-core/datasketches-extension"},"DataSketches extension")," is loaded, you can set it to ",(0,i.kt)("inlineCode",{parentName:"td"},"APPROX_COUNT_DISTINCT_DS_HLL")," or ",(0,i.kt)("inlineCode",{parentName:"td"},"APPROX_COUNT_DISTINCT_DS_THETA"),".",(0,i.kt)("br",null),(0,i.kt)("br",null),"When run on prebuilt sketch columns, the sketch column type must match the implementation of this function. For example: when ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.sql.approxCountDistinct.function")," is set to ",(0,i.kt)("inlineCode",{parentName:"td"},"APPROX_COUNT_DISTINCT_BUILTIN"),", this function runs on prebuilt hyperUnique columns, but not on prebuilt HLLSketchBuild columns."),(0,i.kt)("td",{parentName:"tr",align:null})),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"APPROX_COUNT_DISTINCT_BUILTIN(expr)")),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("em",{parentName:"td"},"Usage note:")," consider using ",(0,i.kt)("inlineCode",{parentName:"td"},"APPROX_COUNT_DISTINCT_DS_HLL")," instead, which offers better accuracy in many cases.",(0,i.kt)("br",null),(0,i.kt)("br",null),"Counts distinct values of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),' using Druid\'s built-in "cardinality" or "hyperUnique" aggregators, which implement a variant of ',(0,i.kt)("a",{parentName:"td",href:"http://algo.inria.fr/flajolet/Publications/FlFuGaMe07.pdf"},"HyperLogLog"),". The ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," can be a string, a number, or a prebuilt hyperUnique column. Results are always approximate, regardless of the value of ",(0,i.kt)("inlineCode",{parentName:"td"},"useApproximateCountDistinct"),"."),(0,i.kt)("td",{parentName:"tr",align:null})),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"APPROX_QUANTILE(expr, probability, [resolution])")),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("em",{parentName:"td"},"Deprecated.")," Use ",(0,i.kt)("inlineCode",{parentName:"td"},"APPROX_QUANTILE_DS")," instead, which provides a superior distribution-independent algorithm with formal error guarantees.",(0,i.kt)("br",null),(0,i.kt)("br",null),"Computes approximate quantiles on numeric or ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/development/extensions-core/approximate-histograms#approximate-histogram-aggregator"},"approxHistogram")," expressions. ",(0,i.kt)("inlineCode",{parentName:"td"},"probability")," should be between 0 and 1, exclusive. ",(0,i.kt)("inlineCode",{parentName:"td"},"resolution")," is the number of centroids to use for the computation. Higher resolutions will give more precise results but also have higher overhead. If not provided, the default resolution is 50. Load the ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/development/extensions-core/approximate-histograms"},"approximate histogram extension")," to use this function."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"NaN"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"APPROX_QUANTILE_FIXED_BUCKETS(expr, probability, numBuckets, lowerLimit, upperLimit, [outlierHandlingMode])")),(0,i.kt)("td",{parentName:"tr",align:null},"Computes approximate quantiles on numeric or ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/development/extensions-core/approximate-histograms#fixed-buckets-histogram"},"fixed buckets histogram")," expressions. ",(0,i.kt)("inlineCode",{parentName:"td"},"probability")," should be between 0 and 1, exclusive. The ",(0,i.kt)("inlineCode",{parentName:"td"},"numBuckets"),", ",(0,i.kt)("inlineCode",{parentName:"td"},"lowerLimit"),", ",(0,i.kt)("inlineCode",{parentName:"td"},"upperLimit"),", and ",(0,i.kt)("inlineCode",{parentName:"td"},"outlierHandlingMode")," parameters are described in the fixed buckets histogram documentation. Load the ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/development/extensions-core/approximate-histograms"},"approximate histogram extension")," to use this function."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"0.0"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"BLOOM_FILTER(expr, numEntries)")),(0,i.kt)("td",{parentName:"tr",align:null},"Computes a bloom filter from values produced by ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),", with ",(0,i.kt)("inlineCode",{parentName:"td"},"numEntries")," maximum number of distinct values before false positive rate increases. 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)("td",{parentName:"tr",align:null},"Empty base64 encoded bloom filter STRING")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"VAR_POP(expr)")),(0,i.kt)("td",{parentName:"tr",align:null},"Computes variance population of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),". See ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/development/extensions-core/stats"},"stats extension")," documentation for additional details."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"0"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"VAR_SAMP(expr)")),(0,i.kt)("td",{parentName:"tr",align:null},"Computes variance sample of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),". See ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/development/extensions-core/stats"},"stats extension")," documentation for additional details."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"0"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"VARIANCE(expr)")),(0,i.kt)("td",{parentName:"tr",align:null},"Computes variance sample of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),". See ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/development/extensions-core/stats"},"stats extension")," documentation for additional details."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"0"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"STDDEV_POP(expr)")),(0,i.kt)("td",{parentName:"tr",align:null},"Computes standard deviation population of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),". See ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/development/extensions-core/stats"},"stats extension")," documentation for additional details."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"0"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"STDDEV_SAMP(expr)")),(0,i.kt)("td",{parentName:"tr",align:null},"Computes standard deviation sample of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),". See ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/development/extensions-core/stats"},"stats extension")," documentation for additional details."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"0"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"STDDEV(expr)")),(0,i.kt)("td",{parentName:"tr",align:null},"Computes standard deviation sample of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),". See ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/development/extensions-core/stats"},"stats extension")," documentation for additional details."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"0"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"EARLIEST(expr)")),(0,i.kt)("td",{parentName:"tr",align:null},"Returns the earliest value of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),", which must be numeric. If ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," comes from a relation with a timestamp column (like ",(0,i.kt)("inlineCode",{parentName:"td"},"__time"),' in a Druid datasource), the "earliest" is taken from the row with the overall earliest non-null value of the timestamp column. If the earliest non-null value of the timestamp column appears in multiple rows, the ',(0,i.kt)("inlineCode",{parentName:"td"},"expr")," may be taken from any of those rows. If ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," does not come from a relation with a timestamp, then it is simply the first value encountered."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"0"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"EARLIEST(expr, maxBytesPerString)")),(0,i.kt)("td",{parentName:"tr",align:null},"Like ",(0,i.kt)("inlineCode",{parentName:"td"},"EARLIEST(expr)"),", but for strings. The ",(0,i.kt)("inlineCode",{parentName:"td"},"maxBytesPerString")," parameter determines how much aggregation space to allocate per string. Strings longer than this limit are truncated. This parameter should be set as low as possible, since high values will lead to wasted memory."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"''"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"EARLIEST_BY(expr, timestampExpr)")),(0,i.kt)("td",{parentName:"tr",align:null},"Returns the earliest value of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),", which must be numeric. The earliest value of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," is taken from the row with the overall earliest non-null value of ",(0,i.kt)("inlineCode",{parentName:"td"},"timestampExpr"),". If the earliest non-null value of ",(0,i.kt)("inlineCode",{parentName:"td"},"timestampExpr")," appears in multiple rows, the ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," may be taken from any of those rows."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"0"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"EARLIEST_BY(expr, timestampExpr, maxBytesPerString)")),(0,i.kt)("td",{parentName:"tr",align:null},"Like ",(0,i.kt)("inlineCode",{parentName:"td"},"EARLIEST_BY(expr, timestampExpr)"),", but for strings. The ",(0,i.kt)("inlineCode",{parentName:"td"},"maxBytesPerString")," parameter determines how much aggregation space to allocate per string. Strings longer than this limit are truncated. This parameter should be set as low as possible, since high values will lead to wasted memory."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"''"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"LATEST(expr)")),(0,i.kt)("td",{parentName:"tr",align:null},"Returns the latest value of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),", which must be numeric. The ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," must come from a relation with a timestamp column (like ",(0,i.kt)("inlineCode",{parentName:"td"},"__time"),' in a Druid datasource) and the "latest" is taken from the row with the overall latest non-null value of the timestamp column. If the latest non-null value of the timestamp column appears in multiple rows, the ',(0,i.kt)("inlineCode",{parentName:"td"},"expr")," may be taken from any of those rows."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"0"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"LATEST(expr, maxBytesPerString)")),(0,i.kt)("td",{parentName:"tr",align:null},"Like ",(0,i.kt)("inlineCode",{parentName:"td"},"LATEST(expr)"),", but for strings. The ",(0,i.kt)("inlineCode",{parentName:"td"},"maxBytesPerString")," parameter determines how much aggregation space to allocate per string. Strings longer than this limit are truncated. This parameter should be set as low as possible, since high values will lead to wasted memory."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"''"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"LATEST_BY(expr, timestampExpr)")),(0,i.kt)("td",{parentName:"tr",align:null},"Returns the latest value of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),", which must be numeric. The latest value of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," is taken from the row with the overall latest non-null value of ",(0,i.kt)("inlineCode",{parentName:"td"},"timestampExpr"),". If the overall latest non-null value of ",(0,i.kt)("inlineCode",{parentName:"td"},"timestampExpr")," appears in multiple rows, the ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," may be taken from any of those rows."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"0"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"LATEST_BY(expr, timestampExpr, maxBytesPerString)")),(0,i.kt)("td",{parentName:"tr",align:null},"Like ",(0,i.kt)("inlineCode",{parentName:"td"},"LATEST_BY(expr, timestampExpr)"),", but for strings. The ",(0,i.kt)("inlineCode",{parentName:"td"},"maxBytesPerString")," parameter determines how much aggregation space to allocate per string. Strings longer than this limit are truncated. This parameter should be set as low as possible, since high values will lead to wasted memory."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"''"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"ANY_VALUE(expr)")),(0,i.kt)("td",{parentName:"tr",align:null},"Returns any value of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," including null. ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," must be numeric. This aggregator can simplify and optimize the performance by returning the first encountered value (including null)"),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"0"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"ANY_VALUE(expr, maxBytesPerString)")),(0,i.kt)("td",{parentName:"tr",align:null},"Like ",(0,i.kt)("inlineCode",{parentName:"td"},"ANY_VALUE(expr)"),", but for strings. The ",(0,i.kt)("inlineCode",{parentName:"td"},"maxBytesPerString")," parameter determines how much aggregation space to allocate per string. Strings longer than this limit are truncated. This parameter should be set as low as possible, since high values will lead to wasted memory."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"''"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"GROUPING(expr, expr...)")),(0,i.kt)("td",{parentName:"tr",align:null},"Returns a number to indicate which groupBy dimension is included in a row, when using ",(0,i.kt)("inlineCode",{parentName:"td"},"GROUPING SETS"),". Refer to ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/querying/aggregations#grouping-aggregator"},"additional documentation")," on how to infer this number."),(0,i.kt)("td",{parentName:"tr",align:null},"N/A")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"ARRAY_AGG(expr, [size])")),(0,i.kt)("td",{parentName:"tr",align:null},"Collects all values of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," into an ARRAY, including null values, with ",(0,i.kt)("inlineCode",{parentName:"td"},"size")," in bytes limit on aggregation size (default of 1024 bytes). If the aggregated array grows larger than the maximum size in bytes, the query will fail. Use of ",(0,i.kt)("inlineCode",{parentName:"td"},"ORDER BY")," within the ",(0,i.kt)("inlineCode",{parentName:"td"},"ARRAY_AGG")," expression is not currently supported, and the ordering of results within the output array may vary depending on processing order."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"ARRAY_AGG(DISTINCT expr, [size])")),(0,i.kt)("td",{parentName:"tr",align:null},"Collects all distinct values of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," into an ARRAY, including null values, with ",(0,i.kt)("inlineCode",{parentName:"td"},"size")," in bytes limit on aggregation size (default of 1024 bytes) per aggregate. If the aggregated array grows larger than the maximum size in bytes, the query will fail. Use of ",(0,i.kt)("inlineCode",{parentName:"td"},"ORDER BY")," within the ",(0,i.kt)("inlineCode",{parentName:"td"},"ARRAY_AGG")," expression is not currently supported, and the ordering of results will be based on the default for the element type."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"ARRAY_CONCAT_AGG(expr, [size])")),(0,i.kt)("td",{parentName:"tr",align:null},"Concatenates all array ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," into a single ARRAY, with ",(0,i.kt)("inlineCode",{parentName:"td"},"size")," in bytes limit on aggregation size (default of 1024 bytes). Input ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," ",(0,i.kt)("em",{parentName:"td"},"must")," be an array. Null ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," will be ignored, but any null values within an ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," ",(0,i.kt)("em",{parentName:"td"},"will")," be included in the resulting array. If the aggregated array grows larger than the maximum size in bytes, the query will fail. Use of ",(0,i.kt)("inlineCode",{parentName:"td"},"ORDER BY")," within the ",(0,i.kt)("inlineCode",{parentName:"td"},"ARRAY_CONCAT_AGG")," expression is not currently supported, and the ordering of results within the output array may vary depending on processing order."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"ARRAY_CONCAT_AGG(DISTINCT expr, [size])")),(0,i.kt)("td",{parentName:"tr",align:null},"Concatenates all distinct values of all array ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," into a single ARRAY, with ",(0,i.kt)("inlineCode",{parentName:"td"},"size")," in bytes limit on aggregation size (default of 1024 bytes) per aggregate. Input ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," ",(0,i.kt)("em",{parentName:"td"},"must")," be an array. Null ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," will be ignored, but any null values within an ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," ",(0,i.kt)("em",{parentName:"td"},"will")," be included in the resulting array. If the aggregated array grows larger than the maximum size in bytes, the query will fail. Use of ",(0,i.kt)("inlineCode",{parentName:"td"},"ORDER BY")," within the ",(0,i.kt)("inlineCode",{parentName:"td"},"ARRAY_CONCAT_AGG")," expression is not currently supported, and the ordering of results will be based on the default for the element type."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"STRING_AGG(expr, separator, [size])")),(0,i.kt)("td",{parentName:"tr",align:null},"Collects all values of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," into a single STRING, ignoring null values. Each value is joined by the ",(0,i.kt)("inlineCode",{parentName:"td"},"separator")," which must be a literal STRING. An optional ",(0,i.kt)("inlineCode",{parentName:"td"},"size")," in bytes can be supplied to limit aggregation size (default of 1024 bytes). If the aggregated string grows larger than the maximum size in bytes, the query will fail. Use of ",(0,i.kt)("inlineCode",{parentName:"td"},"ORDER BY")," within the ",(0,i.kt)("inlineCode",{parentName:"td"},"STRING_AGG")," expression is not currently supported, and the ordering of results within the output string may vary depending on processing order."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"''"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"STRING_AGG(DISTINCT expr, separator, [size])")),(0,i.kt)("td",{parentName:"tr",align:null},"Collects all distinct values of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," into a single STRING, ignoring null values. Each value is joined by the ",(0,i.kt)("inlineCode",{parentName:"td"},"separator")," which must be a literal STRING. An optional ",(0,i.kt)("inlineCode",{parentName:"td"},"size")," in bytes can be supplied to limit aggregation size (default of 1024 bytes). If the aggregated string grows larger than the maximum size in bytes, the query will fail. Use of ",(0,i.kt)("inlineCode",{parentName:"td"},"ORDER BY")," within the ",(0,i.kt)("inlineCode",{parentName:"td"},"STRING_AGG")," expression is not currently supported, and the ordering of results will be based on the default ",(0,i.kt)("inlineCode",{parentName:"td"},"STRING")," ordering."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"''"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"BIT_AND(expr)")),(0,i.kt)("td",{parentName:"tr",align:null},"Performs a bitwise AND operation on all input values."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"0"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"BIT_OR(expr)")),(0,i.kt)("td",{parentName:"tr",align:null},"Performs a bitwise OR operation on all input values."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"0"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"BIT_XOR(expr)")),(0,i.kt)("td",{parentName:"tr",align:null},"Performs a bitwise XOR operation on all input values."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"null")," if ",(0,i.kt)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull=false"),", otherwise ",(0,i.kt)("inlineCode",{parentName:"td"},"0"))))),(0,i.kt)("h2",{id:"sketch-functions"},"Sketch functions"),(0,i.kt)("p",null,"These functions create sketch objects that you can use to perform fast, approximate analyses.\nFor advice on choosing approximate aggregation functions, check out our ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/querying/aggregations#approx"},"approximate aggregations documentation"),".\nTo operate on sketch objects, also see the ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/querying/sql-scalar#sketch-functions"},"DataSketches post aggregator functions"),"."),(0,i.kt)("h3",{id:"hll-sketch-functions"},"HLL sketch functions"),(0,i.kt)("p",null,"Load the ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/development/extensions-core/datasketches-extension"},"DataSketches extension")," to use the following 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},"Notes"),(0,i.kt)("th",{parentName:"tr",align:null},"Default"))),(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"},"APPROX_COUNT_DISTINCT_DS_HLL(expr, [lgK, tgtHllType])")),(0,i.kt)("td",{parentName:"tr",align:null},"Counts distinct values of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),", which can be a regular column or an ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/development/extensions-core/datasketches-hll"},"HLL sketch")," column. Results are always approximate, regardless of the value of ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/querying/sql-query-context"},(0,i.kt)("inlineCode",{parentName:"a"},"useApproximateCountDistinct")),". The ",(0,i.kt)("inlineCode",{parentName:"td"},"lgK")," and ",(0,i.kt)("inlineCode",{parentName:"td"},"tgtHllType")," parameters here are, like the equivalents in the ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/development/extensions-core/datasketches-hll#aggregators"},"aggregator"),", described in the HLL sketch documentation. See also ",(0,i.kt)("inlineCode",{parentName:"td"},"COUNT(DISTINCT expr)"),"."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"0"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"DS_HLL(expr, [lgK, tgtHllType])")),(0,i.kt)("td",{parentName:"tr",align:null},"Creates an ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/development/extensions-core/datasketches-hll"},"HLL sketch")," on the values of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),", which can be a regular column or a column containing HLL sketches. The ",(0,i.kt)("inlineCode",{parentName:"td"},"lgK")," and ",(0,i.kt)("inlineCode",{parentName:"td"},"tgtHllType")," parameters are described in the HLL sketch documentation."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"'0'")," (STRING)")))),(0,i.kt)("h3",{id:"theta-sketch-functions"},"Theta sketch functions"),(0,i.kt)("p",null,"Load the ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/development/extensions-core/datasketches-extension"},"DataSketches extension")," to use the following 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},"Notes"),(0,i.kt)("th",{parentName:"tr",align:null},"Default"))),(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"},"APPROX_COUNT_DISTINCT_DS_THETA(expr, [size])")),(0,i.kt)("td",{parentName:"tr",align:null},"Counts distinct values of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),", which can be a regular column or a ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/development/extensions-core/datasketches-theta"},"Theta sketch")," column. Results are always approximate, regardless of the value of ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/querying/sql-query-context"},(0,i.kt)("inlineCode",{parentName:"a"},"useApproximateCountDistinct")),". The ",(0,i.kt)("inlineCode",{parentName:"td"},"size")," parameter is described in the Theta sketch documentation. See also ",(0,i.kt)("inlineCode",{parentName:"td"},"COUNT(DISTINCT expr)"),"."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"0"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"DS_THETA(expr, [size])")),(0,i.kt)("td",{parentName:"tr",align:null},"Creates a ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/development/extensions-core/datasketches-theta"},"Theta sketch")," on the values of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),", which can be a regular column or a column containing Theta sketches. The ",(0,i.kt)("inlineCode",{parentName:"td"},"size")," parameter is described in the Theta sketch documentation."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"'0.0'")," (STRING)")))),(0,i.kt)("h3",{id:"quantiles-sketch-functions"},"Quantiles sketch functions"),(0,i.kt)("p",null,"Load the ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/development/extensions-core/datasketches-extension"},"DataSketches extension")," to use the following 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},"Notes"),(0,i.kt)("th",{parentName:"tr",align:null},"Default"))),(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"},"APPROX_QUANTILE_DS(expr, probability, [k])")),(0,i.kt)("td",{parentName:"tr",align:null},"Computes approximate quantiles on numeric or ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/development/extensions-core/datasketches-quantiles"},"Quantiles sketch")," expressions. The ",(0,i.kt)("inlineCode",{parentName:"td"},"probability")," value should be between 0 and 1, exclusive. The ",(0,i.kt)("inlineCode",{parentName:"td"},"k")," parameter is described in the Quantiles sketch documentation.",(0,i.kt)("br",null),(0,i.kt)("br",null),"See the ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/querying/sql-translation#approximations"},"known issue")," with this function."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"NaN"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"DS_QUANTILES_SKETCH(expr, [k])")),(0,i.kt)("td",{parentName:"tr",align:null},"Creates a ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/development/extensions-core/datasketches-quantiles"},"Quantiles sketch")," on the values of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),", which can be a regular column or a column containing quantiles sketches. The ",(0,i.kt)("inlineCode",{parentName:"td"},"k")," parameter is described in the Quantiles sketch documentation.",(0,i.kt)("br",null),(0,i.kt)("br",null),"See the ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/querying/sql-translation#approximations"},"known issue")," with this function."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"'0'")," (STRING)")))),(0,i.kt)("h3",{id:"tuple-sketch-functions"},"Tuple sketch functions"),(0,i.kt)("p",null,"Load the ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/development/extensions-core/datasketches-extension"},"DataSketches extension")," to use the following 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},"Notes"),(0,i.kt)("th",{parentName:"tr",align:null},"Default"))),(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"},"DS_TUPLE_DOUBLES(expr, [nominalEntries])")),(0,i.kt)("td",{parentName:"tr",align:null},"Creates a ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/development/extensions-core/datasketches-tuple"},"Tuple sketch")," on the values of ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," which is a column containing Tuple sketches which contain an array of double values as their Summary Objects. The ",(0,i.kt)("inlineCode",{parentName:"td"},"nominalEntries")," override parameter is optional and described in the Tuple sketch documentation."),(0,i.kt)("td",{parentName:"tr",align:null})),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"DS_TUPLE_DOUBLES(dimensionColumnExpr, metricColumnExpr, ..., [nominalEntries])")),(0,i.kt)("td",{parentName:"tr",align:null},"Creates a ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/development/extensions-core/datasketches-tuple"},"Tuple sketch")," which contains an array of double values as its Summary Object based on the dimension value of ",(0,i.kt)("inlineCode",{parentName:"td"},"dimensionColumnExpr")," and the numeric metric values contained in one or more ",(0,i.kt)("inlineCode",{parentName:"td"},"metricColumnExpr")," columns. If the last value of the array is a numeric literal, Druid assumes that the value is an override parameter for ",(0,i.kt)("a",{parentName:"td",href:"/docs/latest/development/extensions-core/datasketches-tuple"},"nominal entries"),"."),(0,i.kt)("td",{parentName:"tr",align:null})))),(0,i.kt)("h3",{id:"t-digest-sketch-functions"},"T-Digest sketch functions"),(0,i.kt)("p",null,"Load the T-Digest extension to use the following functions. See the ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/development/extensions-contrib/tdigestsketch-quantiles"},"T-Digest extension")," for additional details and for more information on these 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},"Notes"),(0,i.kt)("th",{parentName:"tr",align:null},"Default"))),(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"},"TDIGEST_QUANTILE(expr, quantileFraction, [compression])")),(0,i.kt)("td",{parentName:"tr",align:null},"Builds a T-Digest sketch on values produced by ",(0,i.kt)("inlineCode",{parentName:"td"},"expr")," and returns the value for the quantile. Compression parameter (default value 100) determines the accuracy and size of the sketch. Higher compression means higher accuracy but more space to store sketches."),(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"Double.NaN"))),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},(0,i.kt)("inlineCode",{parentName:"td"},"TDIGEST_GENERATE_SKETCH(expr, [compression])")),(0,i.kt)("td",{parentName:"tr",align:null},"Builds a T-Digest sketch on values produced by ",(0,i.kt)("inlineCode",{parentName:"td"},"expr"),". Compression parameter (default value 100) determines the accuracy and size of the sketch Higher compression means higher accuracy but more space to store sketches."),(0,i.kt)("td",{parentName:"tr",align:null},"Empty base64 encoded T-Digest sketch STRING")))))}N.isMDXComponent=!0}}]);