[GH-2886] Recognize Box2D columns as GeoParquet bbox covering columns#2921
Open
jiayuasu wants to merge 1 commit intoapache:masterfrom
Open
[GH-2886] Recognize Box2D columns as GeoParquet bbox covering columns#2921jiayuasu wants to merge 1 commit intoapache:masterfrom
jiayuasu wants to merge 1 commit intoapache:masterfrom
Conversation
…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.
Contributor
There was a problem hiding this comment.
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
Box2DUDTas a valid covering source by mapping it to its underlying struct-shapedsqlType. - Add tests verifying covering metadata is written correctly for explicit
geoparquet.covering.<geom>and auto-detected<geom>_bboxBox2D 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) |
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. Closes Emit Box2D columns as GeoParquet 1.1 bbox covering columns #2886What 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>_bboxpath now register it in GeoParquet metadata as the bbox covering column for the associated geometry.Box2DUDT.sqlTypeisstruct<xmin, ymin, xmax, ymax: double>— exactly the shape required by the GeoParquet 1.1 covering spec — so no data-path change is needed: the existingUserDefinedType→ struct fallback inGeoParquetWriteSupport.makeWriteralready 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.createCoveringColumnMetadatathat recognizesBox2DUDTand dispatches to the existing struct-shaped covering builder.Why Float32 + conservative rounding is deferred
The original issue scoped Float32 +
Math.nextUp/Math.nextDownoutward rounding for size and bit-compatibility withapache/sedona-db'snext_afterwriter. Shipping that without a paired reader-side change would create a write/read asymmetry: a writtenBox2Dcolumn comes back as a genericstruct<float>(not aBox2D) because the on-disk Float32 schema no longer matchesBox2DUDT.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.covering.geometry; verifies the GeoParquet metadata has matchingcovering.bbox.{xmin,ymin,xmax,ymax}paths.<geom>_bboxcolumn" — auto-detect path: a Box2D-typedgeometry_bboxcolumn gets registered without explicit configuration.Did this PR include necessary documentation updates?