Support geohash, geotile and geohex grid types #129581
Open
+4,157
−2,213
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The PR at #125143 added support for
ST_GEOHASH
,ST_GEOTILE
andST_GEOHEX
. However, since it usedlong
as the internal type for the grid id, there was need for many additional functions for converting thelong
to and fromkeyword
as well as generatinggeo_shape
cell bounds for map display. Each pf these involved many more files (for the functions, their docs and the generated evaluators). With inspiration from PostGIS we decided to take a different direction, and instead use a new internal type for each grid:geohash
for theST_GEOHASH
function, created from literal using eitherTO_GEOHASH(hash)
orhash::geohash
geotile
for theST_GEOTILE
function, created from literal using eitherTO_GEOTILE(tile)
ortile::geotile
geohex
for theST_GEOHEX
function, created from literal using eitherTO_GEOHEX(h3)
orh3::geohex
This also leads to much stricter type checking as we can no longer use the
long
as a plainlong
in all functions that accept longs, or inadvertently using a geohash in a geotile function. However, the addition of new types involves a lot of boilerplate, especially considering the large number of functions that operate on all types, and need to be informed of the existence of these three new types.One of the main goals of this work was to also support the concept of a geogrid search. This means "find all documents that intersect a grid cell", similar to the Query DSL version. This is achieved by enabling the use of these three new types in the
ST_INTERSECTS
function, so a query like this would satisfy the requirement: