blob: 0dbbab4c304811067c0fb5470b9935bbb15edf46 [file] [log] [blame]
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[7652],{15680:(e,a,t)=>{t.d(a,{xA:()=>s,yg:()=>y});var n=t(96540);function r(e,a,t){return a in e?Object.defineProperty(e,a,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[a]=t,e}function l(e,a){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);a&&(n=n.filter((function(a){return Object.getOwnPropertyDescriptor(e,a).enumerable}))),t.push.apply(t,n)}return t}function i(e){for(var a=1;a<arguments.length;a++){var t=null!=arguments[a]?arguments[a]:{};a%2?l(Object(t),!0).forEach((function(a){r(e,a,t[a])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):l(Object(t)).forEach((function(a){Object.defineProperty(e,a,Object.getOwnPropertyDescriptor(t,a))}))}return e}function g(e,a){if(null==e)return{};var t,n,r=function(e,a){if(null==e)return{};var t,n,r={},l=Object.keys(e);for(n=0;n<l.length;n++)t=l[n],a.indexOf(t)>=0||(r[t]=e[t]);return r}(e,a);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n<l.length;n++)t=l[n],a.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(r[t]=e[t])}return r}var o=n.createContext({}),u=function(e){var a=n.useContext(o),t=a;return e&&(t="function"==typeof e?e(a):i(i({},a),e)),t},s=function(e){var a=u(e.components);return n.createElement(o.Provider,{value:a},e.children)},p="mdxType",d={inlineCode:"code",wrapper:function(e){var a=e.children;return n.createElement(n.Fragment,{},a)}},m=n.forwardRef((function(e,a){var t=e.components,r=e.mdxType,l=e.originalType,o=e.parentName,s=g(e,["components","mdxType","originalType","parentName"]),p=u(t),m=r,y=p["".concat(o,".").concat(m)]||p[m]||d[m]||l;return t?n.createElement(y,i(i({ref:a},s),{},{components:t})):n.createElement(y,i({ref:a},s))}));function y(e,a){var t=arguments,r=a&&a.mdxType;if("string"==typeof e||r){var l=t.length,i=new Array(l);i[0]=m;var g={};for(var o in a)hasOwnProperty.call(a,o)&&(g[o]=a[o]);g.originalType=e,g[p]="string"==typeof e?e:r,i[1]=g;for(var u=2;u<l;u++)i[u]=t[u];return n.createElement.apply(null,i)}return n.createElement.apply(null,t)}m.displayName="MDXCreateElement"},19258:(e,a,t)=>{t.r(a),t.d(a,{assets:()=>s,contentTitle:()=>o,default:()=>y,frontMatter:()=>g,metadata:()=>u,toc:()=>p});var n=t(58168),r=t(98587),l=(t(96540),t(15680)),i=["components"],g={id:"aggregations",title:"Aggregations"},o=void 0,u={unversionedId:"querying/aggregations",id:"querying/aggregations",title:"Aggregations",description:"\x3c!--",source:"@site/docs/latest/querying/aggregations.md",sourceDirName:"querying",slug:"/querying/aggregations",permalink:"/docs/latest/querying/aggregations",draft:!1,tags:[],version:"current",frontMatter:{id:"aggregations",title:"Aggregations"},sidebar:"docs",previous:{title:"Dimensions",permalink:"/docs/latest/querying/dimensionspecs"},next:{title:"Post-aggregations",permalink:"/docs/latest/querying/post-aggregations"}},s={},p=[{value:"Exact aggregations",id:"exact-aggregations",level:2},{value:"Count aggregator",id:"count-aggregator",level:3},{value:"Sum aggregators",id:"sum-aggregators",level:3},{value:"<code>longSum</code> aggregator",id:"longsum-aggregator",level:4},{value:"<code>doubleSum</code> aggregator",id:"doublesum-aggregator",level:4},{value:"<code>floatSum</code> aggregator",id:"floatsum-aggregator",level:4},{value:"Min and max aggregators",id:"min-and-max-aggregators",level:3},{value:"<code>doubleMin</code> aggregator",id:"doublemin-aggregator",level:4},{value:"<code>doubleMax</code> aggregator",id:"doublemax-aggregator",level:4},{value:"<code>floatMin</code> aggregator",id:"floatmin-aggregator",level:4},{value:"<code>floatMax</code> aggregator",id:"floatmax-aggregator",level:4},{value:"<code>longMin</code> aggregator",id:"longmin-aggregator",level:4},{value:"<code>longMax</code> aggregator",id:"longmax-aggregator",level:4},{value:"<code>doubleMean</code> aggregator",id:"doublemean-aggregator",level:3},{value:"First and last aggregators",id:"first-and-last-aggregators",level:3},{value:"Numeric first and last aggregators",id:"numeric-first-and-last-aggregators",level:4},{value:"<code>doubleFirst</code> aggregator",id:"doublefirst-aggregator",level:5},{value:"<code>doubleLast</code> aggregator",id:"doublelast-aggregator",level:5},{value:"<code>floatFirst</code> aggregator",id:"floatfirst-aggregator",level:5},{value:"<code>floatLast</code> aggregator",id:"floatlast-aggregator",level:5},{value:"<code>longFirst</code> aggregator",id:"longfirst-aggregator",level:5},{value:"<code>longLast</code> aggregator",id:"longlast-aggregator",level:5},{value:"String first and last aggregators",id:"string-first-and-last-aggregators",level:4},{value:"<code>stringFirst</code> aggregator",id:"stringfirst-aggregator",level:4},{value:"<code>stringLast</code> aggregator",id:"stringlast-aggregator",level:4},{value:"ANY aggregators",id:"any-aggregators",level:3},{value:"Numeric any aggregators",id:"numeric-any-aggregators",level:4},{value:"<code>doubleAny</code> aggregator",id:"doubleany-aggregator",level:5},{value:"<code>floatAny</code> aggregator",id:"floatany-aggregator",level:5},{value:"<code>longAny</code> aggregator",id:"longany-aggregator",level:5},{value:"<code>stringAny</code> aggregator",id:"stringany-aggregator",level:4},{value:"Approximate aggregations",id:"approximate-aggregations",level:2},{value:"Count distinct",id:"count-distinct",level:3},{value:"Apache DataSketches Theta Sketch",id:"apache-datasketches-theta-sketch",level:4},{value:"Apache DataSketches HLL Sketch",id:"apache-datasketches-hll-sketch",level:4},{value:"Cardinality, hyperUnique",id:"cardinality-hyperunique",level:4},{value:"Multi-column handling",id:"multi-column-handling",level:5},{value:"Histograms and quantiles",id:"histograms-and-quantiles",level:3},{value:"DataSketches Quantiles Sketch",id:"datasketches-quantiles-sketch",level:4},{value:"Moments Sketch (Experimental)",id:"moments-sketch-experimental",level:4},{value:"Fixed Buckets Histogram",id:"fixed-buckets-histogram",level:4},{value:"Approximate Histogram (deprecated)",id:"approximate-histogram-deprecated",level:4},{value:"Expression aggregations",id:"expression-aggregations",level:2},{value:"Expression aggregator",id:"expression-aggregator",level:3},{value:"Example: a &quot;count&quot; aggregator",id:"example-a-count-aggregator",level:4},{value:"Example: a &quot;sum&quot; aggregator",id:"example-a-sum-aggregator",level:4},{value:"Example: a &quot;distinct array element&quot; aggregator, sorted by array_length",id:"example-a-distinct-array-element-aggregator-sorted-by-array_length",level:4},{value:"Example: an &quot;approximate count&quot; aggregator using the built-in hyper-unique",id:"example-an-approximate-count-aggregator-using-the-built-in-hyper-unique",level:4},{value:"JavaScript aggregator",id:"javascript-aggregator",level:3},{value:"Example",id:"example",level:4},{value:"Miscellaneous aggregations",id:"miscellaneous-aggregations",level:2},{value:"Filtered aggregator",id:"filtered-aggregator",level:3},{value:"Grouping aggregator",id:"grouping-aggregator",level:3}],d={toc:p},m="wrapper";function y(e){var a=e.components,t=(0,r.A)(e,i);return(0,l.yg)(m,(0,n.A)({},d,t,{components:a,mdxType:"MDXLayout"}),(0,l.yg)("admonition",{type:"info"},(0,l.yg)("p",{parentName:"admonition"},"Apache Druid supports two query languages: ",(0,l.yg)("a",{parentName:"p",href:"/docs/latest/querying/sql"},"Druid SQL")," and ",(0,l.yg)("a",{parentName:"p",href:"/docs/latest/querying/"},"native queries"),".\nThis document describes the native\nlanguage. For information about aggregators available in SQL, refer to the\n",(0,l.yg)("a",{parentName:"p",href:"/docs/latest/querying/sql-aggregations"},"SQL documentation"),".")),(0,l.yg)("p",null,"You can use aggregations:"),(0,l.yg)("ul",null,(0,l.yg)("li",{parentName:"ul"},"in the ingestion spec during ingestion to summarize data before it enters Apache Druid."),(0,l.yg)("li",{parentName:"ul"},"at query time to summarize result data.")),(0,l.yg)("p",null,"The following sections list the available aggregate functions. Unless otherwise noted, aggregations are available at both ingestion and query time."),(0,l.yg)("h2",{id:"exact-aggregations"},"Exact aggregations"),(0,l.yg)("h3",{id:"count-aggregator"},"Count aggregator"),(0,l.yg)("p",null,(0,l.yg)("inlineCode",{parentName:"p"},"count")," computes the count of Druid rows that match the filters."),(0,l.yg)("table",null,(0,l.yg)("thead",{parentName:"table"},(0,l.yg)("tr",{parentName:"thead"},(0,l.yg)("th",{parentName:"tr",align:null},"Property"),(0,l.yg)("th",{parentName:"tr",align:null},"Description"),(0,l.yg)("th",{parentName:"tr",align:null},"Required"))),(0,l.yg)("tbody",{parentName:"table"},(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"type")),(0,l.yg)("td",{parentName:"tr",align:null},'Must be "count".'),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"name")),(0,l.yg)("td",{parentName:"tr",align:null},"Output name of the aggregator"),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")))),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{ "type" : "count", "name" : "count" }\n')),(0,l.yg)("p",null,"The ",(0,l.yg)("inlineCode",{parentName:"p"},"count")," aggregator counts the number of Druid rows, which does not always reflect the number of raw events ingested.\nThis is because Druid can be configured to roll up data at ingestion time. To\ncount the number of ingested rows of data, include a ",(0,l.yg)("inlineCode",{parentName:"p"},"count")," aggregator at ingestion time and a ",(0,l.yg)("inlineCode",{parentName:"p"},"longSum")," aggregator at\nquery time."),(0,l.yg)("h3",{id:"sum-aggregators"},"Sum aggregators"),(0,l.yg)("table",null,(0,l.yg)("thead",{parentName:"table"},(0,l.yg)("tr",{parentName:"thead"},(0,l.yg)("th",{parentName:"tr",align:null},"Property"),(0,l.yg)("th",{parentName:"tr",align:null},"Description"),(0,l.yg)("th",{parentName:"tr",align:null},"Required"))),(0,l.yg)("tbody",{parentName:"table"},(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"type")),(0,l.yg)("td",{parentName:"tr",align:null},'Must be "longSum", "doubleSum", or "floatSum".'),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"name")),(0,l.yg)("td",{parentName:"tr",align:null},"Output name for the summed value."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"fieldName")),(0,l.yg)("td",{parentName:"tr",align:null},"Name of the input column to sum over."),(0,l.yg)("td",{parentName:"tr",align:null},"No. You must specify ",(0,l.yg)("inlineCode",{parentName:"td"},"fieldName")," or ",(0,l.yg)("inlineCode",{parentName:"td"},"expression"),".")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"expression")),(0,l.yg)("td",{parentName:"tr",align:null},"You can specify an inline ",(0,l.yg)("a",{parentName:"td",href:"/docs/latest/querying/math-expr"},"expression")," as an alternative to ",(0,l.yg)("inlineCode",{parentName:"td"},"fieldName"),"."),(0,l.yg)("td",{parentName:"tr",align:null},"No. You must specify ",(0,l.yg)("inlineCode",{parentName:"td"},"fieldName")," or ",(0,l.yg)("inlineCode",{parentName:"td"},"expression"),".")))),(0,l.yg)("h4",{id:"longsum-aggregator"},(0,l.yg)("inlineCode",{parentName:"h4"},"longSum")," aggregator"),(0,l.yg)("p",null,"Computes the sum of values as a 64-bit, signed integer."),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{ "type" : "longSum", "name" : "sumLong", "fieldName" : "aLong" }\n')),(0,l.yg)("h4",{id:"doublesum-aggregator"},(0,l.yg)("inlineCode",{parentName:"h4"},"doubleSum")," aggregator"),(0,l.yg)("p",null,"Computes and stores the sum of values as a 64-bit floating point value. Similar to ",(0,l.yg)("inlineCode",{parentName:"p"},"longSum"),"."),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{ "type" : "doubleSum", "name" : "sumDouble", "fieldName" : "aDouble" }\n')),(0,l.yg)("h4",{id:"floatsum-aggregator"},(0,l.yg)("inlineCode",{parentName:"h4"},"floatSum")," aggregator"),(0,l.yg)("p",null,"Computes and stores the sum of values as a 32-bit floating point value. Similar to ",(0,l.yg)("inlineCode",{parentName:"p"},"longSum")," and ",(0,l.yg)("inlineCode",{parentName:"p"},"doubleSum"),"."),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{ "type" : "floatSum", "name" : "sumFloat", "fieldName" : "aFloat" }\n')),(0,l.yg)("h3",{id:"min-and-max-aggregators"},"Min and max aggregators"),(0,l.yg)("table",null,(0,l.yg)("thead",{parentName:"table"},(0,l.yg)("tr",{parentName:"thead"},(0,l.yg)("th",{parentName:"tr",align:null},"Property"),(0,l.yg)("th",{parentName:"tr",align:null},"Description"),(0,l.yg)("th",{parentName:"tr",align:null},"Required"))),(0,l.yg)("tbody",{parentName:"table"},(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"type")),(0,l.yg)("td",{parentName:"tr",align:null},'Must be "doubleMin", "doubleMax", "floatMin", "floatMax", "longMin", or "longMax".'),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"name")),(0,l.yg)("td",{parentName:"tr",align:null},"Output name for the min or max value."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"fieldName")),(0,l.yg)("td",{parentName:"tr",align:null},"Name of the input column to compute the minimum or maximum value over."),(0,l.yg)("td",{parentName:"tr",align:null},"No. You must specify ",(0,l.yg)("inlineCode",{parentName:"td"},"fieldName")," or ",(0,l.yg)("inlineCode",{parentName:"td"},"expression"),".")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"expression")),(0,l.yg)("td",{parentName:"tr",align:null},"You can specify an inline ",(0,l.yg)("a",{parentName:"td",href:"/docs/latest/querying/math-expr"},"expression")," as an alternative to ",(0,l.yg)("inlineCode",{parentName:"td"},"fieldName"),"."),(0,l.yg)("td",{parentName:"tr",align:null},"No. You must specify ",(0,l.yg)("inlineCode",{parentName:"td"},"fieldName")," or ",(0,l.yg)("inlineCode",{parentName:"td"},"expression"),".")))),(0,l.yg)("h4",{id:"doublemin-aggregator"},(0,l.yg)("inlineCode",{parentName:"h4"},"doubleMin")," aggregator"),(0,l.yg)("p",null,(0,l.yg)("inlineCode",{parentName:"p"},"doubleMin")," computes the minimum of all input values and null if ",(0,l.yg)("inlineCode",{parentName:"p"},"druid.generic.useDefaultValueForNull")," is false or Double.POSITIVE_INFINITY if true."),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{ "type" : "doubleMin", "name" : "maxDouble", "fieldName" : "aDouble" }\n')),(0,l.yg)("h4",{id:"doublemax-aggregator"},(0,l.yg)("inlineCode",{parentName:"h4"},"doubleMax")," aggregator"),(0,l.yg)("p",null,(0,l.yg)("inlineCode",{parentName:"p"},"doubleMax")," computes the maximum of all input values and null if ",(0,l.yg)("inlineCode",{parentName:"p"},"druid.generic.useDefaultValueForNull")," is false or Double.NEGATIVE_INFINITY if true."),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{ "type" : "doubleMax", "name" : "minDouble", "fieldName" : "aDouble" }\n')),(0,l.yg)("h4",{id:"floatmin-aggregator"},(0,l.yg)("inlineCode",{parentName:"h4"},"floatMin")," aggregator"),(0,l.yg)("p",null,(0,l.yg)("inlineCode",{parentName:"p"},"floatMin")," computes the minimum of all input values and null if ",(0,l.yg)("inlineCode",{parentName:"p"},"druid.generic.useDefaultValueForNull")," is false or Float.POSITIVE_INFINITY if true."),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{ "type" : "floatMin", "name" : "minFloat", "fieldName" : "aFloat" }\n')),(0,l.yg)("h4",{id:"floatmax-aggregator"},(0,l.yg)("inlineCode",{parentName:"h4"},"floatMax")," aggregator"),(0,l.yg)("p",null,(0,l.yg)("inlineCode",{parentName:"p"},"floatMax")," computes the maximum of all input values and null if ",(0,l.yg)("inlineCode",{parentName:"p"},"druid.generic.useDefaultValueForNull")," is false or Float.NEGATIVE_INFINITY if true."),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{ "type" : "floatMax", "name" : "maxFloat", "fieldName" : "aFloat" }\n')),(0,l.yg)("h4",{id:"longmin-aggregator"},(0,l.yg)("inlineCode",{parentName:"h4"},"longMin")," aggregator"),(0,l.yg)("p",null,(0,l.yg)("inlineCode",{parentName:"p"},"longMin")," computes the minimum of all input values and null if ",(0,l.yg)("inlineCode",{parentName:"p"},"druid.generic.useDefaultValueForNull")," is false or Long.MAX_VALUE if true."),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{ "type" : "longMin", "name" : "minLong", "fieldName" : "aLong" }\n')),(0,l.yg)("h4",{id:"longmax-aggregator"},(0,l.yg)("inlineCode",{parentName:"h4"},"longMax")," aggregator"),(0,l.yg)("p",null,(0,l.yg)("inlineCode",{parentName:"p"},"longMax")," computes the maximum of all metric values and null if ",(0,l.yg)("inlineCode",{parentName:"p"},"druid.generic.useDefaultValueForNull")," is false or Long.MIN_VALUE if true."),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{ "type" : "longMax", "name" : "maxLong", "fieldName" : "aLong" }\n')),(0,l.yg)("h3",{id:"doublemean-aggregator"},(0,l.yg)("inlineCode",{parentName:"h3"},"doubleMean")," aggregator"),(0,l.yg)("p",null,"Computes and returns the arithmetic mean of a column's values as a 64-bit floating point value. "),(0,l.yg)("table",null,(0,l.yg)("thead",{parentName:"table"},(0,l.yg)("tr",{parentName:"thead"},(0,l.yg)("th",{parentName:"tr",align:null},"Property"),(0,l.yg)("th",{parentName:"tr",align:null},"Description"),(0,l.yg)("th",{parentName:"tr",align:null},"Required"))),(0,l.yg)("tbody",{parentName:"table"},(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"type")),(0,l.yg)("td",{parentName:"tr",align:null},'Must be "doubleMean".'),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"name")),(0,l.yg)("td",{parentName:"tr",align:null},"Output name for the mean value."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"fieldName")),(0,l.yg)("td",{parentName:"tr",align:null},"Name of the input column to compute the arithmetic mean value over."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")))),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{ "type" : "doubleMean", "name" : "aMean", "fieldName" : "aDouble" }\n')),(0,l.yg)("p",null,(0,l.yg)("inlineCode",{parentName:"p"},"doubleMean")," is a query time aggregator only. It is not available for indexing. To accomplish mean aggregation on ingestion, refer to the ",(0,l.yg)("a",{parentName:"p",href:"/docs/latest/development/extensions-core/datasketches-quantiles#aggregator"},"Quantiles aggregator")," from the DataSketches extension."),(0,l.yg)("h3",{id:"first-and-last-aggregators"},"First and last aggregators"),(0,l.yg)("p",null,"The first and last aggregators determine the metric values that respectively correspond to the earliest and latest values of a time column."),(0,l.yg)("p",null,"Queries with first or last aggregators on a segment created with rollup return the rolled up value, not the first or last value from the\nraw ingested data. The ",(0,l.yg)("inlineCode",{parentName:"p"},"timeColumn")," will get ignored in such cases, and the aggregation will use the original value of the time column\nstored at the time the segment was created."),(0,l.yg)("h4",{id:"numeric-first-and-last-aggregators"},"Numeric first and last aggregators"),(0,l.yg)("table",null,(0,l.yg)("thead",{parentName:"table"},(0,l.yg)("tr",{parentName:"thead"},(0,l.yg)("th",{parentName:"tr",align:null},"Property"),(0,l.yg)("th",{parentName:"tr",align:null},"Description"),(0,l.yg)("th",{parentName:"tr",align:null},"Required"))),(0,l.yg)("tbody",{parentName:"table"},(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"type")),(0,l.yg)("td",{parentName:"tr",align:null},'Must be "doubleFirst", "doubleLast", "floatFirst", "floatLast", "longFirst", "longLast".'),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"name")),(0,l.yg)("td",{parentName:"tr",align:null},"Output name for the first or last value."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"fieldName")),(0,l.yg)("td",{parentName:"tr",align:null},"Name of the input column to compute the first or last value over."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"timeColumn")),(0,l.yg)("td",{parentName:"tr",align:null},"Name of the input column to use for time values. Must be a LONG typed column."),(0,l.yg)("td",{parentName:"tr",align:null},"No. Defaults to ",(0,l.yg)("inlineCode",{parentName:"td"},"__time"),".")))),(0,l.yg)("h5",{id:"doublefirst-aggregator"},(0,l.yg)("inlineCode",{parentName:"h5"},"doubleFirst")," aggregator"),(0,l.yg)("p",null,(0,l.yg)("inlineCode",{parentName:"p"},"doubleFirst")," computes the input value with the minimum value for time column or 0 in default mode, or ",(0,l.yg)("inlineCode",{parentName:"p"},"null")," in SQL-compatible mode if no row exists."),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{\n "type" : "doubleFirst",\n "name" : "firstDouble",\n "fieldName" : "aDouble"\n}\n')),(0,l.yg)("h5",{id:"doublelast-aggregator"},(0,l.yg)("inlineCode",{parentName:"h5"},"doubleLast")," aggregator"),(0,l.yg)("p",null,(0,l.yg)("inlineCode",{parentName:"p"},"doubleLast")," computes the input value with the maximum value for time column or 0 in default mode, or ",(0,l.yg)("inlineCode",{parentName:"p"},"null")," in SQL-compatible mode if no row exists."),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{\n "type" : "doubleLast",\n "name" : "lastDouble",\n "fieldName" : "aDouble",\n "timeColumn" : "longTime"\n}\n')),(0,l.yg)("h5",{id:"floatfirst-aggregator"},(0,l.yg)("inlineCode",{parentName:"h5"},"floatFirst")," aggregator"),(0,l.yg)("p",null,(0,l.yg)("inlineCode",{parentName:"p"},"floatFirst")," computes the input value with the minimum value for time column or 0 in default mode, or ",(0,l.yg)("inlineCode",{parentName:"p"},"null")," in SQL-compatible mode if no row exists."),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{\n "type" : "floatFirst",\n "name" : "firstFloat",\n "fieldName" : "aFloat"\n}\n')),(0,l.yg)("h5",{id:"floatlast-aggregator"},(0,l.yg)("inlineCode",{parentName:"h5"},"floatLast")," aggregator"),(0,l.yg)("p",null,(0,l.yg)("inlineCode",{parentName:"p"},"floatLast")," computes the metric value with the maximum value for time column or 0 in default mode, or ",(0,l.yg)("inlineCode",{parentName:"p"},"null")," in SQL-compatible mode if no row exists."),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{\n "type" : "floatLast",\n "name" : "lastFloat",\n "fieldName" : "aFloat"\n}\n')),(0,l.yg)("h5",{id:"longfirst-aggregator"},(0,l.yg)("inlineCode",{parentName:"h5"},"longFirst")," aggregator"),(0,l.yg)("p",null,(0,l.yg)("inlineCode",{parentName:"p"},"longFirst")," computes the metric value with the minimum value for time column or 0 in default mode, or ",(0,l.yg)("inlineCode",{parentName:"p"},"null")," in SQL-compatible mode if no row exists."),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{\n "type" : "longFirst",\n "name" : "firstLong",\n "fieldName" : "aLong"\n}\n')),(0,l.yg)("h5",{id:"longlast-aggregator"},(0,l.yg)("inlineCode",{parentName:"h5"},"longLast")," aggregator"),(0,l.yg)("p",null,(0,l.yg)("inlineCode",{parentName:"p"},"longLast")," computes the metric value with the maximum value for time column or 0 in default mode, or ",(0,l.yg)("inlineCode",{parentName:"p"},"null")," in SQL-compatible mode if no row exists."),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{\n "type" : "longLast",\n "name" : "lastLong",\n "fieldName" : "aLong",\n "timeColumn" : "longTime"\n}\n')),(0,l.yg)("h4",{id:"string-first-and-last-aggregators"},"String first and last aggregators"),(0,l.yg)("table",null,(0,l.yg)("thead",{parentName:"table"},(0,l.yg)("tr",{parentName:"thead"},(0,l.yg)("th",{parentName:"tr",align:null},"Property"),(0,l.yg)("th",{parentName:"tr",align:null},"Description"),(0,l.yg)("th",{parentName:"tr",align:null},"Required"))),(0,l.yg)("tbody",{parentName:"table"},(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"type")),(0,l.yg)("td",{parentName:"tr",align:null},'Must be "stringFirst", "stringLast".'),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"name")),(0,l.yg)("td",{parentName:"tr",align:null},"Output name for the first or last value."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"fieldName")),(0,l.yg)("td",{parentName:"tr",align:null},"Name of the input column to compute the first or last value over."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"timeColumn")),(0,l.yg)("td",{parentName:"tr",align:null},"Name of the input column to use for time values. Must be a LONG typed column."),(0,l.yg)("td",{parentName:"tr",align:null},"No. Defaults to ",(0,l.yg)("inlineCode",{parentName:"td"},"__time"),".")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"maxStringBytes")),(0,l.yg)("td",{parentName:"tr",align:null},"Maximum size of string values to accumulate when computing the first or last value per group. Values longer than this will be truncated."),(0,l.yg)("td",{parentName:"tr",align:null},"No. Defaults to 1024.")))),(0,l.yg)("h4",{id:"stringfirst-aggregator"},(0,l.yg)("inlineCode",{parentName:"h4"},"stringFirst")," aggregator"),(0,l.yg)("p",null,(0,l.yg)("inlineCode",{parentName:"p"},"stringFirst")," computes the metric value with the minimum value for time column or ",(0,l.yg)("inlineCode",{parentName:"p"},"null")," if no row exists."),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{\n "type" : "stringFirst",\n "name" : "firstString",\n "fieldName" : "aString",\n "maxStringBytes" : 2048,\n "timeColumn" : "longTime"\n}\n')),(0,l.yg)("h4",{id:"stringlast-aggregator"},(0,l.yg)("inlineCode",{parentName:"h4"},"stringLast")," aggregator"),(0,l.yg)("p",null,(0,l.yg)("inlineCode",{parentName:"p"},"stringLast")," computes the metric value with the maximum value for time column or ",(0,l.yg)("inlineCode",{parentName:"p"},"null")," if no row exists."),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{\n "type" : "stringLast",\n "name" : "lastString",\n "fieldName" : "aString"\n}\n')),(0,l.yg)("h3",{id:"any-aggregators"},"ANY aggregators"),(0,l.yg)("p",null,"(Double/Float/Long/String) ANY aggregator cannot be used in ingestion spec, and should only be specified as part of queries."),(0,l.yg)("p",null,"Returns any value including null. This aggregator can simplify and optimize the performance by returning the first encountered value (including null)"),(0,l.yg)("h4",{id:"numeric-any-aggregators"},"Numeric any aggregators"),(0,l.yg)("table",null,(0,l.yg)("thead",{parentName:"table"},(0,l.yg)("tr",{parentName:"thead"},(0,l.yg)("th",{parentName:"tr",align:null},"Property"),(0,l.yg)("th",{parentName:"tr",align:null},"Description"),(0,l.yg)("th",{parentName:"tr",align:null},"Required"))),(0,l.yg)("tbody",{parentName:"table"},(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"type")),(0,l.yg)("td",{parentName:"tr",align:null},'Must be "doubleAny", "floatAny", or "longAny".'),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"name")),(0,l.yg)("td",{parentName:"tr",align:null},"Output name for the value."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"fieldName")),(0,l.yg)("td",{parentName:"tr",align:null},"Name of the input column to compute the value over."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")))),(0,l.yg)("h5",{id:"doubleany-aggregator"},(0,l.yg)("inlineCode",{parentName:"h5"},"doubleAny")," aggregator"),(0,l.yg)("p",null,(0,l.yg)("inlineCode",{parentName:"p"},"doubleAny")," returns any double metric value."),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{\n "type" : "doubleAny",\n "name" : "anyDouble",\n "fieldName" : "aDouble"\n}\n')),(0,l.yg)("h5",{id:"floatany-aggregator"},(0,l.yg)("inlineCode",{parentName:"h5"},"floatAny")," aggregator"),(0,l.yg)("p",null,(0,l.yg)("inlineCode",{parentName:"p"},"floatAny")," returns any float metric value."),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{\n "type" : "floatAny",\n "name" : "anyFloat",\n "fieldName" : "aFloat"\n}\n')),(0,l.yg)("h5",{id:"longany-aggregator"},(0,l.yg)("inlineCode",{parentName:"h5"},"longAny")," aggregator"),(0,l.yg)("p",null,(0,l.yg)("inlineCode",{parentName:"p"},"longAny")," returns any long metric value."),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{\n "type" : "longAny",\n "name" : "anyLong",\n "fieldName" : "aLong"\n}\n')),(0,l.yg)("h4",{id:"stringany-aggregator"},(0,l.yg)("inlineCode",{parentName:"h4"},"stringAny")," aggregator"),(0,l.yg)("p",null,(0,l.yg)("inlineCode",{parentName:"p"},"stringAny")," returns any string value present in the input."),(0,l.yg)("table",null,(0,l.yg)("thead",{parentName:"table"},(0,l.yg)("tr",{parentName:"thead"},(0,l.yg)("th",{parentName:"tr",align:null},"Property"),(0,l.yg)("th",{parentName:"tr",align:null},"Description"),(0,l.yg)("th",{parentName:"tr",align:null},"Required"))),(0,l.yg)("tbody",{parentName:"table"},(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"type")),(0,l.yg)("td",{parentName:"tr",align:null},'Must be "stringAny".'),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"name")),(0,l.yg)("td",{parentName:"tr",align:null},"Output name for the value."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"fieldName")),(0,l.yg)("td",{parentName:"tr",align:null},"Name of the input column to compute the value over."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"maxStringBytes")),(0,l.yg)("td",{parentName:"tr",align:null},"Maximum size of string values to accumulate when computing the first or last value per group. Values longer than this will be truncated."),(0,l.yg)("td",{parentName:"tr",align:null},"No. Defaults to 1024.")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"aggregateMultipleValues")),(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"aggregateMultipleValues")," is an optional boolean flag controls the behavior of aggregating a ",(0,l.yg)("a",{parentName:"td",href:"/docs/latest/querying/multi-value-dimensions"},"multi-value dimension"),". ",(0,l.yg)("inlineCode",{parentName:"td"},"aggregateMultipleValues")," is set as true by default and returns the stringified array in case of a multi-value dimension. By setting it to false, function will return first value instead."),(0,l.yg)("td",{parentName:"tr",align:null},"No. Defaults to true.")))),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{\n "type" : "stringAny",\n "name" : "anyString",\n "fieldName" : "aString",\n "maxStringBytes" : 2048\n}\n')),(0,l.yg)("a",{name:"approx"}),(0,l.yg)("h2",{id:"approximate-aggregations"},"Approximate aggregations"),(0,l.yg)("h3",{id:"count-distinct"},"Count distinct"),(0,l.yg)("h4",{id:"apache-datasketches-theta-sketch"},"Apache DataSketches Theta Sketch"),(0,l.yg)("p",null,"The ",(0,l.yg)("a",{parentName:"p",href:"/docs/latest/development/extensions-core/datasketches-theta"},"DataSketches Theta Sketch")," extension-provided aggregator gives distinct count estimates with support for set union, intersection, and difference post-aggregators, using Theta sketches from the ",(0,l.yg)("a",{parentName:"p",href:"https://datasketches.apache.org/"},"Apache DataSketches")," library."),(0,l.yg)("h4",{id:"apache-datasketches-hll-sketch"},"Apache DataSketches HLL Sketch"),(0,l.yg)("p",null,"The ",(0,l.yg)("a",{parentName:"p",href:"/docs/latest/development/extensions-core/datasketches-hll"},"DataSketches HLL Sketch")," extension-provided aggregator gives distinct count estimates using the HyperLogLog algorithm."),(0,l.yg)("p",null,"Compared to the Theta sketch, the HLL sketch does not support set operations and has slightly slower update and merge speed, but requires significantly less space."),(0,l.yg)("h4",{id:"cardinality-hyperunique"},"Cardinality, hyperUnique"),(0,l.yg)("admonition",{type:"info"},(0,l.yg)("p",{parentName:"admonition"},"For new use cases, we recommend evaluating ",(0,l.yg)("a",{parentName:"p",href:"/docs/latest/development/extensions-core/datasketches-theta"},"DataSketches Theta Sketch")," or ",(0,l.yg)("a",{parentName:"p",href:"/docs/latest/development/extensions-core/datasketches-hll"},"DataSketches HLL Sketch")," instead.\nThe DataSketches aggregators are generally able to offer more flexibility and better accuracy than the classic Druid ",(0,l.yg)("inlineCode",{parentName:"p"},"cardinality")," and ",(0,l.yg)("inlineCode",{parentName:"p"},"hyperUnique")," aggregators.")),(0,l.yg)("p",null,"The ",(0,l.yg)("a",{parentName:"p",href:"/docs/latest/querying/hll-old"},"Cardinality and HyperUnique")," aggregators are older aggregator implementations available by default in Druid that also provide distinct count estimates using the HyperLogLog algorithm. The newer DataSketches Theta and HLL extension-provided aggregators described above have superior accuracy and performance and are recommended instead."),(0,l.yg)("p",null,"The DataSketches team has published a ",(0,l.yg)("a",{parentName:"p",href:"https://datasketches.apache.org/docs/HLL/HllSketchVsDruidHyperLogLogCollector.html"},"comparison study")," between Druid's original HLL algorithm and the DataSketches HLL algorithm. Based on the demonstrated advantages of the DataSketches implementation, we are recommending using them in preference to Druid's original HLL-based aggregators.\nHowever, to ensure backwards compatibility, we will continue to support the classic aggregators."),(0,l.yg)("p",null,"Please note that ",(0,l.yg)("inlineCode",{parentName:"p"},"hyperUnique")," aggregators are not mutually compatible with Datasketches HLL or Theta sketches."),(0,l.yg)("h5",{id:"multi-column-handling"},"Multi-column handling"),(0,l.yg)("p",null,"Note the DataSketches Theta and HLL aggregators currently only support single-column inputs. If you were previously using the Cardinality aggregator with multiple-column inputs, equivalent operations using Theta or HLL sketches are described below:"),(0,l.yg)("ul",null,(0,l.yg)("li",{parentName:"ul"},"Multi-column ",(0,l.yg)("inlineCode",{parentName:"li"},"byValue")," Cardinality can be replaced with a union of Theta sketches on the individual input columns"),(0,l.yg)("li",{parentName:"ul"},"Multi-column ",(0,l.yg)("inlineCode",{parentName:"li"},"byRow")," Cardinality can be replaced with a Theta or HLL sketch on a single ",(0,l.yg)("a",{parentName:"li",href:"/docs/latest/querying/virtual-columns"},"virtual column")," that combines the individual input columns.")),(0,l.yg)("h3",{id:"histograms-and-quantiles"},"Histograms and quantiles"),(0,l.yg)("h4",{id:"datasketches-quantiles-sketch"},"DataSketches Quantiles Sketch"),(0,l.yg)("p",null,"The ",(0,l.yg)("a",{parentName:"p",href:"/docs/latest/development/extensions-core/datasketches-quantiles"},"DataSketches Quantiles Sketch")," extension-provided aggregator provides quantile estimates and histogram approximations using the numeric quantiles DoublesSketch from the ",(0,l.yg)("a",{parentName:"p",href:"https://datasketches.apache.org/"},"datasketches")," library."),(0,l.yg)("p",null,"We recommend this aggregator in general for quantiles/histogram use cases, as it provides formal error bounds and has distribution-independent accuracy."),(0,l.yg)("h4",{id:"moments-sketch-experimental"},"Moments Sketch (Experimental)"),(0,l.yg)("p",null,"The ",(0,l.yg)("a",{parentName:"p",href:"/docs/latest/development/extensions-contrib/momentsketch-quantiles"},"Moments Sketch")," extension-provided aggregator is an experimental aggregator that provides quantile estimates using the ",(0,l.yg)("a",{parentName:"p",href:"https://github.com/stanford-futuredata/momentsketch"},"Moments Sketch"),"."),(0,l.yg)("p",null,"The Moments Sketch aggregator is provided as an experimental option. It is optimized for merging speed and it can have higher aggregation performance compared to the DataSketches quantiles aggregator. However, the accuracy of the Moments Sketch is distribution-dependent, so users will need to empirically verify that the aggregator is suitable for their input data."),(0,l.yg)("p",null,"As a general guideline for experimentation, the ",(0,l.yg)("a",{parentName:"p",href:"https://arxiv.org/pdf/1803.01969.pdf"},"Moments Sketch paper")," points out that this algorithm works better on inputs with high entropy. In particular, the algorithm is not a good fit when the input data consists of a small number of clustered discrete values."),(0,l.yg)("h4",{id:"fixed-buckets-histogram"},"Fixed Buckets Histogram"),(0,l.yg)("p",null,"Druid also provides a ",(0,l.yg)("a",{parentName:"p",href:"/docs/latest/development/extensions-core/approximate-histograms#fixed-buckets-histogram"},"simple histogram implementation")," that uses a fixed range and fixed number of buckets with support for quantile estimation, backed by an array of bucket count values."),(0,l.yg)("p",null,"The fixed buckets histogram can perform well when the distribution of the input data allows a small number of buckets to be used."),(0,l.yg)("p",null,"We do not recommend the fixed buckets histogram for general use, as its usefulness is extremely data dependent. However, it is made available for users that have already identified use cases where a fixed buckets histogram is suitable."),(0,l.yg)("h4",{id:"approximate-histogram-deprecated"},"Approximate Histogram (deprecated)"),(0,l.yg)("admonition",{type:"info"},(0,l.yg)("p",{parentName:"admonition"},"The Approximate Histogram aggregator is deprecated.\nThere are a number of other quantile estimation algorithms that offer better performance, accuracy, and memory footprint.\nWe recommend using ",(0,l.yg)("a",{parentName:"p",href:"/docs/latest/development/extensions-core/datasketches-quantiles"},"DataSketches Quantiles")," instead.")),(0,l.yg)("p",null,"The ",(0,l.yg)("a",{parentName:"p",href:"/docs/latest/development/extensions-core/approximate-histograms"},"Approximate Histogram")," extension-provided aggregator also provides quantile estimates and histogram approximations, based on ",(0,l.yg)("a",{parentName:"p",href:"http://jmlr.org/papers/volume11/ben-haim10a/ben-haim10a.pdf"},"http://jmlr.org/papers/volume11/ben-haim10a/ben-haim10a.pdf"),"."),(0,l.yg)("p",null,"The algorithm used by this deprecated aggregator is highly distribution-dependent and its output is subject to serious distortions when the input does not fit within the algorithm's limitations."),(0,l.yg)("p",null,"A ",(0,l.yg)("a",{parentName:"p",href:"https://datasketches.apache.org/docs/QuantilesStudies/DruidApproxHistogramStudy.html"},"study published by the DataSketches team")," demonstrates some of the known failure modes of this algorithm:"),(0,l.yg)("ul",null,(0,l.yg)("li",{parentName:"ul"},"The algorithm's quantile calculations can fail to provide results for a large range of rank values (all ranks less than 0.89 in the example used in the study), returning all zeroes instead."),(0,l.yg)("li",{parentName:"ul"},"The algorithm can completely fail to record spikes in the tail ends of the distribution"),(0,l.yg)("li",{parentName:"ul"},"In general, the histogram produced by the algorithm can deviate significantly from the true histogram, with no bounds on the errors.")),(0,l.yg)("p",null,"It is not possible to determine a priori how well this aggregator will behave for a given input stream, nor does the aggregator provide any indication that serious distortions are present in the output."),(0,l.yg)("p",null,"For these reasons, we have deprecated this aggregator and recommend using the DataSketches Quantiles aggregator instead for new and existing use cases, although we will continue to support Approximate Histogram for backwards compatibility."),(0,l.yg)("h2",{id:"expression-aggregations"},"Expression aggregations"),(0,l.yg)("h3",{id:"expression-aggregator"},"Expression aggregator"),(0,l.yg)("p",null,"Aggregator applicable only at query time. Aggregates results using ",(0,l.yg)("a",{parentName:"p",href:"/docs/latest/querying/math-expr"},"Druid expressions")," functions to facilitate building custom functions."),(0,l.yg)("table",null,(0,l.yg)("thead",{parentName:"table"},(0,l.yg)("tr",{parentName:"thead"},(0,l.yg)("th",{parentName:"tr",align:null},"Property"),(0,l.yg)("th",{parentName:"tr",align:null},"Description"),(0,l.yg)("th",{parentName:"tr",align:null},"Required"))),(0,l.yg)("tbody",{parentName:"table"},(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"type")),(0,l.yg)("td",{parentName:"tr",align:null},'Must be "expression".'),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"name")),(0,l.yg)("td",{parentName:"tr",align:null},"The aggregator output name."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"fields")),(0,l.yg)("td",{parentName:"tr",align:null},"The list of aggregator input columns."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"accumulatorIdentifier")),(0,l.yg)("td",{parentName:"tr",align:null},"The variable which identifies the accumulator value in the ",(0,l.yg)("inlineCode",{parentName:"td"},"fold")," and ",(0,l.yg)("inlineCode",{parentName:"td"},"combine")," expressions."),(0,l.yg)("td",{parentName:"tr",align:null},"No. Default ",(0,l.yg)("inlineCode",{parentName:"td"},"__acc"),".")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"fold")),(0,l.yg)("td",{parentName:"tr",align:null},"The expression to accumulate values from ",(0,l.yg)("inlineCode",{parentName:"td"},"fields"),". The result of the expression is stored in ",(0,l.yg)("inlineCode",{parentName:"td"},"accumulatorIdentifier")," and available to the next computation."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"combine")),(0,l.yg)("td",{parentName:"tr",align:null},"The expression to combine the results of various ",(0,l.yg)("inlineCode",{parentName:"td"},"fold")," expressions of each segment when merging results. The input is available to the expression as a variable identified by the ",(0,l.yg)("inlineCode",{parentName:"td"},"name"),"."),(0,l.yg)("td",{parentName:"tr",align:null},"No. Default to ",(0,l.yg)("inlineCode",{parentName:"td"},"fold")," expression if the expression has a single input in ",(0,l.yg)("inlineCode",{parentName:"td"},"fields"),".")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"compare")),(0,l.yg)("td",{parentName:"tr",align:null},"The comparator expression which can only refer to two input variables, ",(0,l.yg)("inlineCode",{parentName:"td"},"o1")," and ",(0,l.yg)("inlineCode",{parentName:"td"},"o2"),", where ",(0,l.yg)("inlineCode",{parentName:"td"},"o1")," and ",(0,l.yg)("inlineCode",{parentName:"td"},"o2")," are the output of ",(0,l.yg)("inlineCode",{parentName:"td"},"fold")," or ",(0,l.yg)("inlineCode",{parentName:"td"},"combine")," expressions, and must adhere to the Java comparator contract. If not set, the aggregator will try to fall back to an output type appropriate comparator."),(0,l.yg)("td",{parentName:"tr",align:null},"No")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"finalize")),(0,l.yg)("td",{parentName:"tr",align:null},"The finalize expression which can only refer to a single input variable, ",(0,l.yg)("inlineCode",{parentName:"td"},"o"),". This expression is used to perform any final transformation of the output of the ",(0,l.yg)("inlineCode",{parentName:"td"},"fold")," or ",(0,l.yg)("inlineCode",{parentName:"td"},"combine")," expressions. If not set, then the value is not transformed."),(0,l.yg)("td",{parentName:"tr",align:null},"No")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"initialValue")),(0,l.yg)("td",{parentName:"tr",align:null},"The initial value of the accumulator for the ",(0,l.yg)("inlineCode",{parentName:"td"},"fold")," (and ",(0,l.yg)("inlineCode",{parentName:"td"},"combine"),", if ",(0,l.yg)("inlineCode",{parentName:"td"},"InitialCombineValue")," is null) expression."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"initialCombineValue")),(0,l.yg)("td",{parentName:"tr",align:null},"The initial value of the accumulator for the ",(0,l.yg)("inlineCode",{parentName:"td"},"combine")," expression."),(0,l.yg)("td",{parentName:"tr",align:null},"No. Default ",(0,l.yg)("inlineCode",{parentName:"td"},"initialValue"),".")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"isNullUnlessAggregated")),(0,l.yg)("td",{parentName:"tr",align:null},"Indicates that the default output value should be ",(0,l.yg)("inlineCode",{parentName:"td"},"null")," if the aggregator does not process any rows. If true, the value is ",(0,l.yg)("inlineCode",{parentName:"td"},"null"),", if false, the result of running the expressions with initial values is used instead."),(0,l.yg)("td",{parentName:"tr",align:null},"No. Defaults to the value of ",(0,l.yg)("inlineCode",{parentName:"td"},"druid.generic.useDefaultValueForNull"),".")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"shouldAggregateNullInputs")),(0,l.yg)("td",{parentName:"tr",align:null},"Indicates if the ",(0,l.yg)("inlineCode",{parentName:"td"},"fold")," expression should operate on any ",(0,l.yg)("inlineCode",{parentName:"td"},"null")," input values."),(0,l.yg)("td",{parentName:"tr",align:null},"No. Defaults to ",(0,l.yg)("inlineCode",{parentName:"td"},"true"),".")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"shouldCombineAggregateNullInputs")),(0,l.yg)("td",{parentName:"tr",align:null},"Indicates if the ",(0,l.yg)("inlineCode",{parentName:"td"},"combine")," expression should operate on any ",(0,l.yg)("inlineCode",{parentName:"td"},"null")," input values."),(0,l.yg)("td",{parentName:"tr",align:null},"No. Defaults to the value of ",(0,l.yg)("inlineCode",{parentName:"td"},"shouldAggregateNullInputs"),".")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"maxSizeBytes")),(0,l.yg)("td",{parentName:"tr",align:null},"Maximum size in bytes that variably sized aggregator output types such as strings and arrays are allowed to grow to before the aggregation fails."),(0,l.yg)("td",{parentName:"tr",align:null},"No. Default is 8192 bytes.")))),(0,l.yg)("h4",{id:"example-a-count-aggregator"},'Example: a "count" aggregator'),(0,l.yg)("p",null,"The initial value is ",(0,l.yg)("inlineCode",{parentName:"p"},"0"),". ",(0,l.yg)("inlineCode",{parentName:"p"},"fold")," adds ",(0,l.yg)("inlineCode",{parentName:"p"},"1")," for each row processed."),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{\n "type": "expression",\n "name": "expression_count",\n "fields": [],\n "initialValue": "0",\n "fold": "__acc + 1",\n "combine": "__acc + expression_count"\n}\n')),(0,l.yg)("h4",{id:"example-a-sum-aggregator"},'Example: a "sum" aggregator'),(0,l.yg)("p",null,"The initial value is ",(0,l.yg)("inlineCode",{parentName:"p"},"0"),". ",(0,l.yg)("inlineCode",{parentName:"p"},"fold")," adds the numeric value ",(0,l.yg)("inlineCode",{parentName:"p"},"column_a")," for each row processed."),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{\n "type": "expression",\n "name": "expression_sum",\n "fields": ["column_a"],\n "initialValue": "0",\n "fold": "__acc + column_a"\n}\n')),(0,l.yg)("h4",{id:"example-a-distinct-array-element-aggregator-sorted-by-array_length"},'Example: a "distinct array element" aggregator, sorted by array_length'),(0,l.yg)("p",null,"The initial value is an empty array. ",(0,l.yg)("inlineCode",{parentName:"p"},"fold")," adds the elements of ",(0,l.yg)("inlineCode",{parentName:"p"},"column_a")," to the accumulator using set semantics, ",(0,l.yg)("inlineCode",{parentName:"p"},"combine")," merges the sets, and ",(0,l.yg)("inlineCode",{parentName:"p"},"compare")," orders the values by ",(0,l.yg)("inlineCode",{parentName:"p"},"array_length"),"."),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{\n "type": "expression",\n "name": "expression_array_agg_distinct",\n "fields": ["column_a"],\n "initialValue": "[]",\n "fold": "array_set_add(__acc, column_a)",\n "combine": "array_set_add_all(__acc, expression_array_agg_distinct)",\n "compare": "if(array_length(o1) > array_length(o2), 1, if (array_length(o1) == array_length(o2), 0, -1))"\n}\n')),(0,l.yg)("h4",{id:"example-an-approximate-count-aggregator-using-the-built-in-hyper-unique"},'Example: an "approximate count" aggregator using the built-in hyper-unique'),(0,l.yg)("p",null,"Similar to the cardinality aggregator, the default value is an empty hyper-unique sketch, ",(0,l.yg)("inlineCode",{parentName:"p"},"fold")," adds the value of ",(0,l.yg)("inlineCode",{parentName:"p"},"column_a")," to the sketch, ",(0,l.yg)("inlineCode",{parentName:"p"},"combine")," merges the sketches, and ",(0,l.yg)("inlineCode",{parentName:"p"},"finalize")," gets the estimated count from the accumulated sketch."),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{\n "type": "expression",\n "name": "expression_cardinality",\n "fields": ["column_a"],\n "initialValue": "hyper_unique()",\n "fold": "hyper_unique_add(column_a, __acc)",\n "combine": "hyper_unique_add(expression_cardinality, __acc)",\n "finalize": "hyper_unique_estimate(o)"\n}\n')),(0,l.yg)("h3",{id:"javascript-aggregator"},"JavaScript aggregator"),(0,l.yg)("p",null,"Computes an arbitrary JavaScript function over a set of columns (both metrics and dimensions are allowed). Your\nJavaScript functions are expected to return floating-point values."),(0,l.yg)("table",null,(0,l.yg)("thead",{parentName:"table"},(0,l.yg)("tr",{parentName:"thead"},(0,l.yg)("th",{parentName:"tr",align:null},"Property"),(0,l.yg)("th",{parentName:"tr",align:null},"Description"),(0,l.yg)("th",{parentName:"tr",align:null},"Required"))),(0,l.yg)("tbody",{parentName:"table"},(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"type")),(0,l.yg)("td",{parentName:"tr",align:null},'Must be "javascript".'),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"name")),(0,l.yg)("td",{parentName:"tr",align:null},"The aggregator output name."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"fieldNames")),(0,l.yg)("td",{parentName:"tr",align:null},"The list of aggregator input columns."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"fnAggregate")),(0,l.yg)("td",{parentName:"tr",align:null},"JavaScript function that updates partial aggregate based on the current row values, and returns the updated partial aggregate."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"fnCombine")),(0,l.yg)("td",{parentName:"tr",align:null},"JavaScript function to combine partial aggregates and return the combined result."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"fnReset")),(0,l.yg)("td",{parentName:"tr",align:null},"JavaScript function that returns the 'initial' value."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")))),(0,l.yg)("h4",{id:"example"},"Example"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{\n "type": "javascript",\n "name": "sum(log(x)*y) + 10",\n "fieldNames": ["x", "y"],\n "fnAggregate" : "function(current, a, b) { return current + (Math.log(a) * b); }",\n "fnCombine" : "function(partialA, partialB) { return partialA + partialB; }",\n "fnReset" : "function() { return 10; }"\n}\n')),(0,l.yg)("admonition",{type:"info"},(0,l.yg)("p",{parentName:"admonition"},"JavaScript-based functionality is disabled by default. Refer to the Druid ",(0,l.yg)("a",{parentName:"p",href:"/docs/latest/development/javascript"},"JavaScript programming guide")," for guidelines about using Druid's JavaScript functionality, including instructions on how to enable it.")),(0,l.yg)("h2",{id:"miscellaneous-aggregations"},"Miscellaneous aggregations"),(0,l.yg)("h3",{id:"filtered-aggregator"},"Filtered aggregator"),(0,l.yg)("p",null,"A filtered aggregator wraps any given aggregator, but only aggregates the values for which the given dimension filter matches."),(0,l.yg)("p",null,"This makes it possible to compute the results of a filtered and an unfiltered aggregation simultaneously, without having to issue multiple queries, and use both results as part of post-aggregations."),(0,l.yg)("p",null,"If only the filtered results are required, consider putting the filter on the query itself. This will be much faster since it does not require scanning all the data."),(0,l.yg)("table",null,(0,l.yg)("thead",{parentName:"table"},(0,l.yg)("tr",{parentName:"thead"},(0,l.yg)("th",{parentName:"tr",align:null},"Property"),(0,l.yg)("th",{parentName:"tr",align:null},"Description"),(0,l.yg)("th",{parentName:"tr",align:null},"Required"))),(0,l.yg)("tbody",{parentName:"table"},(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"type")),(0,l.yg)("td",{parentName:"tr",align:null},'Must be "filtered".'),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"name")),(0,l.yg)("td",{parentName:"tr",align:null},"The aggregator output name."),(0,l.yg)("td",{parentName:"tr",align:null},"No")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"aggregator")),(0,l.yg)("td",{parentName:"tr",align:null},"Inline aggregator specification."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"filter")),(0,l.yg)("td",{parentName:"tr",align:null},"Inline ",(0,l.yg)("a",{parentName:"td",href:"/docs/latest/querying/filters"},"filter")," specification."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")))),(0,l.yg)("p",null,"Example:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{\n "type": "filtered",\n "name": "filteredSumLong",\n "filter": {\n "type" : "selector",\n "dimension" : "someColumn",\n "value" : "abcdef"\n },\n "aggregator": {\n "type": "longSum",\n "name": "sumLong",\n "fieldName": "aLong"\n }\n}\n')),(0,l.yg)("h3",{id:"grouping-aggregator"},"Grouping aggregator"),(0,l.yg)("p",null,"A grouping aggregator can only be used as part of GroupBy queries which have a subtotal spec. It returns a number for\neach output row that lets you infer whether a particular dimension is included in the sub-grouping used for that row. You can pass\na ",(0,l.yg)("em",{parentName:"p"},"non-empty")," list of dimensions to this aggregator which ",(0,l.yg)("em",{parentName:"p"},"must")," be a subset of dimensions that you are grouping on. "),(0,l.yg)("table",null,(0,l.yg)("thead",{parentName:"table"},(0,l.yg)("tr",{parentName:"thead"},(0,l.yg)("th",{parentName:"tr",align:null},"Property"),(0,l.yg)("th",{parentName:"tr",align:null},"Description"),(0,l.yg)("th",{parentName:"tr",align:null},"Required"))),(0,l.yg)("tbody",{parentName:"table"},(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"type")),(0,l.yg)("td",{parentName:"tr",align:null},'Must be "grouping".'),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"name")),(0,l.yg)("td",{parentName:"tr",align:null},"The aggregator output name."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"groupings")),(0,l.yg)("td",{parentName:"tr",align:null},"The list of columns to use in the grouping set."),(0,l.yg)("td",{parentName:"tr",align:null},"Yes")))),(0,l.yg)("p",null,"For example, the following aggregator has ",(0,l.yg)("inlineCode",{parentName:"p"},'["dim1", "dim2"]')," as input dimensions:"),(0,l.yg)("pre",null,(0,l.yg)("code",{parentName:"pre",className:"language-json"},'{ "type" : "grouping", "name" : "someGrouping", "groupings" : ["dim1", "dim2"] }\n')),(0,l.yg)("p",null,"and used in a grouping query with ",(0,l.yg)("inlineCode",{parentName:"p"},'[["dim1", "dim2"], ["dim1"], ["dim2"], []]')," as subtotals, the\npossible output of the aggregator is:"),(0,l.yg)("table",null,(0,l.yg)("thead",{parentName:"table"},(0,l.yg)("tr",{parentName:"thead"},(0,l.yg)("th",{parentName:"tr",align:null},"subtotal used in query"),(0,l.yg)("th",{parentName:"tr",align:null},"Output"),(0,l.yg)("th",{parentName:"tr",align:null},"(bits representation)"))),(0,l.yg)("tbody",{parentName:"table"},(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},'["dim1", "dim2"]')),(0,l.yg)("td",{parentName:"tr",align:null},"0"),(0,l.yg)("td",{parentName:"tr",align:null},"(00)")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},'["dim1"]')),(0,l.yg)("td",{parentName:"tr",align:null},"1"),(0,l.yg)("td",{parentName:"tr",align:null},"(01)")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},'["dim2"]')),(0,l.yg)("td",{parentName:"tr",align:null},"2"),(0,l.yg)("td",{parentName:"tr",align:null},"(10)")),(0,l.yg)("tr",{parentName:"tbody"},(0,l.yg)("td",{parentName:"tr",align:null},(0,l.yg)("inlineCode",{parentName:"td"},"[]")),(0,l.yg)("td",{parentName:"tr",align:null},"3"),(0,l.yg)("td",{parentName:"tr",align:null},"(11)")))),(0,l.yg)("p",null,"As the example illustrates, you can think of the output number as an unsigned ",(0,l.yg)("em",{parentName:"p"},"n")," bit number where ",(0,l.yg)("em",{parentName:"p"},"n")," is the number of dimensions passed to the aggregator.\nDruid sets the bit at position X for the number to 0 if the sub-grouping includes a dimension at position X in the aggregator input. Otherwise, Druid sets this bit to 1."))}y.isMDXComponent=!0}}]);