[GH-2973] Box3D constructors: ST_Box3D and ST_3DMakeBox#2984
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Spark SQL support for constructing Box3D values (3D bounding boxes) via new scalar functions, aligning behavior with PostGIS conventions and wiring them into Sedona’s Catalyst/UDF catalog.
Changes:
- Introduces
ST_Box3D(geom)backed byorg.apache.sedona.common.Functions.box3D/Box3D.fromGeometry. - Introduces
ST_3DMakeBox(p1, p2)backed byorg.apache.sedona.common.Constructors.make3DBox. - Registers both expressions in the SQL function catalog and adds a focused ScalaTest suite.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| spark/common/src/test/scala/org/apache/sedona/sql/Box3DConstructorSuite.scala | Adds SQL-level tests for ST_Box3D and ST_3DMakeBox. |
| spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala | Adds Catalyst expression ST_Box3D. |
| spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Constructors.scala | Adds Catalyst expression ST_3DMakeBox. |
| spark/common/src/main/scala/org/apache/sedona/sql/UDF/Catalog.scala | Registers ST_Box3D and ST_3DMakeBox in the function catalog. |
| common/src/main/java/org/apache/sedona/common/Functions.java | Adds Functions.box3D(Geometry) entry point. |
| common/src/main/java/org/apache/sedona/common/Constructors.java | Adds Constructors.make3DBox(Geometry, Geometry) implementation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+29
to
+32
| .sql("SELECT ST_Box3D(ST_GeomFromText('LINESTRING(0 0, 10 20)')) AS box2d, " + | ||
| "ST_Box3D(ST_GeomFromWKT('LINESTRING Z(0 0 -3, 5 10 7)')) AS box3d") | ||
| .collect()(0) | ||
| assert(row.getAs[Box3D]("box2d") == new Box3D(0, 0, 0, 10, 20, 0)) |
Second slice of the Box3D Phase 1 epic. Builds on the foundation (value class + UDT + Catalyst plumbing) merged in the previous slice. - `Functions.box3D(geom)`: returns the 3D bbox of a Geometry. Geometries whose coordinates have NaN Z fold into the z=0 plane (PostGIS- compatible). - `Constructors.make3DBox(p1, p2)`: builds a Box3D from two corner POINTZ geometries; missing-Z points contribute z=0. - `ST_Box3D` and `ST_3DMakeBox` Catalyst case classes wired through `InferredExpression`, registered in the Catalog. - `Box3DConstructorSuite`: covers ST_Box3D for XY, XYZ, null, and empty inputs; ST_3DMakeBox for POINTZ, XY-only points (Z folds to zero), and null point input. PostGIS-compatible semantics throughout. Phase 1 is split into 5 PRs; remaining slices: accessors+AsText, predicates, ST_3DExtent aggregate.
43c4ef6 to
ef003e3
Compare
10 tasks
3 tasks
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. Second of 5 slices for Add a native Box3D type for 3D bounding boxes (PostGIS-compatible) #2973. Builds on the foundation that landed in [GH-2973] Box3D foundation: value class + UDT + Catalyst plumbing #2978.What changes were proposed in this PR?
Adds the two scalar constructors that produce a
Box3Dfrom a Geometry or two corner points. MirrorsST_Box2D/ST_MakeBox2Dand PostGIS'sBox3D(geometry)/ST_3DMakeBox.Functions.box3D(geom): returns the 3D bbox of a Geometry. Geometries whose coordinates have NaN Z fold into thez = 0plane on a per-coordinate basis, matching PostGIS's flat-XY-treated-as-XY[Z=0] convention.Constructors.make3DBox(p1, p2): builds a Box3D from two corner POINTZ geometries. Missing-Z point inputs contributez = 0. Non-POINT input raisesIllegalArgumentException(same asST_MakeBox2D).ST_Box3DandST_3DMakeBoxCatalyst case classes wired throughInferredExpressionand registered inCatalog.boundingBoxExprs/Catalog.geometryConstructorExprs.How was this patch tested?
Box3DConstructorSuite(5 tests, all passing locally on Spark 3.5 / Scala 2.12):ST_Box3Don XY input (zmin/zmax = 0) and XYZ input.ST_Box3Dreturns NULL for null and empty geometry input.ST_3DMakeBoxfrom two POINTZ corners.ST_3DMakeBoxfrom XY-only points (Z folds to zero).ST_3DMakeBoxreturns NULL for null point input.Did this PR include necessary documentation updates?