Skip to content

rust/sedona-functions: Implement ST_xxxFromText() functions #205

@paleolimbot

Description

@paleolimbot

There are a number of variants of ST_GeomFromText that are identical except they error if a specific data type was not passed. These functions are:

  • ST_GeomCollFromText
  • ST_MPointFromText
  • ST_LineFromText
  • ST_LineStringFromText
  • ST_MLineFromText
  • ST_MPointFromText
  • ST_MPolyFromText
  • ST_PointFromText
  • ST_PolygonFromText

I believe these could all be implemented by adding an (optional) "expected geometry type" here:

fn invoke_scalar(wkt_bytes: &str, builder: &mut BinaryBuilder) -> Result<()> {
let geometry: Wkt<f64> = Wkt::from_str(wkt_bytes)
.map_err(|err| DataFusionError::Internal(format!("WKT parse error: {err}")))?;
write_geometry(builder, &geometry, wkb::Endianness::LittleEndian)
.map_err(|err| DataFusionError::Internal(format!("WKB write error: {err}")))
}

...and add an expected_geometry_type: Option<GeometryTypeId> here:

#[derive(Debug)]
struct STGeoFromWKT {
out_type: SedonaType,
}

Then these functions can be constructed and declared here with their documentation:

/// ST_GeomFromWKT() UDF implementation
///
/// An implementation of WKT reading using GeoRust's wkt crate.
/// See [`st_geogfromwkt_udf`] for the corresponding geography function.
pub fn st_geomfromwkt_udf() -> SedonaScalarUDF {

We should ensure that this doesn't slow down the general case, although I don't think that in the context of WKT parsing this will be measurable.

I don't think we need Geography constructors like this, because nobody else provides them either (these functions would be for OGC/PostGIS compatibility).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions