Parquet: Compute geometry bounding box metrics#17161
Open
huan233usc wants to merge 1 commit into
Open
Conversation
The Parquet footer's lexicographic min/max over WKB bytes is not meaningful for geometry, so geometry columns previously wrote counts only and could not be data skipped. Scan each value's coordinates as it is written and accumulate a 2D (XY) bounding box, emitting it as a FieldMetrics through the writer-side metrics channel (the same path float and double use for NaN counts). The box's lower and upper corners serialize into the existing lower_bounds and upper_bounds maps via the geometry conversion. A new pure-Java WKB coordinate scanner (WKBBoundingBox, in api/geospatial, no JTS dependency) walks all OGC geometry types, skips Z and M, ignores NaN coordinates, and validates the buffer defensively. Geography, higher dimensions, and the content_stats geo struct bounds are left as follow-ups.
ef2f67b to
4a1d8e8
Compare
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.
Computes a bounding box for
geometrycolumns in Parquet so they can carrylower_bounds/upper_boundsand participate in data skipping. This is the firstslice of the geo bounds work (Phase 2), scoped to the clean, unambiguous case.
Problem
The Parquet footer's lexicographic min/max over WKB bytes is not meaningful for
spatial values, so
ParquetMetricsdiverts geometry/geography columns tocounts-only metrics. As a result geometry columns get no bounds and cannot be
data-skipped.
Approach
Compute the box at write time, since the footer cannot provide it. This reuses
the existing writer-side value-scanning metrics channel — the same path
floatand
doublealready use to track NaN counts the footer can't give(
ParquetValueWriter.metrics()→ParquetWriter.metrics()):GeometryWriterwrites byte-identical WKB and folds each value's XYcoordinates into a running box, emitting a
FieldMetrics<GeospatialBound>whoselower/upper corners are the box. These serialize into the existing
lower_bounds/upper_boundsmaps through the geometryConversionscase. Nochanges to
ParquetMetrics,ParquetWriter, orConversions.the optional-field writer reconciles the null count, so the builder tracks only
non-null values.
WKBBoundingBox(new, inapi/geospatialnext toGeospatialBound/BoundingBox)is a pure-Java WKB coordinate scanner — no JTS dependency. It walks all OGC
geometry types (point, linestring, polygon, multi*, collection), handles both byte
orders (per-geometry, so mixed-endian collections work), reads past Z/M (XY-only
box), skips NaN coordinates (so
POINT EMPTYcontributes nothing, per spec), andvalidates the buffer defensively (truncation, bad byte order, unknown type, and
oversized counts all raise
IllegalArgumentExceptionrather than reading out ofbounds).
Scope
GEOMETRY only, 2D (XY), planar — the case the spec calls straightforward and
unambiguous. Deliberately left as follow-ups:
correction, out-of-range coordinate policy) — needs its own numeric design.
content_statsgeo_lower/geo_upperstruct writebridge, ORC/Avro geo bounds, and CRS validation.
Tests
TestWKBBoundingBox— the scanner across all geometry types, Z/M skip, both/mixedendianness, nested collections, empties, NaN skip, ±Inf, and malformed inputs.
TestGeometryFieldMetrics— the builder's bounds, counts, and empty/no-value cases.TestMetrics.testMetricsForGeospatialTypes(new, exercised viaTestParquetMetrics)— end-to-end: two geometry points produce the expected bbox in
lower_bounds/upper_bounds; geography stays bounds-less; ORC is skipped (geo is Parquet-only).TestParquetDataWriter.testGeospatialRoundTripstill passes unchanged, confirmingthe WKB bytes written are byte-identical.