Skip to content

[GH-2973] Box3D constructors: ST_Box3D and ST_3DMakeBox#2984

Merged
jiayuasu merged 1 commit into
apache:masterfrom
jiayuasu:feature/box3d-constructors
May 27, 2026
Merged

[GH-2973] Box3D constructors: ST_Box3D and ST_3DMakeBox#2984
jiayuasu merged 1 commit into
apache:masterfrom
jiayuasu:feature/box3d-constructors

Conversation

@jiayuasu
Copy link
Copy Markdown
Member

Did you read the Contributor Guide?

Is this PR related to a ticket?

What changes were proposed in this PR?

Adds the two scalar constructors that produce a Box3D from a Geometry or two corner points. Mirrors ST_Box2D / ST_MakeBox2D and PostGIS's Box3D(geometry) / ST_3DMakeBox.

  • Functions.box3D(geom): returns the 3D bbox of a Geometry. Geometries whose coordinates have NaN Z fold into the z = 0 plane 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 contribute z = 0. Non-POINT input raises IllegalArgumentException (same as ST_MakeBox2D).
  • ST_Box3D and ST_3DMakeBox Catalyst case classes wired through InferredExpression and registered in Catalog.boundingBoxExprs / Catalog.geometryConstructorExprs.

How was this patch tested?

Box3DConstructorSuite (5 tests, all passing locally on Spark 3.5 / Scala 2.12):

  • ST_Box3D on XY input (zmin/zmax = 0) and XYZ input.
  • ST_Box3D returns NULL for null and empty geometry input.
  • ST_3DMakeBox from two POINTZ corners.
  • ST_3DMakeBox from XY-only points (Z folds to zero).
  • ST_3DMakeBox returns NULL for null point input.

Did this PR include necessary documentation updates?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 by org.apache.sedona.common.Functions.box3D / Box3D.fromGeometry.
  • Introduces ST_3DMakeBox(p1, p2) backed by org.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.
@jiayuasu jiayuasu force-pushed the feature/box3d-constructors branch from 43c4ef6 to ef003e3 Compare May 27, 2026 05:19
@jiayuasu jiayuasu linked an issue May 27, 2026 that may be closed by this pull request
10 tasks
@jiayuasu jiayuasu added this to the sedona-1.9.1 milestone May 27, 2026
@jiayuasu jiayuasu merged commit 305795c into apache:master May 27, 2026
44 checks passed
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.

Add a native Box3D type for 3D bounding boxes (PostGIS-compatible)

2 participants