Skip to content

[GH-2886] Recognize Box2D columns as GeoParquet bbox covering columns#2921

Open
jiayuasu wants to merge 1 commit intoapache:masterfrom
jiayuasu:feature/box2d-geoparquet-writer
Open

[GH-2886] Recognize Box2D columns as GeoParquet bbox covering columns#2921
jiayuasu wants to merge 1 commit intoapache:masterfrom
jiayuasu:feature/box2d-geoparquet-writer

Conversation

@jiayuasu
Copy link
Copy Markdown
Member

@jiayuasu jiayuasu commented May 7, 2026

Did you read the Contributor Guide?

Is this PR related to a ticket?

What changes were proposed in this PR?

When a user has a Box2D-typed column in the schema being written, both the explicit covering option (geoparquet.covering[.geom]=<col>) and the auto-detect <geom>_bbox path now register it in GeoParquet metadata as the bbox covering column for the associated geometry.

Box2DUDT.sqlType is struct<xmin, ymin, xmax, ymax: double> — exactly the shape required by the GeoParquet 1.1 covering spec — so no data-path change is needed: the existing UserDefinedType → struct fallback in GeoParquetWriteSupport.makeWriter already serializes correctly. Only the metadata path needed to learn that a UDT-wrapped struct is a valid covering source.

The change is one new case in GeoParquetMetaData.createCoveringColumnMetadata that recognizes Box2DUDT and dispatches to the existing struct-shaped covering builder.

Why Float32 + conservative rounding is deferred

The original issue scoped Float32 + Math.nextUp / Math.nextDown outward rounding for size and bit-compatibility with apache/sedona-db's next_after writer. Shipping that without a paired reader-side change would create a write/read asymmetry: a written Box2D column comes back as a generic struct<float> (not a Box2D) because the on-disk Float32 schema no longer matches Box2DUDT.sqlType (which is Float64), so PySpark's UDT resolver doesn't claim it.

That asymmetry would regress the user-visible type round-trip we just shipped across #2890#2906. Pairing Float32 with reader auto-materialization is its own follow-up; this PR delivers the metadata side cleanly without committing the read-path regression.

How was this patch tested?

geoparquetIOTests:

  • "GeoParquet supports writing covering metadata from a Box2D column" — user-supplied Box2D column referenced via geoparquet.covering.geometry; verifies the GeoParquet metadata has matching covering.bbox.{xmin,ymin,xmax,ymax} paths.
  • "GeoParquet auto populates covering metadata for a Box2D <geom>_bbox column" — auto-detect path: a Box2D-typed geometry_bbox column gets registered without explicit configuration.

Did this PR include necessary documentation updates?

  • No, this PR does not affect any public SQL API documentation surface in isolation. Documentation for the Phase 1 Box2D surface (Add a native Box2D type for bounding boxes #2877) lands as a single coherent docs update once any deferred follow-ups (Float32 covering writer + reader auto-materialization) are scoped.

…olumns

When a user has a Box2D-typed column in the schema being written, both
the explicit covering option (geoparquet.covering[.geom]=<col>) and
the auto-detect <geom>_bbox path now register it in GeoParquet
metadata as the bbox covering column for the associated geometry.

Box2DUDT.sqlType is struct<xmin, ymin, xmax, ymax: double> — the exact
shape required by the GeoParquet 1.1 covering spec — so no data-path
change is needed: the existing UDT->struct fallback already serializes
correctly. Only the metadata path needed to learn that a UDT-wrapped
struct is a valid covering source.

Float32 + conservative outward rounding (Math.nextUp/Math.nextDown,
matching apache/sedona-db's next_after) is intentionally deferred to
pair with reader-side auto-materialization of covering columns as
Box2D — without that pairing, writing Float32 would create a write/
read asymmetry where reads come back as struct<float> instead of
Box2D, regressing user-visible types.

Closes apache#2886.
@jiayuasu jiayuasu requested a review from Copilot May 7, 2026 06:46
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

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for treating Box2D-typed columns as valid GeoParquet 1.1 bbox covering columns by recognizing the UDT in the metadata path, with accompanying tests for both explicit covering configuration and <geom>_bbox auto-detection.

Changes:

  • Recognize Box2DUDT as a valid covering source by mapping it to its underlying struct-shaped sqlType.
  • Add tests verifying covering metadata is written correctly for explicit geoparquet.covering.<geom> and auto-detected <geom>_bbox Box2D columns.

Reviewed changes

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

File Description
spark/common/src/main/scala/org/apache/spark/sql/execution/datasources/geoparquet/GeoParquetMetaData.scala Adds Box2DUDT handling so GeoParquet covering metadata can be derived from Box2D columns.
spark/common/src/test/scala/org/apache/sedona/sql/geoparquetIOTests.scala Adds tests covering explicit and auto-detected Box2D bbox covering metadata output.

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

Comment on lines 237 to 248
schema(coveringColumnIndex).dataType match {
case coveringColumnType: StructType =>
coveringColumnTypeToCovering(coveringColumnName, coveringColumnType)
case _: Box2DUDT =>
// Box2DUDT exposes a struct<xmin, ymin, xmax, ymax: double> sqlType, which is the exact
// shape required by GeoParquet 1.1 bbox covering columns. Treat the underlying struct as
// the covering struct so users can write a Box2D column and have it referenced as a
// covering column in GeoParquet metadata without any manual struct construction.
coveringColumnTypeToCovering(
coveringColumnName,
new Box2DUDT().sqlType.asInstanceOf[StructType])
case _ =>
Comment on lines +1032 to +1037
val geoParquetSavePath = geoparquetoutputlocation + "/gp_with_box2d_covering.parquet"
df.write
.format("geoparquet")
.option("geoparquet.covering.geometry", "test_cov")
.mode("overwrite")
.save(geoParquetSavePath)
Comment on lines +1058 to +1059
val geoParquetSavePath = geoparquetoutputlocation + "/gp_box2d_auto_covering.parquet"
df.write.format("geoparquet").mode("overwrite").save(geoParquetSavePath)
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.

Emit Box2D columns as GeoParquet 1.1 bbox covering columns

2 participants