[GH-2925] Add ST_Expand(box2d, ...) overloads#2930
Open
jiayuasu wants to merge 2 commits intoapache:masterfrom
Open
[GH-2925] Add ST_Expand(box2d, ...) overloads#2930jiayuasu wants to merge 2 commits intoapache:masterfrom
jiayuasu wants to merge 2 commits intoapache:masterfrom
Conversation
Adds Box2D variants alongside the existing Geometry-input ST_Expand: ST_Expand(box: Box2D, units: double) -> Box2D ST_Expand(box: Box2D, dx: double, dy: double) -> Box2D Negative deltas are allowed and may produce a degenerate Box2D where xmin > xmax or ymin > ymax. The result is returned as-is; callers can detect degenerate output via the accessor functions. NULL on null input. JVM, Python, Flink wrappers all updated. The Python and Scala DataFrame API wrappers were already polymorphic over Column, so no wrapper-side change was needed; the JVM-side overload resolution handles Box2D vs Geometry. Flink ScalarFunction needed two new eval overloads on the existing class. Closes apache#2925.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Box2D overloads for ST_Expand across Sedona’s common layer and engine integrations (Spark + Flink), aligning behavior with PostGIS and enabling bbox expansion/shrink directly on Box2D values.
Changes:
- Add
org.apache.sedona.common.Functions.expand(Box2D, delta)andexpand(Box2D, dx, dy)overloads. - Extend Spark SQL
ST_Expandexpression dispatch to support Box2D inputs alongside existing Geometry overloads. - Add Flink
ST_ExpandBox2Devaloverloads and expand test coverage across common/Spark/Flink/Python.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| common/src/main/java/org/apache/sedona/common/Functions.java | Adds Box2D expand overloads implementing uniform and per-axis expansion with null propagation. |
| common/src/test/java/org/apache/sedona/common/FunctionsTest.java | Adds unit tests for Box2D expansion, including negative deltas and null input. |
| spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala | Updates Spark ST_Expand inferred dispatch to include Box2D overloads (and resolves overload ambiguity via typed lambdas). |
| spark/common/src/test/scala/org/apache/sedona/sql/functionTestScala.scala | Adds Spark SQL test coverage for ST_Expand(Box2D, ...), including shrink and null input. |
| flink/src/main/java/org/apache/sedona/flink/expressions/Functions.java | Adds Flink ST_Expand Box2D overloads with appropriate @DataTypeHint/serializer wiring. |
| flink/src/test/java/org/apache/sedona/flink/FunctionTest.java | Adds Flink Table API test for Box2D expansion results. |
| python/tests/sql/test_function.py | Adds PySpark SQL test verifying Box2D results are deserialized correctly for the new overloads. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+246
to
+252
| def test_st_expand_box_2d(self): | ||
| df = self.spark.sql(""" | ||
| SELECT | ||
| ST_Expand(ST_Box2D(ST_GeomFromText('POLYGON((1 2, 1 5, 4 5, 4 2, 1 2))')), 1.0) AS uniform, | ||
| ST_Expand(ST_Box2D(ST_GeomFromText('POLYGON((1 2, 1 5, 4 5, 4 2, 1 2))')), 2.0, 0.5) AS per_axis | ||
| """) | ||
| row = df.first() |
Member
Author
There was a problem hiding this comment.
Done in 5158213 — added NULL Box2D coverage to both signatures. NULL row deserializes to None as expected.
Comment on lines
+538
to
+555
| @Test | ||
| public void testExpandBox2D() { | ||
| Table t = | ||
| tableEnv.sqlQuery( | ||
| "SELECT ST_Expand(ST_Box2D(ST_GeomFromText('POLYGON((1 2, 1 5, 4 5, 4 2, 1 2))')), 1.0) AS uniform," | ||
| + " ST_Expand(ST_Box2D(ST_GeomFromText('POLYGON((1 2, 1 5, 4 5, 4 2, 1 2))')), 2.0, 0.5) AS per_axis"); | ||
| Row row = first(t); | ||
| Box2D uniform = (Box2D) row.getField(0); | ||
| assertEquals(0.0, uniform.getXMin(), 0.0); | ||
| assertEquals(1.0, uniform.getYMin(), 0.0); | ||
| assertEquals(5.0, uniform.getXMax(), 0.0); | ||
| assertEquals(6.0, uniform.getYMax(), 0.0); | ||
| Box2D perAxis = (Box2D) row.getField(1); | ||
| assertEquals(-1.0, perAxis.getXMin(), 0.0); | ||
| assertEquals(1.5, perAxis.getYMin(), 0.0); | ||
| assertEquals(6.0, perAxis.getXMax(), 0.0); | ||
| assertEquals(5.5, perAxis.getYMax(), 0.0); | ||
| } |
Member
Author
There was a problem hiding this comment.
Done in 5158213 — added NULL Box2D coverage to both Flink signatures. NULL field comes back as null Java reference through getField.
Both Python and Flink tests now exercise NULL Box2D input through the uniform and per-axis ST_Expand signatures, confirming NULL propagates through the deserialization paths.
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 Implement ST_Expand for Box2D #2925What changes were proposed in this PR?
Adds Box2D variants of
ST_Expandalongside the existing Geometry-input overloads:ST_Expand(box: Box2D, units: double) -> Box2D— uniform expansion on both axesST_Expand(box: Box2D, dx: double, dy: double) -> Box2D— per-axis expansionPostGIS-compatible. NULL on null input. Negative deltas are allowed; if a negative delta produces
xmin > xmaxorymin > ymax, the result is returned as-is so callers can detect the degenerate bbox via the accessor functions (matches the Phase 1 design wherexmin > xmaxis reserved for future antimeridian-wraparound semantics rather than treated as in-band empty).Where the changes land
common/.../Functions.javaexpand(Box2D, ...)overloadsspark/common/.../expressions/Functions.scalaST_Expandcase class extended with two newinferrableFunction*overloads (Geometry overloads kept)flink/.../expressions/Functions.javaeval(Box2D, ...)methods on the existingST_ExpandclassColumn, JVM-side overload resolution handles Box2D vs GeometryHow was this patch tested?
common/.../FunctionsTest.java—expandBox2D(uniform, per-axis, negative delta producing degenerate output, NULL input).spark/common/.../functionTestScala.scala— "Passed ST_Expand for Box2D" (uniform, per-axis, shrink, NULL Box2D input).flink/.../FunctionTest.java—testExpandBox2D(uniform + per-axis through Flink Table API).python/tests/sql/test_function.py—test_st_expand_box_2d(uniform + per-axis through PySpark SQL withBox2DPython deserialization).Did this PR include necessary documentation updates?