Repository navigation
[GH-3124] Use SRID-prefixed ISO WKB for SQL spatial transport - #3528
Merged
Merged
Conversation
This was referenced Nov 7, 2026
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?
Yes, I have read the Contributor Rules and Contributor Development Guide.
Is this PR related to a ticket?
Related to #3124. Builds on the public Python WKB compatibility helper from merged #3524. This PR is a prerequisite for #3391's Spark 4.2 native integration.
What changes were proposed in this PR?
Replace Spark SQL
GeometryUDTandGeographyUDTpayloads with a signed four-byte little-endian SRID followed by ISO WKB. JVM geometry uses public JTS IO, JVM geography uses the public S2 WKB writer and a WKB header adapter, and Python uses public Shapely WKB.The SRID prefix is always present, including for SRID 0. For supported ISO WKB payloads, it supplies the decoded geometry's SRID, including collection members and their factories. Geography retains its existing S2 representation and lazy parsing behavior. Readers accept either ISO WKB payload byte order; the prefix is always little-endian. Geometry supports the full signed 32-bit SRID range; geography retains its nonnegative SRID requirement.
The implementation preserves nulls, supported XY/XYZ/XYM/XYZM layouts, dimensional empties, decoded-value ownership, and direct object evaluation during spatial joins. JVM polygon and multipart layout validation is retained; general collection members can have independent layouts. Public JTS/Shapely normalization and GEOS-dependent dimensional behavior are documented. Lazy JVM geography keeps its coordinate bytes and byte order while normalizing WKB headers; S2 computation and lazy/eager shape-index behavior are unchanged.
RDD/Kryo, spatial-index, Python RDD and Flink serialization keep their existing formats. The common non-SQL geography serializer keeps its big-endian prefix. Spark 4.2 native types and Spark's default serializer are handled separately in #3391.
Persisted ordinary-Parquet UDT columns require migration. Released compact geometry payloads and big-endian geography payloads must be exported using the version that wrote them, then reconstructed after upgrading. The guide uses portable WKB/EWKB columns and retains a separate geography SRID column so SRID 0 is not lost. The new reader does not guess the old format. GeoParquet and explicit WKB/EWKB interchange columns are unaffected by this UDT payload change.
Performance compared with master
The SQL migration is materially slower than compact geometry serialization; this is the cost of using public JTS/Shapely ISO WKB across the SQL boundary. Measurements compare master
0a61b7d6(serializer sources identical to the frozen baseline build at20efe7d4) withabb6442af579377b14b4646f4d675beb3bdd307c. The JVM geometry decode rows marked † include the subsequently removed component walk and are pre-cleanup measurements, not current-head timings. Geometry writers and the measured Python/geography paths are unchanged; no benchmark was rerun for this cleanup. Python master uses its built public C extension, verified active in every fork.Geography is compared against master's existing big-endian-SRID+WKB SQL boundary. Both lazy WKB and already-computed S2 inputs are included; S2 construction is outside timing.
Master's Python geography wrapper emits compact geometry bytes that are incompatible with its JVM geography boundary, so it is not used as a valid geography transport baseline. A separate six-pair Python geography-helper comparison against the compatible boundary in #3524 found point/polygon encoding costs of +28.1%/+10.3% and decoding costs of +11.0%/+6.2%; the measured before/after helper sources are byte-identical to #3524/current code, and this is not a master compact baseline.
Method: six paired fresh processes alternating master/measured-PR order; two-second prewarm, three warmup and five measured rounds; no samples dropped. XY inputs, SRID 4326. JVM: Corretto 17, Spark 4.1.1/Scala 2.13 dependencies, fixed 1 GiB heap, wall/CPU/allocation counters. Python: CPython 3.12.11, Shapely 2.1.2, GEOS 3.13.1, wall/CPU counters. Times are medians of per-fork medians; ratios are medians of paired ratios. All timed inputs round-trip; Python decoder ownership and JVM geography laziness were checked. These are local SQL codec microbenchmarks, not end-to-end Spark query, join or Spark 4.2 default native serializer measurements.
How was this patch tested?
Current-head validation at
99e48eef7022e1f95339c20c24eae36a857f19af:geoarrow.typesextension.git diff --checkpassed. The SRID-prefixed ISO WKB contract is unchanged; [GH-3124] Use native spatial types on Spark 4.2 #3391 records native Spark 4.2 integration validation.The performance runs above retained all 36 processes and 960 measured samples, with master's Python C extension verified active in each baseline fork. Their exact measured revision is stated separately from the current validation head.
All applicable current-head CI passed: JVM, Python, wheels, PyFlink, documentation, R and pre-commit. The R setup's package-retrieval stall cleared on one fresh-run retry; no source changes were needed.
Did this PR include necessary documentation updates?
Yes. The SQL spatial serialization guide documents the little-endian SRID + ISO WKB contract, layout behavior, and migration from released compact geometry and big-endian geography UDT files. It distinguishes SQL UDT payloads from standalone WKB/EWKB, unchanged RDD/index formats, and Spark 4.2 native values. Scala installation instructions link to the guide.