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
Original file line number Diff line number Diff line change
Expand Up @@ -2976,7 +2976,7 @@ public void testBuffer() {
actual = Functions.asWKT(Functions.buffer(lineString, 5, false, "side=both endcap=square"));
expected =
"POLYGON ((45.93133264396633 72.90619096859548, 46.607775042289525 73.6732560265092, 47.42614312881237 74.2866374708669, 48.35219759000809 74.72067232686456, 49.34719367328685 74.9572012163925, 50.36950221028991 74.9863281196278, 51.37635131988457 74.80683440990555, 52.32561592057597 74.4262298392609, 53.17758018177616 73.86043834148188, 53.896599175569165 73.13313179820986, 54.452590207913495 72.27473964233116, 54.82229143418446 71.321175735393, 74.82229143418445 -1.6788242646069989, 76.14346716957745 -6.501115698791454, 66.49888430120855 -9.143467169577455, 47.95639322710423 58.5366252509033, 4.068667356033674 -2.9061909685954816, 1.162476387438193 -6.974858324629158, -6.974858324629155 -1.1624763874381943, 45.93133264396633 72.90619096859548))";
assertEquals(expected, actual);
assertGeometryEquals(expected, actual);
}

@Test
Expand Down
27 changes: 18 additions & 9 deletions docs/api/flink/Aggregator.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@
under the License.
-->

## ST_Envelope_Aggr
## ST_Envelope_Agg

Introduction: Return the entire envelope boundary of all geometries in A

Format: `ST_Envelope_Aggr (A: geometryColumn)`
Format: `ST_Envelope_Agg (A: geometryColumn)`

Since: `v1.3.0`

!!!note
This function was previously named `ST_Envelope_Aggr`, which is deprecated since `v1.8.1`.

Example:

```sql
SELECT ST_Envelope_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_Envelope_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)'))
```

Output:
Expand All @@ -37,18 +40,21 @@ Output:
POLYGON ((1.1 101.1, 1.1 120.1, 20.1 120.1, 20.1 101.1, 1.1 101.1))
```

## ST_Intersection_Aggr
## ST_Intersection_Agg

Introduction: Return the polygon intersection of all polygons in A

Format: `ST_Intersection_Aggr (A: geometryColumn)`
Format: `ST_Intersection_Agg (A: geometryColumn)`

Since: `v1.5.0`

!!!note
This function was previously named `ST_Intersection_Aggr`, which is deprecated since `v1.8.1`.

Example:

```sql
SELECT ST_Intersection_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_Intersection_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)'))
```

Output:
Expand All @@ -57,18 +63,21 @@ Output:
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))
```

## ST_Union_Aggr
## ST_Union_Agg

Introduction: Return the polygon union of all polygons in A. All inputs must be polygons.

Format: `ST_Union_Aggr (A: geometryColumn)`
Format: `ST_Union_Agg (A: geometryColumn)`

Since: `v1.3.0`

!!!note
This function was previously named `ST_Union_Aggr`, which is deprecated since `v1.8.1`.

Example:

```sql
SELECT ST_Union_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_Union_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)'))
```

Output:
Expand Down
27 changes: 18 additions & 9 deletions docs/api/snowflake/vector-data/AggregateFunction.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
!!!note
Please always keep the schema name `SEDONA` (e.g., `SEDONA.ST_GeomFromWKT`) when you use Sedona functions to avoid conflicting with Snowflake's built-in functions.

## ST_Envelope_Aggr
## ST_Envelope_Agg

Introduction: Return the entire envelope boundary of all geometries in A

Format: `ST_Envelope_Aggr (A:geometryColumn)`
Format: `ST_Envelope_Agg (A:geometryColumn)`

!!!note
This function was previously named `ST_Envelope_Aggr`, which is deprecated since `v1.8.1`.

SQL example:

Expand All @@ -36,7 +39,7 @@ WITH src_tbl AS (
)
SELECT sedona.ST_AsText(envelope)
FROM src_tbl,
TABLE(sedona.ST_Envelope_Aggr(src_tbl.geom) OVER (PARTITION BY 1));
TABLE(sedona.ST_Envelope_Agg(src_tbl.geom) OVER (PARTITION BY 1));
```

Output:
Expand All @@ -45,11 +48,14 @@ Output:
POLYGON ((0 0, 0 1.5, 1.5 1.5, 1.5 0, 0 0))
```

## ST_Intersection_Aggr
## ST_Intersection_Agg

Introduction: Return the polygon intersection of all polygons in A

Format: `ST_Intersection_Aggr (A:geometryColumn)`
Format: `ST_Intersection_Agg (A:geometryColumn)`

!!!note
This function was previously named `ST_Intersection_Aggr`, which is deprecated since `v1.8.1`.

SQL example:

Expand All @@ -61,7 +67,7 @@ WITH src_tbl AS (
)
SELECT sedona.ST_AsText(intersected)
FROM src_tbl,
TABLE(sedona.ST_Intersection_Aggr(src_tbl.geom) OVER (PARTITION BY 1));
TABLE(sedona.ST_Intersection_Agg(src_tbl.geom) OVER (PARTITION BY 1));
```

Output:
Expand All @@ -70,11 +76,14 @@ Output:
POLYGON ((0.5 1, 1 1, 1 0.5, 0.5 0.5, 0.5 1))
```

## ST_Union_Aggr
## ST_Union_Agg

Introduction: Return the polygon union of all polygons in A

Format: `ST_Union_Aggr (A:geometryColumn)`
Format: `ST_Union_Agg (A:geometryColumn)`

!!!note
This function was previously named `ST_Union_Aggr`, which is deprecated since `v1.8.1`.

SQL example:

Expand All @@ -86,7 +95,7 @@ WITH src_tbl AS (
)
SELECT sedona.ST_AsText(unioned)
FROM src_tbl,
TABLE(sedona.ST_Union_Aggr(src_tbl.geom) OVER (PARTITION BY 1));
TABLE(sedona.ST_Union_Agg(src_tbl.geom) OVER (PARTITION BY 1));
```

Output:
Expand Down
29 changes: 19 additions & 10 deletions docs/api/sql/AggregateFunction.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

## ST_Collect_Agg

Introduction: Collects all geometries in a geometry column into a single multi-geometry (MultiPoint, MultiLineString, MultiPolygon, or GeometryCollection). Unlike `ST_Union_Aggr`, this function does not dissolve boundaries between geometries - it simply collects them into a multi-geometry.
Introduction: Collects all geometries in a geometry column into a single multi-geometry (MultiPoint, MultiLineString, MultiPolygon, or GeometryCollection). Unlike `ST_Union_Agg`, this function does not dissolve boundaries between geometries - it simply collects them into a multi-geometry.

Format: `ST_Collect_Agg (A: geometryColumn)`

Expand Down Expand Up @@ -49,18 +49,21 @@ SQL Example with GROUP BY
SELECT category, ST_Collect_Agg(geom) FROM geometries GROUP BY category
```

## ST_Envelope_Aggr
## ST_Envelope_Agg

Introduction: Return the entire envelope boundary of all geometries in A

Format: `ST_Envelope_Aggr (A: geometryColumn)`
Format: `ST_Envelope_Agg (A: geometryColumn)`

Since: `v1.0.0`

!!!note
This function was previously named `ST_Envelope_Aggr`, which is deprecated since `v1.8.1`.

SQL Example

```sql
SELECT ST_Envelope_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_Envelope_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)'))
```

Output:
Expand All @@ -69,18 +72,21 @@ Output:
POLYGON ((1.1 101.1, 1.1 120.1, 20.1 120.1, 20.1 101.1, 1.1 101.1))
```

## ST_Intersection_Aggr
## ST_Intersection_Agg

Introduction: Return the polygon intersection of all polygons in A

Format: `ST_Intersection_Aggr (A: geometryColumn)`
Format: `ST_Intersection_Agg (A: geometryColumn)`

Since: `v1.0.0`

!!!note
This function was previously named `ST_Intersection_Aggr`, which is deprecated since `v1.8.1`.

SQL Example

```sql
SELECT ST_Intersection_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_Intersection_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)'))
```

Output:
Expand All @@ -89,18 +95,21 @@ Output:
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))
```

## ST_Union_Aggr
## ST_Union_Agg

Introduction: Return the polygon union of all polygons in A

Format: `ST_Union_Aggr (A: geometryColumn)`
Format: `ST_Union_Agg (A: geometryColumn)`

Since: `v1.0.0`

!!!note
This function was previously named `ST_Union_Aggr`, which is deprecated since `v1.8.1`.

SQL Example

```sql
SELECT ST_Union_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_Union_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)'))
```

Output:
Expand Down
4 changes: 4 additions & 0 deletions flink/src/main/java/org/apache/sedona/flink/Catalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public static UserDefinedFunction[] getFuncs() {
new Aggregators.ST_Envelope_Aggr(),
new Aggregators.ST_Intersection_Aggr(),
new Aggregators.ST_Union_Aggr(),
// Aliases for *_Aggr functions with *_Agg suffix
new Aggregators.ST_Envelope_Agg(),
new Aggregators.ST_Intersection_Agg(),
new Aggregators.ST_Union_Agg(),
new Constructors.ST_Point(),
new Constructors.ST_PointZ(),
new Constructors.ST_PointM(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,23 @@ public void resetAccumulator(Accumulators.AccGeometry acc) {
acc.geom = null;
}
}

// Aliases for *_Aggr functions with *_Agg suffix
@DataTypeHint(
value = "RAW",
rawSerializer = GeometryTypeSerializer.class,
bridgedTo = Geometry.class)
public static class ST_Envelope_Agg extends ST_Envelope_Aggr {}

@DataTypeHint(
value = "RAW",
rawSerializer = GeometryTypeSerializer.class,
bridgedTo = Geometry.class)
public static class ST_Intersection_Agg extends ST_Intersection_Aggr {}

@DataTypeHint(
value = "RAW",
rawSerializer = GeometryTypeSerializer.class,
bridgedTo = Geometry.class)
public static class ST_Union_Agg extends ST_Union_Aggr {}
}
34 changes: 34 additions & 0 deletions flink/src/test/java/org/apache/sedona/flink/AggregatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,38 @@ public void testUnion_Aggr() {
Row last = last(result);
assertEquals(1001, ((Polygon) last.getField(0)).getArea(), 0);
}

// Test aliases for *_Aggr functions with *_Agg suffix
@Test
public void testEnvelop_Agg_Alias() {
Table pointTable = createPointTable(testDataSize);
Table result = pointTable.select(call("ST_Envelope_Agg", $(pointColNames[0])));
Row last = last(result);
assertEquals(
String.format(
"POLYGON ((0 0, 0 %s, %s %s, %s 0, 0 0))",
testDataSize - 1, testDataSize - 1, testDataSize - 1, testDataSize - 1),
last.getField(0).toString());
}

@Test
public void testIntersection_Agg_Alias() {
Table polygonTable = createPolygonOverlappingTable(testDataSize);
Table result = polygonTable.select(call("ST_Intersection_Agg", $(polygonColNames[0])));
Row last = last(result);
assertEquals("LINESTRING EMPTY", last.getField(0).toString());

polygonTable = createPolygonOverlappingTable(3);
result = polygonTable.select(call("ST_Intersection_Agg", $(polygonColNames[0])));
last = last(result);
assertEquals("LINESTRING (1 1, 1 0)", last.getField(0).toString());
}

@Test
public void testUnion_Agg_Alias() {
Table polygonTable = createPolygonOverlappingTable(testDataSize);
Table result = polygonTable.select(call("ST_Union_Agg", $(polygonColNames[0])));
Row last = last(result);
assertEquals(1001, ((Polygon) last.getField(0)).getArea(), 0);
}
}
43 changes: 43 additions & 0 deletions python/sedona/spark/sql/st_aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,49 @@ def ST_Collect_Agg(geometry: ColumnOrName) -> Column:
return _call_aggregate_function("ST_Collect_Agg", geometry)


# Aliases for *_Aggr functions with *_Agg suffix
@validate_argument_types
def ST_Envelope_Agg(geometry: ColumnOrName) -> Column:
"""Aggregate Function: Get the aggregate envelope of a geometry column.

This is an alias for ST_Envelope_Aggr.

:param geometry: Geometry column to aggregate.
:type geometry: ColumnOrName
:return: Geometry representing the aggregate envelope of the geometry column.
:rtype: Column
"""
return ST_Envelope_Aggr(geometry)


@validate_argument_types
def ST_Intersection_Agg(geometry: ColumnOrName) -> Column:
"""Aggregate Function: Get the aggregate intersection of a geometry column.

This is an alias for ST_Intersection_Aggr.

:param geometry: Geometry column to aggregate.
:type geometry: ColumnOrName
:return: Geometry representing the aggregate intersection of the geometry column.
:rtype: Column
"""
return ST_Intersection_Aggr(geometry)


@validate_argument_types
def ST_Union_Agg(geometry: ColumnOrName) -> Column:
"""Aggregate Function: Get the aggregate union of a geometry column.

This is an alias for ST_Union_Aggr.

:param geometry: Geometry column to aggregate.
:type geometry: ColumnOrName
:return: Geometry representing the aggregate union of the geometry column.
:rtype: Column
"""
return ST_Union_Aggr(geometry)


# Automatically populate __all__
__all__ = [
name
Expand Down
Loading
Loading