blob: 37c704d61be8603a748c754d5844f5be285739c4 [file] [log] [blame]
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[5167],{15680:(e,n,t)=>{t.d(n,{xA:()=>g,yg:()=>m});var a=t(96540);function r(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function i(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);n&&(a=a.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,a)}return t}function l(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?i(Object(t),!0).forEach((function(n){r(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):i(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function o(e,n){if(null==e)return{};var t,a,r=function(e,n){if(null==e)return{};var t,a,r={},i=Object.keys(e);for(a=0;a<i.length;a++)t=i[a],n.indexOf(t)>=0||(r[t]=e[t]);return r}(e,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(a=0;a<i.length;a++)t=i[a],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(r[t]=e[t])}return r}var s=a.createContext({}),p=function(e){var n=a.useContext(s),t=n;return e&&(t="function"==typeof e?e(n):l(l({},n),e)),t},g=function(e){var n=p(e.components);return a.createElement(s.Provider,{value:n},e.children)},d="mdxType",y={inlineCode:"code",wrapper:function(e){var n=e.children;return a.createElement(a.Fragment,{},n)}},u=a.forwardRef((function(e,n){var t=e.components,r=e.mdxType,i=e.originalType,s=e.parentName,g=o(e,["components","mdxType","originalType","parentName"]),d=p(t),u=r,m=d["".concat(s,".").concat(u)]||d[u]||y[u]||i;return t?a.createElement(m,l(l({ref:n},g),{},{components:t})):a.createElement(m,l({ref:n},g))}));function m(e,n){var t=arguments,r=n&&n.mdxType;if("string"==typeof e||r){var i=t.length,l=new Array(i);l[0]=u;var o={};for(var s in n)hasOwnProperty.call(n,s)&&(o[s]=n[s]);o.originalType=e,o[d]="string"==typeof e?e:r,l[1]=o;for(var p=2;p<i;p++)l[p]=t[p];return a.createElement.apply(null,l)}return a.createElement.apply(null,t)}u.displayName="MDXCreateElement"},74440:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>g,contentTitle:()=>s,default:()=>m,frontMatter:()=>o,metadata:()=>p,toc:()=>d});var a=t(58168),r=t(98587),i=(t(96540),t(15680)),l=["components"],o={id:"geo",title:"Spatial filters"},s=void 0,p={unversionedId:"querying/geo",id:"querying/geo",title:"Spatial filters",description:"\x3c!--",source:"@site/docs/latest/querying/geo.md",sourceDirName:"querying",slug:"/querying/geo",permalink:"/docs/latest/querying/geo",draft:!1,tags:[],version:"current",frontMatter:{id:"geo",title:"Spatial filters"},sidebar:"docs",previous:{title:"Virtual columns",permalink:"/docs/latest/querying/virtual-columns"},next:{title:"Overview",permalink:"/docs/latest/api-reference/"}},g={},d=[{value:"Spatial indexing",id:"spatial-indexing",level:2},{value:"Spatial filters",id:"spatial-filters",level:2},{value:"Bound types",id:"bound-types",level:3},{value:"Rectangular",id:"rectangular",level:4},{value:"Radius",id:"radius",level:4},{value:"Polygon",id:"polygon",level:4}],y={toc:d},u="wrapper";function m(e){var n=e.components,t=(0,r.A)(e,l);return(0,i.yg)(u,(0,a.A)({},y,t,{components:n,mdxType:"MDXLayout"}),(0,i.yg)("admonition",{type:"info"},(0,i.yg)("p",{parentName:"admonition"}," Apache Druid supports two query languages: ",(0,i.yg)("a",{parentName:"p",href:"/docs/latest/querying/sql"},"Druid SQL")," and ",(0,i.yg)("a",{parentName:"p",href:"/docs/latest/querying/"},"native queries"),".\nThis document describes a feature that is only available in the native language.")),(0,i.yg)("p",null,"Apache Druid supports filtering spatially indexed columns based on an origin and a bound."),(0,i.yg)("p",null,"This topic explains how to ingest and query spatial filters.\nFor information on other filters supported by Druid, see ",(0,i.yg)("a",{parentName:"p",href:"/docs/latest/querying/filters"},"Query filters"),"."),(0,i.yg)("h2",{id:"spatial-indexing"},"Spatial indexing"),(0,i.yg)("p",null,"Spatial indexing refers to ingesting data of a spatial data type, such as geometry or geography, into Druid."),(0,i.yg)("p",null,"Spatial dimensions are string columns that contain coordinates separated by a comma.\nIn the ingestion spec, you configure spatial dimensions in the ",(0,i.yg)("inlineCode",{parentName:"p"},"dimensionsSpec")," object of the ",(0,i.yg)("inlineCode",{parentName:"p"},"dataSchema")," component."),(0,i.yg)("p",null,"You can provide spatial dimensions in any of the ",(0,i.yg)("a",{parentName:"p",href:"/docs/latest/ingestion/data-formats"},"data formats")," supported by Druid.\nThe following example shows an ingestion spec with a spatial dimension named ",(0,i.yg)("inlineCode",{parentName:"p"},"coordinates"),", which is constructed from the input fields ",(0,i.yg)("inlineCode",{parentName:"p"},"x")," and ",(0,i.yg)("inlineCode",{parentName:"p"},"y"),":"),(0,i.yg)("pre",null,(0,i.yg)("code",{parentName:"pre",className:"language-json"},'{\n "type": "hadoop",\n "dataSchema": {\n "dataSource": "DatasourceName",\n "parser": {\n "type": "string",\n "parseSpec": {\n "format": "json",\n "timestampSpec": {\n "column": "timestamp",\n "format": "auto"\n },\n "dimensionsSpec": {\n "dimensions": [\n {\n "type": "double",\n "name": "x"\n },\n {\n "type": "double",\n "name": "y"\n }\n ],\n "spatialDimensions": [\n {\n "dimName": "coordinates",\n "dims": [\n "x",\n "y"\n ]\n }\n ]\n }\n }\n }\n }\n}\n')),(0,i.yg)("p",null,"Each spatial dimension object in the ",(0,i.yg)("inlineCode",{parentName:"p"},"spatialDimensions")," array is defined by the following fields:"),(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"},"dimName")),(0,i.yg)("td",{parentName:"tr",align:null},"The name of a spatial dimension. You can construct a spatial dimension from other dimensions or it may already exist as part of an event. If a spatial dimension already exists, it must be an array of coordinate 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"},"dims")),(0,i.yg)("td",{parentName:"tr",align:null},"The list of dimension names that comprise the spatial dimension."),(0,i.yg)("td",{parentName:"tr",align:null},"no")))),(0,i.yg)("p",null,"For information on how to use the ingestion spec to configure ingestion, see ",(0,i.yg)("a",{parentName:"p",href:"/docs/latest/ingestion/ingestion-spec"},"Ingestion spec reference"),".\nFor general information on loading data in Druid, see ",(0,i.yg)("a",{parentName:"p",href:"/docs/latest/ingestion/"},"Ingestion"),"."),(0,i.yg)("h2",{id:"spatial-filters"},"Spatial filters"),(0,i.yg)("p",null,"A ",(0,i.yg)("a",{parentName:"p",href:"/docs/latest/querying/filters"},"filter")," is a JSON object indicating which rows of data should be included in the computation for a query.\nYou can filter on spatial structures, such as rectangles and polygons, using the spatial filter."),(0,i.yg)("p",null,"Spatial filters have the following structure:"),(0,i.yg)("pre",null,(0,i.yg)("code",{parentName:"pre",className:"language-json"},'"filter": {\n "type": "spatial",\n "dimension": <name_of_spatial_dimension>,\n "bound": <bound_type>\n}\n')),(0,i.yg)("p",null,"The following example shows a spatial filter with a rectangular bound type:"),(0,i.yg)("pre",null,(0,i.yg)("code",{parentName:"pre",className:"language-json"},'"filter" : {\n "type": "spatial",\n "dimension": "spatialDim",\n "bound": {\n "type": "rectangular",\n "minCoords": [10.0, 20.0],\n "maxCoords": [30.0, 40.0]\n }\n')),(0,i.yg)("p",null,"The order of the dimension coordinates in the spatial filter must be equal to the order of the dimension coordinates in the ",(0,i.yg)("inlineCode",{parentName:"p"},"spatialDimensions")," array."),(0,i.yg)("h3",{id:"bound-types"},"Bound types"),(0,i.yg)("p",null,"The ",(0,i.yg)("inlineCode",{parentName:"p"},"bound")," property of the spatial filter object lets you filter on ranges of dimension values.\nYou can define rectangular, radius, and polygon filter bounds."),(0,i.yg)("h4",{id:"rectangular"},"Rectangular"),(0,i.yg)("p",null,"The ",(0,i.yg)("inlineCode",{parentName:"p"},"rectangular")," bound has the following elements:"),(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"},"minCoords")),(0,i.yg)("td",{parentName:"tr",align:null},"The list of minimum dimension coordinates in the form ","[x, y]"),(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"},"maxCoords")),(0,i.yg)("td",{parentName:"tr",align:null},"The list of maximum dimension coordinates in the form ","[x, y]"),(0,i.yg)("td",{parentName:"tr",align:null},"yes")))),(0,i.yg)("h4",{id:"radius"},"Radius"),(0,i.yg)("p",null,"The ",(0,i.yg)("inlineCode",{parentName:"p"},"radius")," bound has the following elements:"),(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"},"coords")),(0,i.yg)("td",{parentName:"tr",align:null},"Origin coordinates in the form ","[x, y]"),(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"},"radius")),(0,i.yg)("td",{parentName:"tr",align:null},"The float radius value"),(0,i.yg)("td",{parentName:"tr",align:null},"yes")))),(0,i.yg)("h4",{id:"polygon"},"Polygon"),(0,i.yg)("p",null,"The ",(0,i.yg)("inlineCode",{parentName:"p"},"polygon")," bound has the following elements:"),(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"},"abscissa")),(0,i.yg)("td",{parentName:"tr",align:null},"Horizontal coordinates for the corners of the polygon"),(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"},"ordinate")),(0,i.yg)("td",{parentName:"tr",align:null},"Vertical coordinates for the corners of the polygon"),(0,i.yg)("td",{parentName:"tr",align:null},"yes")))))}m.isMDXComponent=!0}}]);