Spatial filters

Apache Druid supports filtering specially spatially indexed columns based on an origin and a bound.

Spatial indexing

In any of the data specs, there is the option of providing spatial dimensions. For example, for a JSON data spec, spatial dimensions can be specified as follows:

  1. {
  2. "type": "hadoop",
  3. "dataSchema": {
  4. "dataSource": "DatasourceName",
  5. "parser": {
  6. "type": "string",
  7. "parseSpec": {
  8. "format": "json",
  9. "timestampSpec": {
  10. "column": "timestamp",
  11. "format": "auto"
  12. },
  13. "dimensionsSpec": {
  14. "dimensions": [],
  15. "spatialDimensions": [{
  16. "dimName": "coordinates",
  17. "dims": ["lat", "long"]
  18. }]
  19. }
  20. }
  21. }
  22. }
  23. }

Spatial filters

propertydescriptionrequired?
dimNameThe name of the spatial dimension. A spatial dimension may be constructed from multiple 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.yes
dimsA list of dimension names that comprise a spatial dimension.no

The grammar for a spatial filter is as follows:

  1. "filter" : {
  2. "type": "spatial",
  3. "dimension": "spatialDim",
  4. "bound": {
  5. "type": "rectangular",
  6. "minCoords": [10.0, 20.0],
  7. "maxCoords": [30.0, 40.0]
  8. }
  9. }

Bound types

rectangular

propertydescriptionrequired?
minCoordsList of minimum dimension coordinates for coordinates [x, y, z, …]yes
maxCoordsList of maximum dimension coordinates for coordinates [x, y, z, …]yes

radius

propertydescriptionrequired?
coordsOrigin coordinates in the form [x, y, z, …]yes
radiusThe float radius valueyes

polygon

propertydescriptionrequired?
abscissaHorizontal coordinate for corners of the polygonyes
ordinateVertical coordinate for corners of the polygonyes