blob: 62fa02b4f85c59caf3945f0ed047572d26529aad [file] [log] [blame]
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[6037],{15680:(e,t,n)=>{n.d(t,{xA:()=>d,yg:()=>m});var a=n(96540);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 o(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 l(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 s=a.createContext({}),g=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},d=function(e){var t=g(e.components);return a.createElement(s.Provider,{value:t},e.children)},p="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},c=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,i=e.originalType,s=e.parentName,d=l(e,["components","mdxType","originalType","parentName"]),p=g(n),c=r,m=p["".concat(s,".").concat(c)]||p[c]||u[c]||i;return n?a.createElement(m,o(o({ref:t},d),{},{components:n})):a.createElement(m,o({ref:t},d))}));function m(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var i=n.length,o=new Array(i);o[0]=c;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[p]="string"==typeof e?e:r,o[1]=l;for(var g=2;g<i;g++)o[g]=n[g];return a.createElement.apply(null,o)}return a.createElement.apply(null,n)}c.displayName="MDXCreateElement"},51826:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>s,default:()=>m,frontMatter:()=>l,metadata:()=>g,toc:()=>p});var a=n(58168),r=n(98587),i=(n(96540),n(15680)),o=["components"],l={id:"datasketches-hll",title:"DataSketches HLL Sketch module"},s=void 0,g={unversionedId:"development/extensions-core/datasketches-hll",id:"development/extensions-core/datasketches-hll",title:"DataSketches HLL Sketch module",description:"\x3c!--",source:"@site/docs/latest/development/extensions-core/datasketches-hll.md",sourceDirName:"development/extensions-core",slug:"/development/extensions-core/datasketches-hll",permalink:"/docs/latest/development/extensions-core/datasketches-hll",draft:!1,tags:[],version:"current",frontMatter:{id:"datasketches-hll",title:"DataSketches HLL Sketch module"}},d={},p=[{value:"Aggregators",id:"aggregators",level:2},{value:"HLLSketchBuild aggregator",id:"hllsketchbuild-aggregator",level:3},{value:"HLLSketchMerge aggregator",id:"hllsketchmerge-aggregator",level:3},{value:"Post aggregators",id:"post-aggregators",level:2},{value:"Estimate",id:"estimate",level:3},{value:"Estimate with bounds",id:"estimate-with-bounds",level:3},{value:"Union",id:"union",level:3},{value:"Sketch to string",id:"sketch-to-string",level:3}],u={toc:p},c="wrapper";function m(e){var t=e.components,n=(0,r.A)(e,o);return(0,i.yg)(c,(0,a.A)({},u,n,{components:t,mdxType:"MDXLayout"}),(0,i.yg)("p",null,"This module provides Apache Druid aggregators for distinct counting based on HLL sketch from ",(0,i.yg)("a",{parentName:"p",href:"https://datasketches.apache.org/"},"Apache DataSketches")," library. At ingestion time, this aggregator creates the HLL sketch objects to store in Druid segments. By default, Druid reads and merges sketches at query time. The default result is\nthe estimate of the number of distinct values presented to the sketch. You can also use post aggregators to produce a union of sketch columns in the same row.\nYou can use the HLL sketch aggregator on any column to estimate its cardinality."),(0,i.yg)("p",null,"To use this aggregator, make sure you ",(0,i.yg)("a",{parentName:"p",href:"/docs/latest/configuration/extensions#loading-extensions"},"include")," the extension in your config file:"),(0,i.yg)("pre",null,(0,i.yg)("code",{parentName:"pre"},'druid.extensions.loadList=["druid-datasketches"]\n')),(0,i.yg)("p",null,"For additional sketch types supported in Druid, see ",(0,i.yg)("a",{parentName:"p",href:"/docs/latest/development/extensions-core/datasketches-extension"},"DataSketches extension"),"."),(0,i.yg)("h2",{id:"aggregators"},"Aggregators"),(0,i.yg)("table",null,(0,i.yg)("thead",{parentName:"table"},(0,i.yg)("tr",{parentName:"thead"},(0,i.yg)("th",{parentName:"tr",align:null},"Property"),(0,i.yg)("th",{parentName:"tr",align:null},"Description"),(0,i.yg)("th",{parentName:"tr",align:null},"Required?"))),(0,i.yg)("tbody",{parentName:"table"},(0,i.yg)("tr",{parentName:"tbody"},(0,i.yg)("td",{parentName:"tr",align:null},(0,i.yg)("inlineCode",{parentName:"td"},"type")),(0,i.yg)("td",{parentName:"tr",align:null},"Either ",(0,i.yg)("a",{parentName:"td",href:"#hllsketchbuild-aggregator"},(0,i.yg)("inlineCode",{parentName:"a"},"HLLSketchBuild"))," or ",(0,i.yg)("a",{parentName:"td",href:"#hllsketchmerge-aggregator"},(0,i.yg)("inlineCode",{parentName:"a"},"HLLSketchMerge")),"."),(0,i.yg)("td",{parentName:"tr",align:null},"yes")),(0,i.yg)("tr",{parentName:"tbody"},(0,i.yg)("td",{parentName:"tr",align:null},(0,i.yg)("inlineCode",{parentName:"td"},"name")),(0,i.yg)("td",{parentName:"tr",align:null},"String representing the output column to store sketch values."),(0,i.yg)("td",{parentName:"tr",align:null},"yes")),(0,i.yg)("tr",{parentName:"tbody"},(0,i.yg)("td",{parentName:"tr",align:null},(0,i.yg)("inlineCode",{parentName:"td"},"fieldName")),(0,i.yg)("td",{parentName:"tr",align:null},"The name of the input field."),(0,i.yg)("td",{parentName:"tr",align:null},"yes")),(0,i.yg)("tr",{parentName:"tbody"},(0,i.yg)("td",{parentName:"tr",align:null},(0,i.yg)("inlineCode",{parentName:"td"},"lgK")),(0,i.yg)("td",{parentName:"tr",align:null},"log2 of K that is the number of buckets in the sketch, parameter that controls the size and the accuracy. Must be between 4 and 21 inclusively."),(0,i.yg)("td",{parentName:"tr",align:null},"no, defaults to ",(0,i.yg)("inlineCode",{parentName:"td"},"12"))),(0,i.yg)("tr",{parentName:"tbody"},(0,i.yg)("td",{parentName:"tr",align:null},(0,i.yg)("inlineCode",{parentName:"td"},"tgtHllType")),(0,i.yg)("td",{parentName:"tr",align:null},"The type of the target HLL sketch. Must be ",(0,i.yg)("inlineCode",{parentName:"td"},"HLL_4"),", ",(0,i.yg)("inlineCode",{parentName:"td"},"HLL_6")," or ",(0,i.yg)("inlineCode",{parentName:"td"},"HLL_8")),(0,i.yg)("td",{parentName:"tr",align:null},"no, defaults to ",(0,i.yg)("inlineCode",{parentName:"td"},"HLL_4"))),(0,i.yg)("tr",{parentName:"tbody"},(0,i.yg)("td",{parentName:"tr",align:null},(0,i.yg)("inlineCode",{parentName:"td"},"round")),(0,i.yg)("td",{parentName:"tr",align:null},"Round off values to whole numbers. Only affects query-time behavior and is ignored at ingestion-time."),(0,i.yg)("td",{parentName:"tr",align:null},"no, defaults to ",(0,i.yg)("inlineCode",{parentName:"td"},"false"))),(0,i.yg)("tr",{parentName:"tbody"},(0,i.yg)("td",{parentName:"tr",align:null},(0,i.yg)("inlineCode",{parentName:"td"},"shouldFinalize")),(0,i.yg)("td",{parentName:"tr",align:null},"Return the final double type representing the estimate rather than the intermediate sketch type itself. In addition to controlling the finalization of this aggregator, you can control whether all aggregators are finalized with the query context parameters ",(0,i.yg)("a",{parentName:"td",href:"/docs/latest/querying/query-context"},(0,i.yg)("inlineCode",{parentName:"a"},"finalize"))," and ",(0,i.yg)("a",{parentName:"td",href:"/docs/latest/querying/sql-query-context"},(0,i.yg)("inlineCode",{parentName:"a"},"sqlFinalizeOuterSketches")),"."),(0,i.yg)("td",{parentName:"tr",align:null},"no, defaults to ",(0,i.yg)("inlineCode",{parentName:"td"},"true"))))),(0,i.yg)("admonition",{type:"info"},(0,i.yg)("p",{parentName:"admonition"}," The default ",(0,i.yg)("inlineCode",{parentName:"p"},"lgK")," value has proven to be sufficient for most use cases; expect only very negligible improvements in accuracy with ",(0,i.yg)("inlineCode",{parentName:"p"},"lgK")," values over ",(0,i.yg)("inlineCode",{parentName:"p"},"16")," in normal circumstances.")),(0,i.yg)("h3",{id:"hllsketchbuild-aggregator"},"HLLSketchBuild aggregator"),(0,i.yg)("pre",null,(0,i.yg)("code",{parentName:"pre"},'{\n "type": "HLLSketchBuild",\n "name": <output name>,\n "fieldName": <metric name>,\n "lgK": <size and accuracy parameter>,\n "tgtHllType": <target HLL type>,\n "round": <false | true>\n }\n')),(0,i.yg)("p",null,"The ",(0,i.yg)("inlineCode",{parentName:"p"},"HLLSketchBuild")," aggregator builds an HLL sketch object from the specified input column. When used during ingestion, Druid stores pre-generated HLL sketch objects in the datasource instead of the raw data from the input column.\nWhen applied at query time on an existing dimension, you can use the resulting column as an intermediate dimension by the ",(0,i.yg)("a",{parentName:"p",href:"#post-aggregators"},"post-aggregators"),"."),(0,i.yg)("admonition",{type:"info"},(0,i.yg)("p",{parentName:"admonition"}," It is very common to use ",(0,i.yg)("inlineCode",{parentName:"p"},"HLLSketchBuild")," in combination with ",(0,i.yg)("a",{parentName:"p",href:"/docs/latest/ingestion/rollup"},"rollup")," to create a ",(0,i.yg)("a",{parentName:"p",href:"/docs/latest/ingestion/ingestion-spec#metricsspec"},"metric")," on high-cardinality columns. In this example, a metric called ",(0,i.yg)("inlineCode",{parentName:"p"},"userid_hll")," is included in the ",(0,i.yg)("inlineCode",{parentName:"p"},"metricsSpec"),". This will perform a HLL sketch on the ",(0,i.yg)("inlineCode",{parentName:"p"},"userid")," field at ingestion time, allowing for highly-performant approximate ",(0,i.yg)("inlineCode",{parentName:"p"},"COUNT DISTINCT")," query operations and improving roll-up ratios when ",(0,i.yg)("inlineCode",{parentName:"p"},"userid")," is then left out of the ",(0,i.yg)("inlineCode",{parentName:"p"},"dimensionsSpec"),"."),(0,i.yg)("pre",{parentName:"admonition"},(0,i.yg)("code",{parentName:"pre"},'"metricsSpec": [\n {\n "type": "HLLSketchBuild",\n "name": "userid_hll",\n "fieldName": "userid",\n "lgK": 12,\n "tgtHllType": "HLL_4"\n }\n]\n'))),(0,i.yg)("h3",{id:"hllsketchmerge-aggregator"},"HLLSketchMerge aggregator"),(0,i.yg)("pre",null,(0,i.yg)("code",{parentName:"pre"},'{\n "type": "HLLSketchMerge",\n "name": <output name>,\n "fieldName": <metric name>,\n "lgK": <size and accuracy parameter>,\n "tgtHllType": <target HLL type>,\n "round": <false | true>\n}\n')),(0,i.yg)("p",null,"You can use the ",(0,i.yg)("inlineCode",{parentName:"p"},"HLLSketchMerge")," aggregator to ingest pre-generated sketches from an input dataset. For example, you can set up a batch processing job to generate the sketches before sending the data to Druid. You must serialize the sketches in the input dataset to Base64-encoded bytes. Then, specify ",(0,i.yg)("inlineCode",{parentName:"p"},"HLLSketchMerge")," for the input column in the native ingestion ",(0,i.yg)("inlineCode",{parentName:"p"},"metricsSpec"),"."),(0,i.yg)("h2",{id:"post-aggregators"},"Post aggregators"),(0,i.yg)("h3",{id:"estimate"},"Estimate"),(0,i.yg)("p",null,"Returns the distinct count estimate as a double."),(0,i.yg)("pre",null,(0,i.yg)("code",{parentName:"pre"},'{\n "type": "HLLSketchEstimate",\n "name": <output name>,\n "field": <post aggregator that returns an HLL Sketch>,\n "round": <if true, round the estimate. Default is false>\n}\n')),(0,i.yg)("h3",{id:"estimate-with-bounds"},"Estimate with bounds"),(0,i.yg)("p",null,"Returns a distinct count estimate and error bounds from an HLL sketch.\nThe result will be an array containing three double values: estimate, lower bound and upper bound.\nThe bounds are provided at a given number of standard deviations (optional, defaults to 1).\nThis must be an integer value of 1, 2 or 3 corresponding to approximately 68.3%, 95.4% and 99.7% confidence intervals."),(0,i.yg)("pre",null,(0,i.yg)("code",{parentName:"pre"},'{\n "type": "HLLSketchEstimateWithBounds",\n "name": <output name>,\n "field": <post aggregator that returns an HLL Sketch>,\n "numStdDev": <number of standard deviations: 1 (default), 2 or 3>\n}\n')),(0,i.yg)("h3",{id:"union"},"Union"),(0,i.yg)("pre",null,(0,i.yg)("code",{parentName:"pre"},'{\n "type": "HLLSketchUnion",\n "name": <output name>,\n "fields": <array of post aggregators that return HLL sketches>,\n "lgK": <log2 of K for the target sketch>,\n "tgtHllType": <target HLL type>\n}\n')),(0,i.yg)("h3",{id:"sketch-to-string"},"Sketch to string"),(0,i.yg)("p",null,"Human-readable sketch summary for debugging."),(0,i.yg)("pre",null,(0,i.yg)("code",{parentName:"pre"},'{\n "type": "HLLSketchToString",\n "name": <output name>,\n "field": <post aggregator that returns an HLL Sketch>\n}\n')))}m.isMDXComponent=!0}}]);