Skip to main content

Module spatial_funcs

Module spatial_funcs 

Source
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 typed geo::Geometry<f64>; round-tripping through a String would 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::String until parsed inside parse_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:

NameArityResult kind
ST_Intersects(a, b)2Value::Boolean
ST_Contains(a, b)2Value::Boolean
ST_Within(a, b)2Value::Boolean
ST_Disjoint(a, b)2Value::Boolean
ST_Equals(a, b)2Value::Boolean
ST_Touches(a, b)2Value::Boolean
ST_Overlaps(a, b)2Value::Boolean
ST_Crosses(a, b)2Value::Boolean
ST_Covers(a, b)2Value::Boolean
ST_CoveredBy(a, b)2Value::Boolean
ST_DWithin(a, b, dist)3Value::Boolean
ST_Distance(a, b)2Value::Float64
ST_Area(g)1Value::Float64
ST_Length(g)1Value::Float64
ST_Centroid(g)1Value::Geometry
ST_Envelope(g)1Value::Geometry
ST_Buffer(g, dist)2Value::Geometry
ST_Intersection(a, b)2Value::Geometry
ST_Union(a, b)2Value::Geometry
ST_Difference(a, b)2Value::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.