ing-bank / scruid

Scala + Druid: Scruid. A library that allows you to compose queries in Scala, and parse the result back into typesafe classes.
Apache License 2.0
115 stars 29 forks source link

Geographic queries #46

Closed anskarl closed 5 years ago

anskarl commented 5 years ago

Druid has supports filtering for spatially indexed columns based on an origin and a bound. I would like to propose to add the support for geographic queries in scruid. There are two types of filters to support, Rectangular and Radius (for details, see http://druid.io/docs/latest/development/geo.html).

Furthermore, in DQL geographic queries can be defined using the within operator in Dim class:

/**
  * Filter spatially indexed columns by specifying the bounds of minimum and maximum coordinates
  *
  * @param minCoords a list of minimum dimension coordinates for coordinates [x, y, z, ...]
  * @param maxCoords a list of maximum dimension coordinates for coordinates [x, y, z, ...]
  *
  * @return the resulting spatial filtering expression
  */
def within(minCoords: List[Double], maxCoords: List[Double]): FilteringExpression = ...

/**
  * Filter spatially indexed columns by specifying the origin coordinates and a distance
  *
  * @param coords a list of origin coordinates in the form [x, y, z, ...]
  * @param distance the distance from origin coordinates.
  *                 It can be specified in kilometers, miles or radius degrees (default)
  *
  * @return the resulting spatial filtering expression
  */
def within(coords: List[Double], distance: Double, unit: Distance.Unit = Distance.DistanceUnit.DEGREES): FilteringExpression = ...

where Distance.DistanceUnit is an enumeration for defining the unit of distance.

object DistanceUnit extends Enumeration {

  final val KM      = Value(0, "KM")
  final val MI      = Value(1, "MI")
  final val DEGREES = Value(2, "DEGREES")

  final val Kilometers = KM
  final val Miles      = MI
  final val Degrees    = DEGREES

}