Skip to content

[GH-2973] Box3D accessors + ST_AsText overload#3005

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

[GH-2973] Box3D accessors + ST_AsText overload#3005
jiayuasu merged 1 commit into
apache:masterfrom
jiayuasu:feature/box3d-accessors

Conversation

@jiayuasu
Copy link
Copy Markdown
Member

Did you read the Contributor Guide?

Is this PR related to a ticket?

  • Yes, and the PR title follows the format [GH-XXX] my subject.

What changes were proposed in this PR?

Third slice of the Box3D Phase 1 epic (#2973). Builds on the type + constructors merged in #2978 and #2984.

  • Functions.{xMin, yMin, zMin, xMax, yMax, zMax}(Box3D) Java overloads — each returns the corresponding bound from the Box3D struct.
  • Functions.box3dAsText(Box3D) — PostGIS-format text form BOX3D(xmin ymin zmin, xmax ymax zmax). Not WKT; lives alongside the existing Box2D BOX(...) text form rather than inside the asWKT family.
  • Catalyst dispatch wired through InferredExpression: ST_XMin/YMin/ZMin/XMax/YMax/ZMax gain inferrableFunction1((b: Box3D) => ...) branches; ST_AsText is extended with a Box3D overload so the same accessor names work for geometry, Box2D, and Box3D.
  • Box3DAccessorSuite: covers all six accessors, NULL-input propagation, ST_AsText output format, and ST_AsText NULL propagation.

Remaining Phase 1 slices: predicates (ST_3DBoxIntersects / ST_3DBoxContains) and the ST_3DExtent aggregate.

How was this patch tested?

  • New ScalaTest suite Box3DAccessorSuite (4 tests, all green locally).
  • mvn -pl spark/common -Dspark=3.5 -Dscala=2.12 test covering the affected expression layer.

Did this PR include necessary documentation updates?

  • No, docs will land alongside the final Phase 1 slice once the full surface (accessors + predicates + aggregate) is in place.

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 Box3D accessor support to the Spark SQL expression layer and exposes a PostGIS-style BOX3D(...) text form via ST_AsText, with a new ScalaTest suite validating behavior.

Changes:

  • Added Functions.{xMin,yMin,zMin,xMax,yMax,zMax}(Box3D) overloads and Functions.box3dAsText(Box3D) in common.
  • Extended Catalyst InferredExpression dispatch so ST_XMin/YMin/ZMin/XMax/YMax/ZMax and ST_AsText accept Box3D.
  • Added Box3DAccessorSuite covering accessors, null propagation, and ST_AsText(box3d) formatting.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
spark/common/src/test/scala/org/apache/sedona/sql/Box3DAccessorSuite.scala Adds tests for Box3D accessors and ST_AsText(Box3D) behavior.
spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala Extends expression dispatch to support Box3D in accessors and ST_AsText.
common/src/main/java/org/apache/sedona/common/Functions.java Adds Box3D accessor overloads and box3dAsText implementation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +98 to +102
* This function takes a geometry and returns the maximum of all Z-coordinate values.
*/
private[apache] case class ST_ZMax(inputExpressions: Seq[Expression])
extends InferredExpression(Functions.zMax _) {
extends InferredExpression(
inferrableFunction1((g: Geometry) => Functions.zMax(g)),
Comment on lines +114 to +118
* This function takes a geometry and returns the minimum of all Z-coordinate values.
*/
private[apache] case class ST_ZMin(inputExpressions: Seq[Expression])
extends InferredExpression(Functions.zMin _) {
extends InferredExpression(
inferrableFunction1((g: Geometry) => Functions.zMin(g)),

/**
* PostGIS-format text for a Box3D: {@code BOX3D(xmin ymin zmin, xmax ymax zmax)}. NULL on null
* input. Like {@link #box2dAsText(Box2D)} this is not WKT (WKT has no {@code BOX3D} type) and
Third slice of the Box3D Phase 1 epic. Builds on the type + constructors
from the previous slices.

- `Functions.{xMin,yMin,zMin,xMax,yMax,zMax}(Box3D)` Java overloads —
  each returns the corresponding bound from the Box3D struct.
- `Functions.box3dAsText(Box3D)` — PostGIS-format text form
  `BOX3D(xmin ymin zmin, xmax ymax zmax)`. Not WKT; lives alongside the
  Box2D `BOX(...)` text form rather than inside the `asWKT` family.
- Catalyst case classes `ST_XMin/YMin/ZMin/XMax/YMax/ZMax` and
  `ST_AsText` extended with `inferrableFunction1((b: Box3D) => ...)`
  entries so Spark dispatches by argument type.
- `Box3DAccessorSuite`: covers all six accessors, NULL-input propagation,
  ST_AsText output format, and ST_AsText NULL propagation.

Remaining slices: predicates (ST_3DBoxIntersects / ST_3DBoxContains)
and ST_3DExtent aggregate.
@jiayuasu jiayuasu force-pushed the feature/box3d-accessors branch from a04bf45 to 666218c Compare May 28, 2026 22:20
@jiayuasu jiayuasu linked an issue May 29, 2026 that may be closed by this pull request
10 tasks
@jiayuasu jiayuasu added this to the sedona-1.9.1 milestone May 29, 2026
@jiayuasu jiayuasu merged commit 6623b58 into apache:master May 29, 2026
46 of 61 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