Skip to content

Commit 2cc4331

Browse files
authored
[GH-2547] Support *_Agg alias for *_Aggr functions (#2564)
1 parent ec6a1b6 commit 2cc4331

File tree

19 files changed

+602
-36
lines changed

19 files changed

+602
-36
lines changed

common/src/test/java/org/apache/sedona/common/FunctionsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2976,7 +2976,7 @@ public void testBuffer() {
29762976
actual = Functions.asWKT(Functions.buffer(lineString, 5, false, "side=both endcap=square"));
29772977
expected =
29782978
"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))";
2979-
assertEquals(expected, actual);
2979+
assertGeometryEquals(expected, actual);
29802980
}
29812981

29822982
@Test

docs/api/flink/Aggregator.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,21 @@
1717
under the License.
1818
-->
1919

20-
## ST_Envelope_Aggr
20+
## ST_Envelope_Agg
2121

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

24-
Format: `ST_Envelope_Aggr (A: geometryColumn)`
24+
Format: `ST_Envelope_Agg (A: geometryColumn)`
2525

2626
Since: `v1.3.0`
2727

28+
!!!note
29+
This function was previously named `ST_Envelope_Aggr`, which is deprecated since `v1.8.1`.
30+
2831
Example:
2932

3033
```sql
31-
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)'))
34+
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)'))
3235
```
3336

3437
Output:
@@ -37,18 +40,21 @@ Output:
3740
POLYGON ((1.1 101.1, 1.1 120.1, 20.1 120.1, 20.1 101.1, 1.1 101.1))
3841
```
3942

40-
## ST_Intersection_Aggr
43+
## ST_Intersection_Agg
4144

4245
Introduction: Return the polygon intersection of all polygons in A
4346

44-
Format: `ST_Intersection_Aggr (A: geometryColumn)`
47+
Format: `ST_Intersection_Agg (A: geometryColumn)`
4548

4649
Since: `v1.5.0`
4750

51+
!!!note
52+
This function was previously named `ST_Intersection_Aggr`, which is deprecated since `v1.8.1`.
53+
4854
Example:
4955

5056
```sql
51-
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)'))
57+
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)'))
5258
```
5359

5460
Output:
@@ -57,18 +63,21 @@ Output:
5763
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))
5864
```
5965

60-
## ST_Union_Aggr
66+
## ST_Union_Agg
6167

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

64-
Format: `ST_Union_Aggr (A: geometryColumn)`
70+
Format: `ST_Union_Agg (A: geometryColumn)`
6571

6672
Since: `v1.3.0`
6773

74+
!!!note
75+
This function was previously named `ST_Union_Aggr`, which is deprecated since `v1.8.1`.
76+
6877
Example:
6978

7079
```sql
71-
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)'))
80+
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)'))
7281
```
7382

7483
Output:

docs/api/snowflake/vector-data/AggregateFunction.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020
!!!note
2121
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.
2222

23-
## ST_Envelope_Aggr
23+
## ST_Envelope_Agg
2424

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

27-
Format: `ST_Envelope_Aggr (A:geometryColumn)`
27+
Format: `ST_Envelope_Agg (A:geometryColumn)`
28+
29+
!!!note
30+
This function was previously named `ST_Envelope_Aggr`, which is deprecated since `v1.8.1`.
2831

2932
SQL example:
3033

@@ -36,7 +39,7 @@ WITH src_tbl AS (
3639
)
3740
SELECT sedona.ST_AsText(envelope)
3841
FROM src_tbl,
39-
TABLE(sedona.ST_Envelope_Aggr(src_tbl.geom) OVER (PARTITION BY 1));
42+
TABLE(sedona.ST_Envelope_Agg(src_tbl.geom) OVER (PARTITION BY 1));
4043
```
4144

4245
Output:
@@ -45,11 +48,14 @@ Output:
4548
POLYGON ((0 0, 0 1.5, 1.5 1.5, 1.5 0, 0 0))
4649
```
4750

48-
## ST_Intersection_Aggr
51+
## ST_Intersection_Agg
4952

5053
Introduction: Return the polygon intersection of all polygons in A
5154

52-
Format: `ST_Intersection_Aggr (A:geometryColumn)`
55+
Format: `ST_Intersection_Agg (A:geometryColumn)`
56+
57+
!!!note
58+
This function was previously named `ST_Intersection_Aggr`, which is deprecated since `v1.8.1`.
5359

5460
SQL example:
5561

@@ -61,7 +67,7 @@ WITH src_tbl AS (
6167
)
6268
SELECT sedona.ST_AsText(intersected)
6369
FROM src_tbl,
64-
TABLE(sedona.ST_Intersection_Aggr(src_tbl.geom) OVER (PARTITION BY 1));
70+
TABLE(sedona.ST_Intersection_Agg(src_tbl.geom) OVER (PARTITION BY 1));
6571
```
6672

6773
Output:
@@ -70,11 +76,14 @@ Output:
7076
POLYGON ((0.5 1, 1 1, 1 0.5, 0.5 0.5, 0.5 1))
7177
```
7278

73-
## ST_Union_Aggr
79+
## ST_Union_Agg
7480

7581
Introduction: Return the polygon union of all polygons in A
7682

77-
Format: `ST_Union_Aggr (A:geometryColumn)`
83+
Format: `ST_Union_Agg (A:geometryColumn)`
84+
85+
!!!note
86+
This function was previously named `ST_Union_Aggr`, which is deprecated since `v1.8.1`.
7887

7988
SQL example:
8089

@@ -86,7 +95,7 @@ WITH src_tbl AS (
8695
)
8796
SELECT sedona.ST_AsText(unioned)
8897
FROM src_tbl,
89-
TABLE(sedona.ST_Union_Aggr(src_tbl.geom) OVER (PARTITION BY 1));
98+
TABLE(sedona.ST_Union_Agg(src_tbl.geom) OVER (PARTITION BY 1));
9099
```
91100

92101
Output:

docs/api/sql/AggregateFunction.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
## ST_Collect_Agg
2121

22-
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.
22+
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.
2323

2424
Format: `ST_Collect_Agg (A: geometryColumn)`
2525

@@ -49,18 +49,21 @@ SQL Example with GROUP BY
4949
SELECT category, ST_Collect_Agg(geom) FROM geometries GROUP BY category
5050
```
5151

52-
## ST_Envelope_Aggr
52+
## ST_Envelope_Agg
5353

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

56-
Format: `ST_Envelope_Aggr (A: geometryColumn)`
56+
Format: `ST_Envelope_Agg (A: geometryColumn)`
5757

5858
Since: `v1.0.0`
5959

60+
!!!note
61+
This function was previously named `ST_Envelope_Aggr`, which is deprecated since `v1.8.1`.
62+
6063
SQL Example
6164

6265
```sql
63-
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)'))
66+
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)'))
6467
```
6568

6669
Output:
@@ -69,18 +72,21 @@ Output:
6972
POLYGON ((1.1 101.1, 1.1 120.1, 20.1 120.1, 20.1 101.1, 1.1 101.1))
7073
```
7174

72-
## ST_Intersection_Aggr
75+
## ST_Intersection_Agg
7376

7477
Introduction: Return the polygon intersection of all polygons in A
7578

76-
Format: `ST_Intersection_Aggr (A: geometryColumn)`
79+
Format: `ST_Intersection_Agg (A: geometryColumn)`
7780

7881
Since: `v1.0.0`
7982

83+
!!!note
84+
This function was previously named `ST_Intersection_Aggr`, which is deprecated since `v1.8.1`.
85+
8086
SQL Example
8187

8288
```sql
83-
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)'))
89+
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)'))
8490
```
8591

8692
Output:
@@ -89,18 +95,21 @@ Output:
8995
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))
9096
```
9197

92-
## ST_Union_Aggr
98+
## ST_Union_Agg
9399

94100
Introduction: Return the polygon union of all polygons in A
95101

96-
Format: `ST_Union_Aggr (A: geometryColumn)`
102+
Format: `ST_Union_Agg (A: geometryColumn)`
97103

98104
Since: `v1.0.0`
99105

106+
!!!note
107+
This function was previously named `ST_Union_Aggr`, which is deprecated since `v1.8.1`.
108+
100109
SQL Example
101110

102111
```sql
103-
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)'))
112+
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)'))
104113
```
105114

106115
Output:

flink/src/main/java/org/apache/sedona/flink/Catalog.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public static UserDefinedFunction[] getFuncs() {
2727
new Aggregators.ST_Envelope_Aggr(),
2828
new Aggregators.ST_Intersection_Aggr(),
2929
new Aggregators.ST_Union_Aggr(),
30+
// Aliases for *_Aggr functions with *_Agg suffix
31+
new Aggregators.ST_Envelope_Agg(),
32+
new Aggregators.ST_Intersection_Agg(),
33+
new Aggregators.ST_Union_Agg(),
3034
new Constructors.ST_Point(),
3135
new Constructors.ST_PointZ(),
3236
new Constructors.ST_PointM(),

flink/src/main/java/org/apache/sedona/flink/expressions/Aggregators.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,23 @@ public void resetAccumulator(Accumulators.AccGeometry acc) {
242242
acc.geom = null;
243243
}
244244
}
245+
246+
// Aliases for *_Aggr functions with *_Agg suffix
247+
@DataTypeHint(
248+
value = "RAW",
249+
rawSerializer = GeometryTypeSerializer.class,
250+
bridgedTo = Geometry.class)
251+
public static class ST_Envelope_Agg extends ST_Envelope_Aggr {}
252+
253+
@DataTypeHint(
254+
value = "RAW",
255+
rawSerializer = GeometryTypeSerializer.class,
256+
bridgedTo = Geometry.class)
257+
public static class ST_Intersection_Agg extends ST_Intersection_Aggr {}
258+
259+
@DataTypeHint(
260+
value = "RAW",
261+
rawSerializer = GeometryTypeSerializer.class,
262+
bridgedTo = Geometry.class)
263+
public static class ST_Union_Agg extends ST_Union_Aggr {}
245264
}

flink/src/test/java/org/apache/sedona/flink/AggregatorTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,38 @@ public void testUnion_Aggr() {
9393
Row last = last(result);
9494
assertEquals(1001, ((Polygon) last.getField(0)).getArea(), 0);
9595
}
96+
97+
// Test aliases for *_Aggr functions with *_Agg suffix
98+
@Test
99+
public void testEnvelop_Agg_Alias() {
100+
Table pointTable = createPointTable(testDataSize);
101+
Table result = pointTable.select(call("ST_Envelope_Agg", $(pointColNames[0])));
102+
Row last = last(result);
103+
assertEquals(
104+
String.format(
105+
"POLYGON ((0 0, 0 %s, %s %s, %s 0, 0 0))",
106+
testDataSize - 1, testDataSize - 1, testDataSize - 1, testDataSize - 1),
107+
last.getField(0).toString());
108+
}
109+
110+
@Test
111+
public void testIntersection_Agg_Alias() {
112+
Table polygonTable = createPolygonOverlappingTable(testDataSize);
113+
Table result = polygonTable.select(call("ST_Intersection_Agg", $(polygonColNames[0])));
114+
Row last = last(result);
115+
assertEquals("LINESTRING EMPTY", last.getField(0).toString());
116+
117+
polygonTable = createPolygonOverlappingTable(3);
118+
result = polygonTable.select(call("ST_Intersection_Agg", $(polygonColNames[0])));
119+
last = last(result);
120+
assertEquals("LINESTRING (1 1, 1 0)", last.getField(0).toString());
121+
}
122+
123+
@Test
124+
public void testUnion_Agg_Alias() {
125+
Table polygonTable = createPolygonOverlappingTable(testDataSize);
126+
Table result = polygonTable.select(call("ST_Union_Agg", $(polygonColNames[0])));
127+
Row last = last(result);
128+
assertEquals(1001, ((Polygon) last.getField(0)).getArea(), 0);
129+
}
96130
}

python/sedona/spark/sql/st_aggregates.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,49 @@ def ST_Collect_Agg(geometry: ColumnOrName) -> Column:
8181
return _call_aggregate_function("ST_Collect_Agg", geometry)
8282

8383

84+
# Aliases for *_Aggr functions with *_Agg suffix
85+
@validate_argument_types
86+
def ST_Envelope_Agg(geometry: ColumnOrName) -> Column:
87+
"""Aggregate Function: Get the aggregate envelope of a geometry column.
88+
89+
This is an alias for ST_Envelope_Aggr.
90+
91+
:param geometry: Geometry column to aggregate.
92+
:type geometry: ColumnOrName
93+
:return: Geometry representing the aggregate envelope of the geometry column.
94+
:rtype: Column
95+
"""
96+
return ST_Envelope_Aggr(geometry)
97+
98+
99+
@validate_argument_types
100+
def ST_Intersection_Agg(geometry: ColumnOrName) -> Column:
101+
"""Aggregate Function: Get the aggregate intersection of a geometry column.
102+
103+
This is an alias for ST_Intersection_Aggr.
104+
105+
:param geometry: Geometry column to aggregate.
106+
:type geometry: ColumnOrName
107+
:return: Geometry representing the aggregate intersection of the geometry column.
108+
:rtype: Column
109+
"""
110+
return ST_Intersection_Aggr(geometry)
111+
112+
113+
@validate_argument_types
114+
def ST_Union_Agg(geometry: ColumnOrName) -> Column:
115+
"""Aggregate Function: Get the aggregate union of a geometry column.
116+
117+
This is an alias for ST_Union_Aggr.
118+
119+
:param geometry: Geometry column to aggregate.
120+
:type geometry: ColumnOrName
121+
:return: Geometry representing the aggregate union of the geometry column.
122+
:rtype: Column
123+
"""
124+
return ST_Union_Aggr(geometry)
125+
126+
84127
# Automatically populate __all__
85128
__all__ = [
86129
name

0 commit comments

Comments
 (0)