Skip to content

[GH-2884] Add ST_Extent aggregate (returns Box2D)#2898

Merged
jiayuasu merged 1 commit intoapache:masterfrom
jiayuasu:feature/st-extent
May 4, 2026
Merged

[GH-2884] Add ST_Extent aggregate (returns Box2D)#2898
jiayuasu merged 1 commit intoapache:masterfrom
jiayuasu:feature/st-extent

Conversation

@jiayuasu
Copy link
Copy Markdown
Member

@jiayuasu jiayuasu commented May 3, 2026

Did you read the Contributor Guide?

Is this PR related to a ticket?

What changes were proposed in this PR?

Adds the ST_Extent(geom) aggregate, returning a Box2D (the union of all bounding boxes in the column). PostGIS-compatible.

SELECT ST_Extent(geom) FROM my_table;
-- BOX(xmin ymin, xmax ymax)

Reuses the existing EnvelopeBuffer reducer/merger from ST_Envelope_Aggr; only the finish step differs — Box2D instead of a polygon Geometry. ST_Envelope_Aggr is left untouched for backwards compatibility.

Behavior:

  • Empty input (zero rows) → NULL.
  • All rows null or empty geometry → NULL.
  • Mixed null/empty/valid rows → bbox of the valid rows only; null and empty rows are ignored.

How was this patch tested?

aggregateFunctionTestScala:

  • "Passed ST_Extent" — three geometries (two points + one linestring) reduce to the expected box.
  • "ST_Extent returns null over zero rows" — empty input filtered to zero rows → NULL.
  • "ST_Extent returns null when all inputs are null or empty" — all-null/empty input → NULL.
  • "ST_Extent ignores null and empty rows mixed with valid geometries" — mixed input reflects valid geometries only.

Did this PR include necessary documentation updates?

ST_Extent(geom) reduces a stream of geometries to the union of their
bounding boxes, returning a Box2D. PostGIS-compatible.

- Returns SQL NULL when there are no rows.
- Returns SQL NULL when all rows are null or empty geometries.
- Mixed null/empty/valid rows: null and empty are ignored; the result
  reflects the valid geometries only.

Reuses the existing EnvelopeBuffer reducer/merger from
ST_Envelope_Aggr; only the finish step differs (Box2D vs polygon
Geometry). ST_Envelope_Aggr is left untouched for backwards
compatibility.

Closes apache#2884.
@jiayuasu jiayuasu added this to the sedona-1.9.1 milestone May 4, 2026
@jiayuasu jiayuasu merged commit 3c280e7 into apache:master May 4, 2026
43 checks passed
jiayuasu added a commit to jiayuasu/sedona that referenced this pull request May 5, 2026
Mirrors the Phase 1 SQL surface added in apache#2890, apache#2895, apache#2897, apache#2898,
apache#2899 in PySpark wrappers:

- ST_Box2D in st_functions
- ST_MakeBox2D and ST_GeomFromBox2D in st_constructors
- ST_Extent in st_aggregates

Accessor overloads (ST_XMin/XMax/YMin/YMax) and ST_AsText already
worked with Box2D inputs through their existing wrappers; SQL
overload resolution happens on the JVM side.

The Python Box2DType UDT and Box2D value class were merged in apache#2878,
so collected results materialize as Box2D Python objects with
xmin/ymin/xmax/ymax attributes.

Closes apache#2887.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement ST_Extent aggregate (returns Box2D)

1 participant