[GH-2887] Box2D DataFrame API + Python bindings for Phase 1#2904
Merged
jiayuasu merged 3 commits intoapache:masterfrom May 6, 2026
Merged
[GH-2887] Box2D DataFrame API + Python bindings for Phase 1#2904jiayuasu merged 3 commits intoapache:masterfrom
jiayuasu merged 3 commits intoapache:masterfrom
Conversation
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.
Comment on lines
+662
to
+663
| """ | ||
| return _call_st_function("ST_Box2D", geometry) |
Member
Author
Comment on lines
+568
to
+570
| :rtype: Column | ||
| """ | ||
| return _call_constructor_function("ST_MakeBox2D", (lower_left, upper_right)) |
Member
Author
There was a problem hiding this comment.
Added st_constructors.ST_MakeBox2D (Column + String overloads) in c134508.
Comment on lines
+584
to
+586
| :rtype: Column | ||
| """ | ||
| return _call_constructor_function("ST_GeomFromBox2D", box) |
Member
Author
There was a problem hiding this comment.
Added st_constructors.ST_GeomFromBox2D (Column + String overloads) in c134508.
Comment on lines
+53
to
+56
| :return: Box2D representing the union of bounding boxes of the geometry column. | ||
| :rtype: Column | ||
| """ | ||
| return _call_aggregate_function("ST_Extent", geometry) |
Member
Author
There was a problem hiding this comment.
Added st_aggregates.ST_Extent (Column + String overloads) in c134508, following the udaf-wrapper pattern of the other aggregates in that file.
Comment on lines
+188
to
+192
| def test_st_box_2d(self): | ||
| df = self.spark.sql(""" | ||
| SELECT | ||
| ST_Box2D(ST_GeomFromText('POLYGON((1 2, 1 5, 4 5, 4 2, 1 2))')) AS bbox, | ||
| ST_Box2D(ST_GeomFromText('POINT EMPTY')) AS bbox_empty, |
Member
Author
There was a problem hiding this comment.
Added DataFrame API parametric coverage in test_dataframe_api.py for ST_Box2D, ST_MakeBox2D, ST_GeomFromBox2D, and ST_Extent in c134508. The existing test_dataframe_function harness handles Box2D return values via __eq__ on the Python Box2D value class.
The Python wrappers in apache#2887 dispatch through the Scala DataFrame API objects (org.apache.spark.sql.sedona_sql.expressions.st_functions / st_constructors / st_aggregates) — without matching Scala wrappers, the Python bindings would fail at runtime. Folding the deferred DataFrame API work (apache#2891) into this PR since it is a hard dependency. - st_functions.ST_Box2D - st_constructors.ST_MakeBox2D, ST_GeomFromBox2D - st_aggregates.ST_Extent Each gets the standard Column / String overload pair. Existing ST_XMin/XMax/YMin/YMax and ST_AsText wrappers already accept any Column (including Box2D), so they need no Scala-side changes. Adds DataFrame API coverage in test_dataframe_api.py for the new wrappers (ST_Box2D, ST_MakeBox2D, ST_GeomFromBox2D, ST_Extent).
The two_points fixture has a=(0,0,0) and b=(3,0,4) — both have y=0. ST_MakeBox2D drops Z, so the bbox is Box2D(0, 0, 3, 0), not Box2D(0, 0, 3, 4) as I had wrongly entered (confused Z with Y).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Did you read the Contributor Guide?
Is this PR related to a ticket?
[GH-XXX] my subject. Closes Python bindings for Box2D scalar functions and ST_Extent #2887, closes Scala/Python DataFrame API wrappers for Box2D Phase 1 functions #2891What changes were proposed in this PR?
Adds the Scala DataFrame API wrappers and matching PySpark Column wrappers for the Phase 1 Box2D surface.
The two pieces ship together because they're a hard dependency: the Python wrappers dispatch through the Scala
st_functions/st_constructors/st_aggregatesobjects (seedataframe_api.py:78-79), so the Python bindings would fail at runtime without the Scala wrappers. The original plan to defer DataFrame API work (#2891) has been folded into this PR.Scala DataFrame API (closes #2891)
org.apache.spark.sql.sedona_sql.expressions.*:ST_Box2D(geom: Column | String)st_functionsST_MakeBox2D(ll, ur)st_constructorsST_GeomFromBox2D(box)st_constructorsST_Extent(geom)st_aggregatesThe existing
ST_XMin/XMax/YMin/YMaxandST_AsTextwrappers already accept anyColumn, so no Scala-side changes are needed for them — JVM overload resolution handles Box2D arguments.Python bindings (closes #2887)
sedona.spark.sql.*:ST_Box2D(geometry)st_functionsST_MakeBox2D(p1, p2)st_constructorsST_GeomFromBox2D(box)st_constructorsST_Extent(geom)st_aggregatesThe Python
Box2DTypeUDT andBox2Dvalue class were added in #2878. Collected results materialize asBox2Dobjects withxmin/ymin/xmax/ymaxattributes.How was this patch tested?
python/tests/sql/test_function.py—test_st_box_2d,test_st_as_text_box_2d.python/tests/sql/test_constructor_test.py—test_st_make_box_2d,test_st_geom_from_box_2d(POLYGON/POINT/LINESTRING dispatch).python/tests/sql/test_aggregate_functions.py—test_st_extent,test_st_extent_returns_null_for_empty_input.python/tests/sql/test_dataframe_api.py— parametric coverage forST_Box2D,ST_MakeBox2D,ST_GeomFromBox2D,ST_Extentexercising the Column-API wrapper dispatch end-to-end.Did this PR include necessary documentation updates?