Skip to content

feat: add ST_NumPoints alias for ST_NPoints#989

Open
ajaypadwal73 wants to merge 7 commits into
apache:mainfrom
ajaypadwal73:feat/st-numpoints-alias
Open

feat: add ST_NumPoints alias for ST_NPoints#989
ajaypadwal73 wants to merge 7 commits into
apache:mainfrom
ajaypadwal73:feat/st-numpoints-alias

Conversation

@ajaypadwal73

Copy link
Copy Markdown

Summary

  • Adds ST_NumPoints as an alias for ST_NPoints in st_points.rs
  • Adds a test verifying the alias is registered correctly

Closes part of #200.

Changes

  • rust/sedona-functions/src/st_points.rs: added .with_aliases(vec!["st_numpoints".to_string()]) to st_npoints_udf() and a corresponding alias test

@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!

We actually have an implementation of ST_NumPoints in c/sedona-geos that we should remove if we go ahead with this. I believe there are some tests in python/sedonadb/tests/functions that assert the behaviour of ST_NumPoints and STNPoints against PostGIS, whose documentation says they are aliases but we should make sure (or deliberately treat them as aliases anyway).

I think the alias behaviour is the one we want (BigQuery and possibly others treat them as exact aliases too).

Comment thread docs/reference/sql/st_npoints.qmd Outdated
@ajaypadwal73 ajaypadwal73 force-pushed the feat/st-numpoints-alias branch from 61e3b96 to 8d8db4c Compare June 21, 2026 16:29
ST_NumPoints is now an alias for ST_NPoints (registered via with_aliases
in rust/sedona-functions). The separate GEOS implementation in
c/sedona-geos was LineString-only (returned NULL for other types).
Remove it to avoid the duplicate registration conflict.

Update test_st_numpoints expected values to reflect alias behavior:
ST_NumPoints now counts vertices across all geometry types, matching
ST_NPoints and PostGIS documentation.
@ajaypadwal73

Copy link
Copy Markdown
Author

@paleolimbot Thanks for the context! Agreed - treating them as exact aliases (consistent with BigQuery) makes more sense than strict PostGIS LineString-only behavior. The old GEOS st_numpoints implementation has been removed and the Python tests updated to reflect the alias semantics.

@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! The PostGIS docs indicate that these functions are supposed to be aliases but they don't seem to be (as you just found out). I think an alias is the right move.

One note on the test but other that this is good to go!

Comment on lines -3772 to -3780
("geom", "expected"),
[
(None, None),
("POINT EMPTY", None),
("POINT EMPTY", 0),
("LINESTRING EMPTY", 0),
("POLYGON EMPTY", None),
("MULTIPOINT EMPTY", None),
("MULTILINESTRING EMPTY", None),
("MULTIPOLYGON EMPTY", None),

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.

Sorry to bikeshed here, but can we just remove this test and add a second line to the ST_NPoints test? That will ensure that the behaviour stays in sync and any added parameters always apply to both.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@paleolimbot Done - standalone test_st_numpoints removed and ST_NumPoints assertion added directly into test_st_points alongside ST_NPoints, sharing the same parametrized cases.

…ctations

Per review feedback: remove standalone test_st_numpoints from test_functions.py
and add ST_NumPoints as a third assertion in test_st_points, keeping both
aliases in sync automatically.

Also update test_geog_mechanical_transforms.py ST_NumPoints expected values
to reflect alias behavior (all geometry types return counts, not just
LineStrings).
PostGIS treats ST_NumPoints as LineString-only in practice, returning NULL
for other geometry types, even though its documentation lists it as an alias
for ST_NPoints. Skip the ST_NumPoints assertion on PostGIS to avoid false
failures.
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.

2 participants