Skip to content
36 changes: 36 additions & 0 deletions benchmarks/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,39 @@ def queries():
eng.execute_and_collect(f"SELECT ST_Perimeter(geom1) from {table}")

benchmark(queries)

@pytest.mark.parametrize(
"eng", [SedonaDBSingleThread, PostGISSingleThread, DuckDBSingleThread]
)
@pytest.mark.parametrize(
"table",
[
"collections_simple",
"segments_large",
],
)
def test_st_start_point(self, benchmark, eng, table):
eng = self._get_eng(eng)

def queries():
eng.execute_and_collect(f"SELECT ST_StartPoint(geom1) from {table}")

benchmark(queries)

@pytest.mark.parametrize(
"eng", [SedonaDBSingleThread, PostGISSingleThread, DuckDBSingleThread]
)
@pytest.mark.parametrize(
"table",
[
"collections_simple",
"segments_large",
],
)
def test_st_end_point(self, benchmark, eng, table):
eng = self._get_eng(eng)

def queries():
eng.execute_and_collect(f"SELECT ST_EndPoint(geom1) from {table}")

benchmark(queries)
65 changes: 65 additions & 0 deletions python/sedonadb/tests/functions/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,71 @@ def test_st_pointm(eng, x, y, m, expected):
)


@pytest.mark.parametrize("eng", [SedonaDB, PostGIS])
@pytest.mark.parametrize(
("geometry", "expected"),
[
(None, None),
("POINT EMPTY", None),
("LINESTRING EMPTY", None),
("POLYGON EMPTY", None),
("MULTIPOINT EMPTY", None),
("MULTILINESTRING EMPTY", None),
("MULTIPOLYGON EMPTY", None),
("GEOMETRYCOLLECTION EMPTY", None),
("LINESTRING (1 2, 3 4, 5 6)", "POINT (1 2)"),
("LINESTRING Z (1 2 3, 3 4 5, 5 6 7)", "POINT Z (1 2 3)"),
("LINESTRING M (1 2 3, 3 4 5, 5 6 7)", "POINT M (1 2 3)"),
("LINESTRING ZM (1 2 3 4, 3 4 5 6, 5 6 7 8)", "POINT ZM (1 2 3 4)"),
("POINT (1 2)", "POINT (1 2)"),
("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))", "POINT (0 0)"),
("MULTIPOINT (0 0, 10 0, 10 10, 0 10, 0 0)", "POINT (0 0)"),
("MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))", "POINT (1 2)"),
("MULTIPOLYGON (((0 0, 10 0, 10 10, 0 10, 0 0)))", "POINT (0 0)"),
("GEOMETRYCOLLECTION (POINT (1 2), LINESTRING (3 4, 5 6))", "POINT (1 2)"),
(
"GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (1 2), LINESTRING (3 4, 5 6))))",
"POINT (1 2)",
),
],
)
def test_st_start_point(eng, geometry, expected):
eng = eng.create_or_skip()
eng.assert_query_result(
f"SELECT ST_StartPoint({geom_or_null(geometry)})",
expected,
)


@pytest.mark.parametrize("eng", [SedonaDB, PostGIS])
@pytest.mark.parametrize(
("geometry", "expected"),
[
(None, None),
("POINT EMPTY", None),
("LINESTRING EMPTY", None),
("POLYGON EMPTY", None),
("MULTIPOINT EMPTY", None),
("MULTILINESTRING EMPTY", None),
("MULTIPOLYGON EMPTY", None),
("GEOMETRYCOLLECTION EMPTY", None),
("LINESTRING (1 2, 3 4, 5 6)", "POINT (5 6)"),
("LINESTRING Z (1 2 3, 3 4 5, 5 6 7)", "POINT Z (5 6 7)"),
("LINESTRING M (1 2 3, 3 4 5, 5 6 7)", "POINT M (5 6 7)"),
("LINESTRING ZM (1 2 3 4, 3 4 5 6, 5 6 7 8)", "POINT ZM (5 6 7 8)"),
("POINT (1 2)", None),
("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))", None),
("MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))", None),
],
)
def test_st_end_point(eng, geometry, expected):
eng = eng.create_or_skip()
eng.assert_query_result(
f"SELECT ST_EndPoint({geom_or_null(geometry)})",
expected,
)


@pytest.mark.parametrize("eng", [SedonaDB, PostGIS])
@pytest.mark.parametrize(
("x", "y", "z", "m", "expected"),
Expand Down
16 changes: 16 additions & 0 deletions rust/sedona-functions/benches/native-functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ fn criterion_benchmark(c: &mut Criterion) {
),
);

benchmark::scalar(
c,
&f,
"native",
"st_startpoint",
BenchmarkArgs::Array(LineString(10)),
);

benchmark::scalar(
c,
&f,
"native",
"st_endpoint",
BenchmarkArgs::Array(LineString(10)),
);

benchmark::scalar(c, &f, "native", "st_x", Point);
benchmark::scalar(c, &f, "native", "st_y", Point);
benchmark::scalar(c, &f, "native", "st_z", Point);
Expand Down
1 change: 1 addition & 0 deletions rust/sedona-functions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ mod st_point;
mod st_pointzm;
mod st_setsrid;
mod st_srid;
mod st_start_point;
mod st_transform;
pub mod st_union_aggr;
mod st_xyzm;
Expand Down
2 changes: 2 additions & 0 deletions rust/sedona-functions/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ pub fn default_function_set() -> FunctionSet {
crate::st_setsrid::st_set_srid_udf,
crate::st_srid::st_crs_udf,
crate::st_srid::st_srid_udf,
crate::st_start_point::st_end_point_udf,
crate::st_start_point::st_start_point_udf,
crate::st_xyzm::st_m_udf,
crate::st_xyzm::st_x_udf,
crate::st_xyzm::st_y_udf,
Expand Down
Loading