Expand description
Spatial (ST_*) function evaluator.
This module closes the eval gap between the query planner and the row-based filter interpreter. The parser turns SQL like
WHERE ST_Intersects(geom, 'POLYGON((...))')into an Expr::Function node. The
Filter operator now forwards every
Expr::Function to evaluate_spatial_function, which dispatches on the
function name (case-insensitive) and returns either a typed
Value or a typed
QueryError.
§Value-variant rationale
The runtime
Value enum lives in
crates/oxigdal-query/src/executor/filter.rs (it is the row-level value
type used by the row-based interpreter). A grep of Value:: across
crates/oxigdal-query/src confirmed that every match on Value uses a
_ => … catch-all (binary/unary operator dispatch, comparison fall-through,
filter column extraction, etc.). Adding a new variant is therefore safe and
does not regress any existing call site.
Following that observation we chose Value::Geometry(geo::Geometry<f64>)
over the alternative Value::Wkt(String). Reasons:
- Set-operation and constructor functions (
ST_Centroid,ST_Envelope,ST_Buffer,ST_Intersection, …) naturally produce a typedgeo::Geometry<f64>; round-tripping through aStringwould waste cycles and lose precision via float-to-text conversion. - Downstream predicate evaluators (
ST_Intersects,ST_Contains, …) keep the geometry in its parsed form, so they avoid re-parsing WKT on every row. - The variant is constructed by this module only; literal WKT strings
embedded in SQL stay as
Value::Stringuntil parsed insideparse_geometry_arg, so the SQL parser/optimizer surface is unchanged.
§Function dispatch
Names match case-insensitively (the SQL parser preserves the original casing). Supported operations:
| Name | Arity | Result kind |
|---|---|---|
ST_Intersects(a, b) | 2 | Value::Boolean |
ST_Contains(a, b) | 2 | Value::Boolean |
ST_Within(a, b) | 2 | Value::Boolean |
ST_Disjoint(a, b) | 2 | Value::Boolean |
ST_Equals(a, b) | 2 | Value::Boolean |
ST_Touches(a, b) | 2 | Value::Boolean |
ST_Overlaps(a, b) | 2 | Value::Boolean |
ST_Crosses(a, b) | 2 | Value::Boolean |
ST_Covers(a, b) | 2 | Value::Boolean |
ST_CoveredBy(a, b) | 2 | Value::Boolean |
ST_DWithin(a, b, dist) | 3 | Value::Boolean |
ST_Distance(a, b) | 2 | Value::Float64 |
ST_Area(g) | 1 | Value::Float64 |
ST_Length(g) | 1 | Value::Float64 |
ST_Centroid(g) | 1 | Value::Geometry |
ST_Envelope(g) | 1 | Value::Geometry |
ST_Buffer(g, dist) | 2 | Value::Geometry |
ST_Intersection(a, b) | 2 | Value::Geometry |
ST_Union(a, b) | 2 | Value::Geometry |
ST_Difference(a, b) | 2 | Value::Geometry |
Unsupported geometry combinations (e.g. BooleanOps on a non-Polygon)
return a typed QueryError::Unsupported rather than panicking.
Functions§
- evaluate_
spatial_ function - Evaluate a spatial (
ST_*) function call.