Skip to content

[GH-3124] Fix Python geography SQL serialization - #3524

Draft
jiayuasu wants to merge 1 commit into
apache:masterfrom
jiayuasu:codex/oss-python-geography-wkb
Draft

jiayuasu wants to merge 1 commit into
apache:masterfrom
jiayuasu:codex/oss-python-geography-wkb

Conversation

@jiayuasu

@jiayuasu jiayuasu commented Nov 6, 2026

Copy link
Copy Markdown
Member

Did you read the Contributor Guide?

Yes, I have read the contributor rules and development guide.

Is this PR related to a ticket?

Related to #3124. This is an independent compatibility fix discovered while preparing the Spark 4.2 port; it does not enable native types.

What changes were proposed in this PR?

Python GeographyType currently encodes compact geometry bytes, but the JVM geography UDT expects a four-byte big-endian SRID followed by WKB. Consequently, collecting JVM geography values in Python and sending Python geography values to the JVM fail.

Use the existing JVM geography wire format on the Python side. Preserve SRID, supported Z/M dimensions, typed empties and nulls through collect, createDataFrame and Python UDFs. A shared Shapely WKB helper handles the supported Shapely 1.x empty-constructor and old-GEOS empty-point cases.

The JVM/S2 geography implementation, SQL geometry transport, and RDD/index serialization are unchanged.

How was this patch tested?

  • Reproduced the existing mismatch against an unchanged OSS shaded jar: JVM-only geography worked, while both Python/JVM directions failed. The added tests initially reported 17 failures.
  • Actual Spark 3.5.8 / Shapely 1.8.5: 57 passed, 1 unsupported-M skip. Spark 4.1.1 / Shapely 2.1.2: 58 passed. Both run the full existing geography SQL suite plus the new framing/UDF/SRID/null tests against unchanged JVM artifacts.
  • Focused pure tests cover both WKB byte orders, explicit SRIDs, dimensions, typed empties and malformed framing. Old GEOS <3.9 is not installed locally; those compatibility branches are tested with explicit version/writer-failure simulations.
  • Repository-pinned Black and commit hooks pass.

Review additionally reproduced three old-GEOS dimensional-empty failures; the corrected compatibility path passes all three. No actual GEOS <3.9 runtime was used.

Did this PR include necessary documentation updates?

No new public API. This fixes the behavior already documented by GeographyType.

This branch has not been deployed

No deployments
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.

1 participant