Skip to content

[GH-3021] Python Box3DType UDT bindings#3022

Merged
jiayuasu merged 1 commit into
apache:masterfrom
jiayuasu:feature/box3d-python-udt
Jun 1, 2026
Merged

[GH-3021] Python Box3DType UDT bindings#3022
jiayuasu merged 1 commit into
apache:masterfrom
jiayuasu:feature/box3d-python-udt

Conversation

@jiayuasu
Copy link
Copy Markdown
Member

@jiayuasu jiayuasu commented Jun 1, 2026

Did you read the Contributor Guide?

Is this PR related to a ticket?

  • Yes — closes #3021; follow-up to the Box3D Phase 1 epic (#2973).

What changes were proposed in this PR?

Adds the Python-side Box3D UDT so columns deserialize into a real Python object instead of requiring a CAST(... AS STRING) workaround. Pairs the Python Box3DType with the Scala Box3DUDT.pyUDT override that was deferred in #2978 pending the Python class.

  • python/sedona/spark/core/geom/box3d.py: new Box3D class with six float fields in PostGIS storage order (xmin, ymin, zmin, xmax, ymax, zmax), __eq__ / __hash__ / __repr__, mirroring the Box2D class shape.
  • python/sedona/spark/sql/types.py: new Box3DType(UserDefinedType). sqlType mirrors Box3DUDT.sqlType (six non-nullable doubles in the same order); scalaUDT points at org.apache.spark.sql.sedona_sql.UDT.Box3DUDT.
  • Re-exported Box3DType from python/sedona/spark/sql/__init__.py and python/sedona/spark/__init__.py alongside Box2DType.
  • Restored Box3DUDT.pyUDT override on the Scala side now that the Python class actually exists. This was removed in [GH-2973] Box3D foundation: value class + UDT + Catalyst plumbing #2978 to satisfy the P2 review note about a dangling pyUDT pointer.
  • Replaced the CAST(geom AS STRING) workaround in the existing ST_3DMakeBox / ST_Box3D / ST_3DExtent entries in python/tests/sql/test_dataframe_api.py with direct Box3D field-wise comparisons, matching how Box2D is tested.

How was this patch tested?

  • 5 Python test_dataframe_api.py entries (ST_3DMakeBox, ST_Box3D, ST_3DExtent, ST_3DBoxIntersects, ST_3DBoxContains) now collect Box3D Python objects and pass with the real UDT. All green locally.
  • Smoke-tested end-to-end via spark.sql("SELECT ST_Box3D(...)")df.first()[0] and verified the result is a Box3D instance with the expected field values.
  • Scala suites unchanged contract: Box3DUDTSuite, Box3DConstructorSuite, Box3DAccessorSuite, Box3DPredicateSuite, Box3DExtentSuite — all 23 tests pass locally after the pyUDT restore.

Did this PR include necessary documentation updates?

Adds the Python-side UDT so Box3D columns deserialize into a real
Python object instead of requiring a `CAST(... AS STRING)` workaround.
Pairs the Python `Box3DType` with the Scala `Box3DUDT.pyUDT` override
that was deferred in apache#2978 pending the Python class.

- `python/sedona/spark/core/geom/box3d.py`: new `Box3D` class with six
  float fields in PostGIS storage order, `__eq__` / `__hash__` /
  `__repr__`, mirroring the Box2D class shape.
- `python/sedona/spark/sql/types.py`: new `Box3DType(UserDefinedType)`.
  `sqlType` mirrors `Box3DUDT.sqlType` (six non-nullable doubles in
  the same order); `scalaUDT` points at
  `org.apache.spark.sql.sedona_sql.UDT.Box3DUDT`.
- Re-exported `Box3DType` from `python/sedona/spark/sql/__init__.py`
  and `python/sedona/spark/__init__.py` alongside `Box2DType`.
- Restored `Box3DUDT.pyUDT` override on the Scala side now that the
  Python class actually exists (removed in apache#2978 to satisfy the P2
  review note about a dangling pyUDT pointer).
- Replaced the `CAST(geom AS STRING)` workaround in the existing
  `ST_3DMakeBox` / `ST_Box3D` / `ST_3DExtent` entries in
  `python/tests/sql/test_dataframe_api.py` with direct `Box3D`
  field-wise comparisons, matching how Box2D is tested.
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

This PR adds first-class Python bindings for Sedona’s Box3D UDT so Spark SQL Box3D columns deserialize into a real Python Box3D object (instead of requiring string casts), aligning Python behavior with the existing JVM Box3D UDT.

Changes:

  • Restores/introduces the Scala Box3DUDT.pyUDT override pointing to the Python UDT class.
  • Adds Python Box3D value class and Box3DType(UserDefinedType) implementation matching the Scala struct layout/order.
  • Updates Python SQL/DataFrame tests to assert Box3D objects directly (removing the prior CAST(... AS STRING) workaround) and re-exports Box3DType from public Python modules.

Reviewed changes

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

Show a summary per file
File Description
spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/UDT/Box3DUDT.scala Adds the pyUDT override so Spark can deserialize Box3D values into Python via the new UDT.
python/sedona/spark/core/geom/box3d.py Introduces the Python Box3D value object (6 doubles in PostGIS order) with equality/hash/representation.
python/sedona/spark/sql/types.py Implements Box3DType UDT (StructType of 6 non-nullable doubles) with serialize/deserialize to Box3D.
python/sedona/spark/sql/init.py Re-exports Box3DType from the sedona.spark.sql package surface.
python/sedona/spark/init.py Re-exports Box3DType from the top-level sedona.spark namespace.
python/tests/sql/test_dataframe_api.py Updates existing Box3D-related test expectations to compare Box3D objects directly (no string-cast workaround).

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

@jiayuasu jiayuasu added this to the sedona-1.9.1 milestone Jun 1, 2026
@jiayuasu jiayuasu linked an issue Jun 1, 2026 that may be closed by this pull request
@jiayuasu jiayuasu merged commit d02397a into apache:master Jun 1, 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.

Python Box3DType UDT bindings

2 participants