Skip to content

feat(rust/sedona-functions): implement ST_XxxFromText typed geometry constructors (issue #205)#993

Merged
paleolimbot merged 3 commits into
apache:mainfrom
ajaypadwal73:feat/st-geomfromtext-variants-clean
Jun 24, 2026
Merged

feat(rust/sedona-functions): implement ST_XxxFromText typed geometry constructors (issue #205)#993
paleolimbot merged 3 commits into
apache:mainfrom
ajaypadwal73:feat/st-geomfromtext-variants-clean

Conversation

@ajaypadwal73

Copy link
Copy Markdown
Contributor

Summary

Closes #205.

Implements the typed WKT constructor functions listed in the issue:

  • ST_GeomCollFromText — errors if input is not a GeometryCollection
  • ST_LineFromText — errors if input is not a LineString (alias: ST_LineStringFromText)
  • ST_MLineFromText — errors if input is not a MultiLineString
  • ST_MPointFromText — errors if input is not a MultiPoint
  • ST_MPolyFromText — errors if input is not a MultiPolygon
  • ST_PointFromText — errors if input is not a Point
  • ST_PolygonFromText — errors if input is not a Polygon

Implementation

Added ExpectedGeomType enum and an expected_geom_type: Option<ExpectedGeomType> field to the existing STGeoFromWKT struct. All parsing, SRID, and CRS propagation logic is shared with ST_GeomFromWKT — no duplication.

A make_typed_geom_udf helper constructs each function with one line.

Tests

  • typed_constructors_accept_correct_type — all 7 functions accept their matching WKT type
  • typed_constructors_reject_wrong_type — error message includes expected type name
  • typed_constructors_accept_srid — all 7 functions work with the optional SRID argument

Docs

Reference .qmd added for each function including SRID examples. CI doc check passes (Missing docs: 0, Missing alias mentions: 0).

…che#205)

Add ST_GeomCollFromText, ST_LineFromText, ST_LineStringFromText (alias),
ST_MLineFromText, ST_MPointFromText, ST_MPolyFromText, ST_PointFromText,
and ST_PolygonFromText. Each function parses WKT and errors if the result
does not match the expected geometry type, providing OGC/PostGIS
compatibility.

Implemented by adding an optional ExpectedGeomType to STGeoFromWKT,
sharing all parsing and SRID logic with ST_GeomFromWKT.

@paleolimbot paleolimbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Can you add Python tests to confirm parity with PostGIS here?

Can you also confirm the behaviour for EMPTY types? (i.e., is LINESTRING EMTPY rejected by ST_GeomCollFromText()`)?

Comment thread docs/reference/sql/st_linefromtext.qmd Outdated

Parses a WKT string and returns a geometry. Raises an error if the WKT does not represent a LineString.

This function also has the alias `ST_LineStringFromText`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This function also has the alias `ST_LineStringFromText`.
Aliases: `ST_LineStringFromText`.

SELECT ST_PolygonFromText('POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0))');
```

With an SRID:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
With an SRID:
With an SRID or CRS:

(For the others as well)

Comment on lines +41 to +43
/// Geometry type constraint used by ST_XxxFromText functions.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum ExpectedGeomType {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use sedona_geometry::...::GeometryTypeId for this to avoid the duplicated enum?

Comment on lines +581 to +583
#[test]
fn typed_constructors_accept_correct_type() {
let cases: &[(&str, SedonaScalarUDF)] = &[

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use rstest parameterized tests for consistency here?

…, fix docs

- Replace custom ExpectedGeomType enum with sedona_geometry::types::GeometryTypeId
  to avoid duplication; use .geojson_id() for error messages
- Convert typed_constructors_accept_correct_type, accept_srid, and reject_wrong_type
  Rust tests to rstest #[case] parametrize covering all 7 constructors
- Add Python integration tests: accept correct type, reject wrong type, accept SRID,
  accept matching EMPTY, reject wrong EMPTY (all 7), null input, ST_LineStringFromText alias
- Fix ST_LineFromText doc: 'This function also has the alias' -> 'Aliases:'
- Fix all 7 typed constructor docs: 'With an SRID:' -> 'With an SRID or CRS:'
@ajaypadwal73

ajaypadwal73 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Hi @paleolimbot , I've addressed all the feedback:

ExpectedGeomType → GeometryTypeId: Replaced the custom enum with sedona_geometry::types::GeometryTypeId and switched error messages to use .geojson_id().
rstest parametrize: All three Rust test functions (accept_correct_type, accept_srid, reject_wrong_type) now use #[rstest] + #[case] covering all 7 constructors.
Python integration tests: Added tests for correct type acceptance, wrong type rejection (including wrong EMPTY types for all 7 constructors - covers your question about LINESTRING EMPTY in ST_GeomCollFromText), SRID, matching EMPTY input, null input, and the ST_LineStringFromText alias - all parametrized against both SedonaDB and PostGIS.
Docs: Aliases: \ST_LineStringFromTextinst_linefromtext.qmd; With an SRID or CRS: across all 7 reference pages.

…or tests

- ST_MPointFromText: use geoarrow-c canonical form (no per-point parens)
- reject_wrong_type: SedonaDB-only; PostGIS typed constructors are aliases
  for ST_GeomFromText and do not validate geometry type
- accept_matching_empty: POINT EMPTY renders as POINT (nan nan) via geoarrow-c
- ST_LineStringFromText alias: SedonaDB-only; function does not exist in PostGIS
- reject_wrong_empty: SedonaDB-only; same reason as reject_wrong_type

@paleolimbot paleolimbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@paleolimbot paleolimbot changed the title feat: implement ST_XxxFromText typed geometry constructors (issue #205) feat(rust/sedona-functions): implement ST_XxxFromText typed geometry constructors (issue #205) Jun 24, 2026
@paleolimbot paleolimbot merged commit 178543b into apache:main Jun 24, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rust/sedona-functions: Implement ST_xxxFromText() functions

2 participants