blob: 8932c9a958be7ba8478537f3b7daee5b4fe7f291 [file] [log] [blame]
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[6887],{3905:(e,t,n)=>{n.d(t,{Zo:()=>m,kt:()=>g});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 s=a.createContext({}),p=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):l(l({},t),e)),n},m=function(e){var t=p(e.components);return a.createElement(s.Provider,{value:t},e.children)},u="mdxType",d={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,m=o(e,["components","mdxType","originalType","parentName"]),u=p(n),c=r,g=u["".concat(s,".").concat(c)]||u[c]||d[c]||i;return n?a.createElement(g,l(l({ref:t},m),{},{components:n})):a.createElement(g,l({ref:t},m))}));function g(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var i=n.length,l=new Array(i);l[0]=c;var o={};for(var s in t)hasOwnProperty.call(t,s)&&(o[s]=t[s]);o.originalType=e,o[u]="string"==typeof e?e:r,l[1]=o;for(var p=2;p<i;p++)l[p]=n[p];return a.createElement.apply(null,l)}return a.createElement.apply(null,n)}c.displayName="MDXCreateElement"},528:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>m,contentTitle:()=>s,default:()=>g,frontMatter:()=>o,metadata:()=>p,toc:()=>u});var a=n(7462),r=n(3366),i=(n(7294),n(3905)),l=["components"],o={id:"compressed-big-decimal",title:"Compressed Big Decimal"},s=void 0,p={unversionedId:"development/extensions-contrib/compressed-big-decimal",id:"development/extensions-contrib/compressed-big-decimal",title:"Compressed Big Decimal",description:"\x3c!--",source:"@site/docs/26.0.0/development/extensions-contrib/compressed-big-decimal.md",sourceDirName:"development/extensions-contrib",slug:"/development/extensions-contrib/compressed-big-decimal",permalink:"/docs/26.0.0/development/extensions-contrib/compressed-big-decimal",draft:!1,tags:[],version:"current",frontMatter:{id:"compressed-big-decimal",title:"Compressed Big Decimal"}},m={},u=[{value:"Overview",id:"overview",level:2},{value:"Main enhancements provided by this extension:",id:"main-enhancements-provided-by-this-extension",level:4},{value:"Operations",id:"operations",level:2},{value:"Configuration",id:"configuration",level:2},{value:"Limitations",id:"limitations",level:2},{value:"Ingestion Spec:",id:"ingestion-spec",level:3},{value:"Query spec:",id:"query-spec",level:3},{value:"Examples",id:"examples",level:2},{value:"Group By Query example",id:"group-by-query--example",level:3},{value:"TimeSeries Query Example",id:"timeseries-query-example",level:3}],d={toc:u},c="wrapper";function g(e){var t=e.components,n=(0,r.Z)(e,l);return(0,i.kt)(c,(0,a.Z)({},d,n,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("h2",{id:"overview"},"Overview"),(0,i.kt)("p",null,(0,i.kt)("strong",{parentName:"p"},"Compressed Big Decimal")," is an extension which provides support for Mutable big decimal value that can be used to accumulate values without losing precision or reallocating memory. This type helps in absolute precision arithmetic on large numbers in applications, where greater level of accuracy is required, such as financial applications, currency based transactions. This helps avoid rounding issues where in potentially large amount of money can be lost."),(0,i.kt)("p",null,"Accumulation requires that the two numbers have the same scale, but does not require that they are of the same size. If the value being accumulated has a larger underlying array than this value (the result), then the higher order bits are dropped, similar to what happens when adding a long to an int and storing the result in an int. A compressed big decimal that holds its data with an embedded array."),(0,i.kt)("p",null,"Compressed big decimal is an absolute number based complex type based on big decimal in Java. This supports all the functionalities supported by Java Big Decimal. Java Big Decimal is not mutable in order to avoid big garbage collection issues. Compressed big decimal is needed to mutate the value in the accumulator."),(0,i.kt)("h4",{id:"main-enhancements-provided-by-this-extension"},"Main enhancements provided by this extension:"),(0,i.kt)("ol",null,(0,i.kt)("li",{parentName:"ol"},"Functionality: Mutating Big decimal type with greater precision "),(0,i.kt)("li",{parentName:"ol"},"Accuracy: Provides greater level of accuracy in decimal arithmetic")),(0,i.kt)("h2",{id:"operations"},"Operations"),(0,i.kt)("p",null,"To use this extension, make sure to ",(0,i.kt)("a",{parentName:"p",href:"/docs/26.0.0/development/extensions#loading-extensions"},"load")," ",(0,i.kt)("inlineCode",{parentName:"p"},"compressed-big-decimal")," to your config file."),(0,i.kt)("h2",{id:"configuration"},"Configuration"),(0,i.kt)("p",null,"There are currently no configuration properties specific to Compressed Big Decimal"),(0,i.kt)("h2",{id:"limitations"},"Limitations"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Compressed Big Decimal does not provide correct result when the value being accumulated has a larger underlying array than this value (the result), then the higher order bits are dropped, similar to what happens when adding a long to an int and storing the result in an int.")),(0,i.kt)("h3",{id:"ingestion-spec"},"Ingestion Spec:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Most properties in the Ingest spec derived from ",(0,i.kt)("a",{parentName:"li",href:"/docs/26.0.0/ingestion/"},"Ingestion Spec")," / ",(0,i.kt)("a",{parentName:"li",href:"/docs/26.0.0/ingestion/data-formats"},"Data Formats"))),(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},"property"),(0,i.kt)("th",{parentName:"tr",align:null},"description"),(0,i.kt)("th",{parentName:"tr",align:null},"required?"))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"metricsSpec"),(0,i.kt)("td",{parentName:"tr",align:null},"Metrics Specification, In metrics specification while specifying metrics details such as name, type should be specified as compressedBigDecimal"),(0,i.kt)("td",{parentName:"tr",align:null},"Yes")))),(0,i.kt)("h3",{id:"query-spec"},"Query spec:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Most properties in the query spec derived from ",(0,i.kt)("a",{parentName:"li",href:"/docs/26.0.0/querying/groupbyquery"},"groupBy query")," / ",(0,i.kt)("a",{parentName:"li",href:"/docs/26.0.0/querying/timeseriesquery"},"timeseries"),", see documentation for these query types.")),(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},"property"),(0,i.kt)("th",{parentName:"tr",align:null},"description"),(0,i.kt)("th",{parentName:"tr",align:null},"required?"))),(0,i.kt)("tbody",{parentName:"table"},(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"queryType"),(0,i.kt)("td",{parentName:"tr",align:null},'This String should always be either "groupBy" OR "timeseries"; this is the first thing Druid looks at to figure out how to interpret the query.'),(0,i.kt)("td",{parentName:"tr",align:null},"yes")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"dataSource"),(0,i.kt)("td",{parentName:"tr",align:null},"A String or Object defining the data source to query, very similar to a table in a relational database. See ",(0,i.kt)("a",{parentName:"td",href:"/docs/26.0.0/querying/datasource"},"DataSource")," for more information."),(0,i.kt)("td",{parentName:"tr",align:null},"yes")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"dimensions"),(0,i.kt)("td",{parentName:"tr",align:null},"A JSON list of ",(0,i.kt)("a",{parentName:"td",href:"/docs/26.0.0/querying/dimensionspecs"},"DimensionSpec")," (Notice that property is optional)"),(0,i.kt)("td",{parentName:"tr",align:null},"no")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"limitSpec"),(0,i.kt)("td",{parentName:"tr",align:null},"See ",(0,i.kt)("a",{parentName:"td",href:"/docs/26.0.0/querying/limitspec"},"LimitSpec")),(0,i.kt)("td",{parentName:"tr",align:null},"no")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"having"),(0,i.kt)("td",{parentName:"tr",align:null},"See ",(0,i.kt)("a",{parentName:"td",href:"/docs/26.0.0/querying/having"},"Having")),(0,i.kt)("td",{parentName:"tr",align:null},"no")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"granularity"),(0,i.kt)("td",{parentName:"tr",align:null},"A period granularity; See ",(0,i.kt)("a",{parentName:"td",href:"../../querying/granularities.html#period-granularities"},"Period Granularities")),(0,i.kt)("td",{parentName:"tr",align:null},"yes")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"filter"),(0,i.kt)("td",{parentName:"tr",align:null},"See ",(0,i.kt)("a",{parentName:"td",href:"/docs/26.0.0/querying/filters"},"Filters")),(0,i.kt)("td",{parentName:"tr",align:null},"no")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"aggregations"),(0,i.kt)("td",{parentName:"tr",align:null},"Aggregations forms the input to Averagers; See ",(0,i.kt)("a",{parentName:"td",href:"/docs/26.0.0/querying/aggregations"},"Aggregations"),". The Aggregations must specify type, scale and size as follows for compressedBigDecimal Type ",(0,i.kt)("inlineCode",{parentName:"td"},'"aggregations": [{"type": "compressedBigDecimal","name": "..","fieldName": "..","scale": [Numeric],"size": [Numeric]}'),". Please refer query example in Examples section."),(0,i.kt)("td",{parentName:"tr",align:null},"Yes")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"postAggregations"),(0,i.kt)("td",{parentName:"tr",align:null},"Supports only aggregations as input; See ",(0,i.kt)("a",{parentName:"td",href:"/docs/26.0.0/querying/post-aggregations"},"Post Aggregations")),(0,i.kt)("td",{parentName:"tr",align:null},"no")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"intervals"),(0,i.kt)("td",{parentName:"tr",align:null},"A JSON Object representing ISO-8601 Intervals. This defines the time ranges to run the query over."),(0,i.kt)("td",{parentName:"tr",align:null},"yes")),(0,i.kt)("tr",{parentName:"tbody"},(0,i.kt)("td",{parentName:"tr",align:null},"context"),(0,i.kt)("td",{parentName:"tr",align:null},"An additional JSON Object which can be used to specify certain flags."),(0,i.kt)("td",{parentName:"tr",align:null},"no")))),(0,i.kt)("h2",{id:"examples"},"Examples"),(0,i.kt)("p",null,"Consider the data as"),(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},"Date"),(0,i.kt)("th",{parentName:"tr",align:null},"Item"),(0,i.kt)("th",{parentName:"tr",align:null},"SaleAmount")))),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"20201208,ItemA,0.0\n20201208,ItemB,10.000000000\n20201208,ItemA,-1.000000000\n20201208,ItemC,9999999999.000000000\n20201208,ItemB,5000000000.000000005\n20201208,ItemA,2.0\n20201208,ItemD,0.0\n")),(0,i.kt)("p",null,"IngestionSpec syntax:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-json"},'{\n "type": "index_parallel",\n "spec": {\n "dataSchema": {\n "dataSource": "invoices",\n "timestampSpec": {\n "column": "timestamp",\n "format": "yyyyMMdd"\n },\n "dimensionsSpec": {\n "dimensions": [{\n "type": "string",\n "name": "itemName"\n }]\n },\n "metricsSpec": [{\n "name": "saleAmount",\n "type": *"compressedBigDecimal"*,\n "fieldName": "saleAmount"\n }],\n "transformSpec": {\n "filter": null,\n "transforms": []\n },\n "granularitySpec": {\n "type": "uniform",\n "rollup": false,\n "segmentGranularity": "DAY",\n "queryGranularity": "none",\n "intervals": ["2020-12-08/2020-12-09"]\n }\n },\n "ioConfig": {\n "type": "index_parallel",\n "inputSource": {\n "type": "local",\n "baseDir": "/home/user/sales/data/staging/invoice-data",\n "filter": "invoice-001.20201208.txt"\n },\n "inputFormat": {\n "type": "tsv",\n "delimiter": ",",\n "skipHeaderRows": 0,\n "columns": [\n "timestamp",\n "itemName",\n "saleAmount"\n ]\n }\n },\n "tuningConfig": {\n "type": "index_parallel"\n }\n }\n}\n')),(0,i.kt)("h3",{id:"group-by-query--example"},"Group By Query example"),(0,i.kt)("p",null,"Calculating sales groupBy all."),(0,i.kt)("p",null,"Query syntax:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-json"},'{\n "queryType": "groupBy",\n "dataSource": "invoices",\n "granularity": "ALL",\n "dimensions": [\n ],\n "aggregations": [\n {\n "type": "compressedBigDecimal",\n "name": "saleAmount",\n "fieldName": "saleAmount",\n "scale": 9,\n "size": 3\n\n }\n ],\n "intervals": [\n "2020-01-08T00:00:00.000Z/P1D"\n ]\n}\n')),(0,i.kt)("p",null,"Result:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-json"},'[ {\n "version" : "v1",\n "timestamp" : "2020-12-08T00:00:00.000Z",\n "event" : {\n "revenue" : 15000000010.000000005\n }\n} ]\n')),(0,i.kt)("p",null,"Had you used ",(0,i.kt)("em",{parentName:"p"},"doubleSum")," instead of compressedBigDecimal the result would be "),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-json"},'[ {\n "timestamp" : "2020-12-08T00:00:00.000Z",\n "result" : {\n "revenue" : 1.500000001E10\n }\n} ]\n')),(0,i.kt)("p",null,"As shown above the precision is lost and could lead to loss in money."),(0,i.kt)("h3",{id:"timeseries-query-example"},"TimeSeries Query Example"),(0,i.kt)("p",null,"Query syntax:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-json"},'{\n "queryType": "timeseries",\n "dataSource": "invoices",\n "granularity": "ALL",\n "aggregations": [\n {\n "type": "compressedBigDecimal",\n "name": "revenue",\n "fieldName": "revenue",\n "scale": 9,\n "size": 3\n }\n ],\n "filter": {\n "type": "not",\n "field": {\n "type": "selector",\n "dimension": "itemName",\n "value": "ItemD"\n }\n },\n "intervals": [\n "2020-12-08T00:00:00.000Z/P1D"\n ]\n}\n')),(0,i.kt)("p",null,"Result:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-json"},'[ {\n "timestamp" : "2020-12-08T00:00:00.000Z",\n "result" : {\n "revenue" : 15000000010.000000005\n }\n} ]\n')))}g.isMDXComponent=!0}}]);