Skip to content

Commit 7e8cb1c

Browse files
authored
feat(rust/sedona-functions): add ST_NumPoints alias for ST_NPoints (#989)
1 parent 178543b commit 7e8cb1c

7 files changed

Lines changed: 27 additions & 190 deletions

File tree

c/sedona-geos/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ mod st_minimumclearance_line;
4141
mod st_normalize;
4242
mod st_nrings;
4343
mod st_numinteriorrings;
44-
mod st_numpoints;
4544
mod st_perimeter;
4645
mod st_polygonize;
4746
mod st_polygonize_agg;

c/sedona-geos/src/register.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ pub fn scalar_kernels() -> Vec<(&'static str, Vec<ScalarKernelRef>)> {
7070
"st_normalize" => crate::st_normalize::st_normalize_impl,
7171
"st_nrings" => crate::st_nrings::st_nrings_impl,
7272
"st_numinteriorrings" => crate::st_numinteriorrings::st_num_interior_rings_impl,
73-
"st_numpoints" => crate::st_numpoints::st_num_points_impl,
7473
"st_overlaps" => crate::binary_predicates::st_overlaps_impl,
7574
"st_perimeter" => crate::st_perimeter::st_perimeter_impl,
7675
"st_polygonize" => crate::st_polygonize::st_polygonize_impl,

c/sedona-geos/src/st_numpoints.rs

Lines changed: 0 additions & 146 deletions
This file was deleted.

docs/reference/sql/st_npoints.qmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ kernels:
2929

3030
Returns the total number of coordinate points in the geometry, counting all vertices across all components.
3131

32+
Aliases: `ST_NumPoints`.
33+
3234
## Examples
3335

3436
```sql

python/sedonadb/tests/functions/test_functions.py

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2714,6 +2714,7 @@ def test_st_pointm(eng, x, y, m, expected):
27142714
],
27152715
)
27162716
def test_st_points(eng, geometry, expected, expected_n):
2717+
is_postgis = eng is PostGIS
27172718
eng = eng.create_or_skip()
27182719
eng.assert_query_result(
27192720
f"SELECT ST_Points({geom_or_null(geometry)})",
@@ -2723,6 +2724,13 @@ def test_st_points(eng, geometry, expected, expected_n):
27232724
f"SELECT ST_NPoints({geom_or_null(geometry)})",
27242725
expected_n,
27252726
)
2727+
if not is_postgis:
2728+
# ST_NumPoints is an alias for ST_NPoints in SedonaDB.
2729+
# PostGIS still treats ST_NumPoints as LineString-only despite documentation.
2730+
eng.assert_query_result(
2731+
f"SELECT ST_NumPoints({geom_or_null(geometry)})",
2732+
expected_n,
2733+
)
27262734

27272735

27282736
@pytest.mark.parametrize("eng", [SedonaDB, PostGIS])
@@ -3876,38 +3884,6 @@ def test_st_numinteriorrings_basic(eng, geom, expected):
38763884
)
38773885

38783886

3879-
@pytest.mark.parametrize("eng", [SedonaDB, PostGIS])
3880-
@pytest.mark.parametrize(
3881-
("geom", "expected"),
3882-
[
3883-
(None, None),
3884-
("POINT EMPTY", None),
3885-
("LINESTRING EMPTY", 0),
3886-
("POLYGON EMPTY", None),
3887-
("MULTIPOINT EMPTY", None),
3888-
("MULTILINESTRING EMPTY", None),
3889-
("MULTIPOLYGON EMPTY", None),
3890-
("GEOMETRYCOLLECTION EMPTY", None),
3891-
("POINT (1 2)", None),
3892-
("LINESTRING (0 0, 1 1, 2 2)", 3),
3893-
("LINESTRING (0 0, 1 1, 0 0)", 3),
3894-
("LINESTRING Z (0 0 0, 1 1 1, 2 2 2, 3 3 3)", 4),
3895-
("LINESTRING M (0 0 0, 1 1 1, 2 2 2, 3 3 3)", 4),
3896-
("LINESTRING ZM (0 0 0 2, 1 1 1 4)", 2),
3897-
("POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0))", None),
3898-
("MULTILINESTRING ((0 0, 0 1, 1 1, 0 0),(0 0, 1 1))", None),
3899-
("GEOMETRYCOLLECTION (LINESTRING (0 0, 0 1, 1 1, 0 0))", None),
3900-
("POLYGON ((0 0,6 0,6 6,0 6,0 0),(2 2,4 2,4 4,2 4,2 2))", None),
3901-
],
3902-
)
3903-
def test_st_numpoints(eng, geom, expected):
3904-
eng = eng.create_or_skip()
3905-
eng.assert_query_result(
3906-
f"SELECT ST_NumPoints({geom_or_null(geom)})",
3907-
expected,
3908-
)
3909-
3910-
39113887
@pytest.mark.parametrize("eng", [SedonaDB, PostGIS])
39123888
@pytest.mark.parametrize(
39133889
("geom", "expected"),

python/sedonadb/tests/geography/test_geog_mechanical_transforms.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -638,28 +638,28 @@ def test_st_numinteriorrings(eng, geog, expected):
638638
("geog", "expected"),
639639
[
640640
pytest.param(None, None, id="null"),
641-
pytest.param("POINT EMPTY", None, id="point_empty"),
641+
pytest.param("POINT EMPTY", 0, id="point_empty"),
642642
pytest.param("LINESTRING EMPTY", 0, id="linestring_empty"),
643-
pytest.param("POLYGON EMPTY", None, id="polygon_empty"),
644-
pytest.param("MULTIPOINT EMPTY", None, id="multipoint_empty"),
645-
pytest.param("MULTILINESTRING EMPTY", None, id="multilinestring_empty"),
646-
pytest.param("MULTIPOLYGON EMPTY", None, id="multipolygon_empty"),
647-
pytest.param("GEOMETRYCOLLECTION EMPTY", None, id="geometrycollection_empty"),
648-
pytest.param("POINT (1 2)", None, id="point"),
643+
pytest.param("POLYGON EMPTY", 0, id="polygon_empty"),
644+
pytest.param("MULTIPOINT EMPTY", 0, id="multipoint_empty"),
645+
pytest.param("MULTILINESTRING EMPTY", 0, id="multilinestring_empty"),
646+
pytest.param("MULTIPOLYGON EMPTY", 0, id="multipolygon_empty"),
647+
pytest.param("GEOMETRYCOLLECTION EMPTY", 0, id="geometrycollection_empty"),
648+
pytest.param("POINT (1 2)", 1, id="point"),
649649
pytest.param("LINESTRING (0 0, 1 1, 2 2)", 3, id="linestring"),
650650
pytest.param("LINESTRING (0 0, 1 1, 0 0)", 3, id="linestring_closed"),
651651
pytest.param("LINESTRING Z (0 0 0, 1 1 1, 2 2 2, 3 3 3)", 4, id="linestring_z"),
652652
pytest.param("LINESTRING M (0 0 0, 1 1 1, 2 2 2, 3 3 3)", 4, id="linestring_m"),
653653
pytest.param("LINESTRING ZM (0 0 0 2, 1 1 1 4)", 2, id="linestring_zm"),
654-
pytest.param("POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0))", None, id="polygon"),
654+
pytest.param("POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0))", 5, id="polygon"),
655655
pytest.param(
656656
"MULTILINESTRING ((0 0, 0 1, 1 1, 0 0),(0 0, 1 1))",
657-
None,
657+
6,
658658
id="multilinestring",
659659
),
660660
pytest.param(
661661
"GEOMETRYCOLLECTION (LINESTRING (0 0, 0 1, 1 1, 0 0))",
662-
None,
662+
4,
663663
id="geometrycollection",
664664
),
665665
],

rust/sedona-functions/src/st_points.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ pub fn st_npoints_udf() -> SedonaScalarUDF {
115115
ItemCrsKernel::wrap_impl(vec![Arc::new(STNPoints)]),
116116
Volatility::Immutable,
117117
)
118+
.with_aliases(vec!["st_numpoints".to_string()])
118119
}
119120

120121
#[derive(Debug)]
@@ -296,6 +297,12 @@ mod tests {
296297
assert!(st_npoints_udf.documentation().is_none());
297298
}
298299

300+
#[test]
301+
fn npoints_aliases() {
302+
let udf: ScalarUDF = st_npoints_udf().into();
303+
assert!(udf.aliases().contains(&"st_numpoints".to_string()));
304+
}
305+
299306
#[rstest]
300307
fn udf(#[values(WKB_GEOMETRY, WKB_GEOGRAPHY)] sedona_type: SedonaType) {
301308
use arrow_array::UInt64Array;

0 commit comments

Comments
 (0)