Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions python/sedonadb/tests/functions/test_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
from sedonadb.testing import PostGIS, SedonaDB


def polygonize_fn_suffix(eng):
"""Return the appropriate suffix for the polygonize function for the given engine."""
def agg_fn_suffix(eng):
"""Return the appropriate suffix for the aggregate function for the given engine."""
return "" if isinstance(eng, PostGIS) else "_Agg"


@pytest.mark.parametrize("eng", [SedonaDB, PostGIS])
def test_st_collect_points(eng):
eng = eng.create_or_skip()
suffix = agg_fn_suffix(eng)
eng.assert_query_result(
"""SELECT ST_Collect(ST_GeomFromText(geom)) FROM (
f"""SELECT ST_Collect{suffix}(ST_GeomFromText(geom)) FROM (
VALUES
('POINT (1 2)'),
('POINT (3 4)'),
Expand All @@ -41,8 +42,9 @@ def test_st_collect_points(eng):
@pytest.mark.parametrize("eng", [SedonaDB, PostGIS])
def test_st_collect_linestrings(eng):
eng = eng.create_or_skip()
suffix = agg_fn_suffix(eng)
eng.assert_query_result(
"""SELECT ST_Collect(ST_GeomFromText(geom)) FROM (
f"""SELECT ST_Collect{suffix}(ST_GeomFromText(geom)) FROM (
VALUES
('LINESTRING (1 2, 3 4)'),
('LINESTRING (5 6, 7 8)'),
Expand All @@ -55,8 +57,9 @@ def test_st_collect_linestrings(eng):
@pytest.mark.parametrize("eng", [SedonaDB, PostGIS])
def test_st_collect_polygons(eng):
eng = eng.create_or_skip()
suffix = agg_fn_suffix(eng)
eng.assert_query_result(
"""SELECT ST_Collect(ST_GeomFromText(geom)) FROM (
f"""SELECT ST_Collect{suffix}(ST_GeomFromText(geom)) FROM (
VALUES
('POLYGON ((0 0, 1 0, 0 1, 0 0))'),
('POLYGON ((10 10, 11 10, 10 11, 10 10))'),
Expand All @@ -69,8 +72,9 @@ def test_st_collect_polygons(eng):
@pytest.mark.parametrize("eng", [SedonaDB, PostGIS])
def test_st_collect_mixed_types(eng):
eng = eng.create_or_skip()
suffix = agg_fn_suffix(eng)
eng.assert_query_result(
"""SELECT ST_Collect(ST_GeomFromText(geom)) FROM (
f"""SELECT ST_Collect{suffix}(ST_GeomFromText(geom)) FROM (
VALUES
('POINT (1 2)'),
('LINESTRING (3 4, 5 6)'),
Expand All @@ -83,10 +87,10 @@ def test_st_collect_mixed_types(eng):
@pytest.mark.parametrize("eng", [SedonaDB, PostGIS])
def test_st_collect_mixed_dimensions(eng):
eng = eng.create_or_skip()

suffix = agg_fn_suffix(eng)
with pytest.raises(Exception, match="mixed dimension geometries"):
eng.assert_query_result(
"""SELECT ST_Collect(ST_GeomFromText(geom)) FROM (
f"""SELECT ST_Collect{suffix}(ST_GeomFromText(geom)) FROM (
VALUES
('POINT (1 2)'),
('POINT Z (3 4 5)'),
Expand All @@ -99,8 +103,9 @@ def test_st_collect_mixed_dimensions(eng):
@pytest.mark.parametrize("eng", [SedonaDB, PostGIS])
def test_st_collect_all_null(eng):
eng = eng.create_or_skip()
suffix = agg_fn_suffix(eng)
eng.assert_query_result(
"""SELECT ST_Collect(geom) FROM (
f"""SELECT ST_Collect{suffix}(geom) FROM (
VALUES
(NULL),
(NULL),
Expand All @@ -113,8 +118,9 @@ def test_st_collect_all_null(eng):
@pytest.mark.parametrize("eng", [SedonaDB, PostGIS])
def test_st_collect_zero_input(eng):
eng = eng.create_or_skip()
suffix = agg_fn_suffix(eng)
eng.assert_query_result(
"""SELECT ST_Collect(ST_GeomFromText(geom)) AS empty FROM (
f"""SELECT ST_Collect{suffix}(ST_GeomFromText(geom)) AS empty FROM (
VALUES
('POINT (1 2)')
) AS t(geom) WHERE false""",
Expand All @@ -125,7 +131,7 @@ def test_st_collect_zero_input(eng):
@pytest.mark.parametrize("eng", [SedonaDB, PostGIS])
def test_st_polygonize_basic_triangle(eng):
eng = eng.create_or_skip()
suffix = polygonize_fn_suffix(eng)
suffix = agg_fn_suffix(eng)
eng.assert_query_result(
f"""SELECT ST_Polygonize{suffix}(ST_GeomFromText(geom)) FROM (
VALUES
Expand All @@ -140,7 +146,7 @@ def test_st_polygonize_basic_triangle(eng):
@pytest.mark.parametrize("eng", [SedonaDB, PostGIS])
def test_st_polygonize_with_nulls(eng):
eng = eng.create_or_skip()
suffix = polygonize_fn_suffix(eng)
suffix = agg_fn_suffix(eng)
eng.assert_query_result(
f"""SELECT ST_Polygonize{suffix}(ST_GeomFromText(geom)) FROM (
VALUES
Expand All @@ -157,7 +163,7 @@ def test_st_polygonize_with_nulls(eng):
@pytest.mark.parametrize("eng", [SedonaDB, PostGIS])
def test_st_polygonize_no_polygons_formed(eng):
eng = eng.create_or_skip()
suffix = polygonize_fn_suffix(eng)
suffix = agg_fn_suffix(eng)
eng.assert_query_result(
f"""SELECT ST_Polygonize{suffix}(ST_GeomFromText(geom)) FROM (
VALUES
Expand All @@ -171,7 +177,7 @@ def test_st_polygonize_no_polygons_formed(eng):
@pytest.mark.parametrize("eng", [SedonaDB, PostGIS])
def test_st_polygonize_multiple_polygons(eng):
eng = eng.create_or_skip()
suffix = polygonize_fn_suffix(eng)
suffix = agg_fn_suffix(eng)
eng.assert_query_result(
f"""SELECT ST_Polygonize{suffix}(ST_GeomFromText(geom)) FROM (
VALUES
Expand Down Expand Up @@ -214,7 +220,7 @@ def test_st_polygonize_multiple_polygons(eng):
)
def test_st_polygonize_single_geom(eng, geom, expected):
eng = eng.create_or_skip()
suffix = polygonize_fn_suffix(eng)
suffix = agg_fn_suffix(eng)
eng.assert_query_result(
f"""SELECT ST_Polygonize{suffix}(ST_GeomFromText(geom)) FROM (
VALUES ('{geom}')
Expand Down
12 changes: 6 additions & 6 deletions rust/sedona-functions/benches/native-functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ fn criterion_benchmark(c: &mut Criterion) {
BenchmarkArgs::ArrayArray(Point, Point),
);

benchmark::aggregate(c, &f, "native", "st_envelope_aggr", Point);
benchmark::aggregate(c, &f, "native", "st_envelope_aggr", LineString(10));
benchmark::aggregate(c, &f, "native", "st_envelope_agg", Point);
benchmark::aggregate(c, &f, "native", "st_envelope_agg", LineString(10));

benchmark::aggregate(c, &f, "native", "st_analyze_aggr", Point);
benchmark::aggregate(c, &f, "native", "st_analyze_aggr", LineString(10));
benchmark::aggregate(c, &f, "native", "st_analyze_agg", Point);
benchmark::aggregate(c, &f, "native", "st_analyze_agg", LineString(10));

benchmark::aggregate(c, &f, "native", "st_collect", Point);
benchmark::aggregate(c, &f, "native", "st_collect", LineString(10));
benchmark::aggregate(c, &f, "native", "st_collect_agg", Point);
benchmark::aggregate(c, &f, "native", "st_collect_agg", LineString(10));
}

criterion_group!(benches, criterion_benchmark);
Expand Down
10 changes: 5 additions & 5 deletions rust/sedona-functions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ mod predicates;
mod referencing;
pub mod register;
mod sd_format;
pub mod st_analyze_aggr;
pub mod st_analyze_agg;
mod st_area;
mod st_asbinary;
mod st_astext;
mod st_azimuth;
mod st_buffer;
mod st_centroid;
mod st_collect;
mod st_collect_agg;
mod st_dimension;
mod st_dump;
mod st_dwithin;
pub mod st_envelope;
pub mod st_envelope_aggr;
pub mod st_envelope_agg;
pub mod st_flipcoordinates;
mod st_geometryn;
mod st_geometrytype;
mod st_geomfromwkb;
mod st_geomfromwkt;
mod st_haszm;
pub mod st_intersection_aggr;
pub mod st_intersection_agg;
pub mod st_isclosed;
mod st_iscollection;
pub mod st_isempty;
Expand All @@ -59,7 +59,7 @@ mod st_srid;
mod st_start_point;
mod st_transform;
mod st_translate;
pub mod st_union_aggr;
pub mod st_union_agg;
mod st_xyzm;
mod st_xyzm_minmax;
mod st_zmflag;
10 changes: 5 additions & 5 deletions rust/sedona-functions/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ pub fn default_function_set() -> FunctionSet {

register_aggregate_udfs!(
function_set,
crate::st_analyze_aggr::st_analyze_aggr_udf,
crate::st_collect::st_collect_udf,
crate::st_envelope_aggr::st_envelope_aggr_udf,
crate::st_intersection_aggr::st_intersection_aggr_udf,
crate::st_analyze_agg::st_analyze_agg_udf,
crate::st_collect_agg::st_collect_agg_udf,
crate::st_envelope_agg::st_envelope_agg_udf,
crate::st_intersection_agg::st_intersection_agg_udf,
crate::st_polygonize_agg::st_polygonize_agg_udf,
crate::st_union_aggr::st_union_aggr_udf,
crate::st_union_agg::st_union_agg_udf,
);

function_set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,40 +41,40 @@ use wkb::reader::Wkb;

use crate::executor::WkbExecutor;

/// ST_Analyze_Aggr() aggregate UDF implementation
/// ST_Analyze_Agg() aggregate UDF implementation
///
/// This function computes comprehensive statistics for a collection of geometries.
/// It returns a struct containing various metrics such as count, min/max coordinates,
/// mean size, and geometry type counts.
pub fn st_analyze_aggr_udf() -> SedonaAggregateUDF {
pub fn st_analyze_agg_udf() -> SedonaAggregateUDF {
SedonaAggregateUDF::new(
"st_analyze_aggr",
vec![Arc::new(STAnalyzeAggr {})],
"st_analyze_agg",
vec![Arc::new(STAnalyzeAgg {})],
Volatility::Immutable,
Some(st_analyze_aggr_doc()),
Some(st_analyze_agg_doc()),
)
}

fn st_analyze_aggr_doc() -> Documentation {
fn st_analyze_agg_doc() -> Documentation {
Documentation::builder(
DOC_SECTION_OTHER,
"Return Return the statistics of geometries for geom.",
"ST_Analyze_Aggr (A: Geometry)",
"ST_Analyze_Agg (A: Geometry)",
)
.with_argument("geom", "geometry: Input geometry or geography")
.with_sql_example("
SELECT ST_Analyze_Aggr(ST_GeomFromText('MULTIPOINT(1.1 101.1,2.1 102.1,3.1 103.1,4.1 104.1,5.1 105.1,6.1 106.1,7.1 107.1,8.1 108.1,9.1 109.1,10.1 110.1)'))")
SELECT ST_Analyze_Agg(ST_GeomFromText('MULTIPOINT(1.1 101.1,2.1 102.1,3.1 103.1,4.1 104.1,5.1 105.1,6.1 106.1,7.1 107.1,8.1 108.1,9.1 109.1,10.1 110.1)'))")
.build()
}
/// ST_Analyze_Aggr() implementation
pub fn st_analyze_aggr_impl() -> SedonaAccumulatorRef {
Arc::new(STAnalyzeAggr {})
/// ST_Analyze_Agg() implementation
pub fn st_analyze_agg_impl() -> SedonaAccumulatorRef {
Arc::new(STAnalyzeAgg {})
}

#[derive(Debug)]
struct STAnalyzeAggr {}
struct STAnalyzeAgg {}

impl SedonaAccumulator for STAnalyzeAggr {
impl SedonaAccumulator for STAnalyzeAgg {
fn return_type(&self, args: &[SedonaType]) -> Result<Option<SedonaType>> {
let output_fields = Self::output_fields();

Expand Down Expand Up @@ -103,7 +103,7 @@ impl SedonaAccumulator for STAnalyzeAggr {
}
}

impl STAnalyzeAggr {
impl STAnalyzeAgg {
fn create_float64_array(value: Option<f64>) -> Float64Array {
match value {
Some(v) => Float64Array::from(vec![v]),
Expand Down Expand Up @@ -202,7 +202,7 @@ impl STAnalyzeAggr {
};

// Define output fields
let fields = STAnalyzeAggr::output_fields();
let fields = STAnalyzeAgg::output_fields();

// Create arrays with proper null handling
let values = vec![
Expand Down Expand Up @@ -390,7 +390,7 @@ impl Accumulator for AnalyzeAccumulator {
}

fn evaluate(&mut self) -> Result<ScalarValue> {
let field_array_pairs = STAnalyzeAggr::output_arrays(self.stats.clone());
let field_array_pairs = STAnalyzeAgg::output_arrays(self.stats.clone());

// Create the struct array with field values
let struct_array = StructArray::from(field_array_pairs);
Expand Down Expand Up @@ -498,8 +498,8 @@ mod test {

#[rstest]
fn basic_analyze_cases(#[values(WKB_GEOMETRY, WKB_VIEW_GEOMETRY)] sedona_type: SedonaType) {
let mut udaf = st_analyze_aggr_udf();
udaf.add_kernel(st_analyze_aggr_impl());
let mut udaf = st_analyze_agg_udf();
udaf.add_kernel(st_analyze_agg_impl());

let tester = AggregateUdfTester::new(udaf.into(), vec![sedona_type.clone()]);

Expand Down Expand Up @@ -538,8 +538,8 @@ mod test {

#[rstest]
fn analyze_linestring(#[values(WKB_GEOMETRY, WKB_VIEW_GEOMETRY)] sedona_type: SedonaType) {
let mut udaf = st_analyze_aggr_udf();
udaf.add_kernel(st_analyze_aggr_impl());
let mut udaf = st_analyze_agg_udf();
udaf.add_kernel(st_analyze_agg_impl());

let tester = AggregateUdfTester::new(udaf.into(), vec![sedona_type.clone()]);

Expand Down Expand Up @@ -578,8 +578,8 @@ mod test {

#[rstest]
fn analyze_polygon(#[values(WKB_GEOMETRY, WKB_VIEW_GEOMETRY)] sedona_type: SedonaType) {
let mut udaf = st_analyze_aggr_udf();
udaf.add_kernel(st_analyze_aggr_impl());
let mut udaf = st_analyze_agg_udf();
udaf.add_kernel(st_analyze_agg_impl());

let tester = AggregateUdfTester::new(udaf.into(), vec![sedona_type.clone()]);

Expand Down Expand Up @@ -620,8 +620,8 @@ mod test {
fn analyze_mixed_geometries(
#[values(WKB_GEOMETRY, WKB_VIEW_GEOMETRY)] sedona_type: SedonaType,
) {
let mut udaf = st_analyze_aggr_udf();
udaf.add_kernel(st_analyze_aggr_impl());
let mut udaf = st_analyze_agg_udf();
udaf.add_kernel(st_analyze_agg_impl());

let tester = AggregateUdfTester::new(udaf.into(), vec![sedona_type.clone()]);

Expand Down Expand Up @@ -662,8 +662,8 @@ mod test {

#[rstest]
fn analyze_empty_input(#[values(WKB_GEOMETRY, WKB_VIEW_GEOMETRY)] sedona_type: SedonaType) {
let mut udaf = st_analyze_aggr_udf();
udaf.add_kernel(st_analyze_aggr_impl());
let mut udaf = st_analyze_agg_udf();
udaf.add_kernel(st_analyze_agg_impl());

let tester = AggregateUdfTester::new(udaf.into(), vec![sedona_type.clone()]);

Expand Down
Loading