james-willis opened a new pull request, #60638: URL: https://github.com/apache/spark/pull/60638
### What changes were proposed in this pull request? `SpatialReferenceSystemCache` in `python/pyspark/sql/geo_utils.py` loads the SRS registry PySpark already ships (`python/pyspark/sql/srs_registry.csv`, generated by `dev/generate_srs_registry.py` from PROJ 9.8.1 alongside the JVM copy under `sql/api`) instead of a hard-coded table of three entries. The loading mirrors `SpatialReferenceSystemCache.java`: comment and header lines are skipped, each `srid,string_id,is_geographic` row becomes a `SpatialReferenceSystemInformation`, then the Spark-specific entries go on top: `SRID:0`, and the OGC overrides `OGC:CRS84` (4326), `OGC:CRS27` (4267) and `OGC:CRS83` (4269), which become the canonical string IDs of those SRIDs while their EPSG spellings keep resolving to the same SRS. `GeometryType`, `GeographyType` and their `_from_crs` constructors are unchanged; they already consult the two mappers, so they now accept and name every CRS the JVM does. The CSV is added to `package_data` of the classic and client distributions (`**/*.csv`), next to the JSON files. The cache exposes read-only copies of its two maps for the new test, `pyspark.sql.tests.test_geo_utils`, which is the Python counterpart of `SpatialReferenceSystemMapperSuite`: the same valid and invalid SRIDs and string IDs, the map consistency checks, and the same registry counts (1 `SRID:0`, 3 OGC, 7720 EPSG, 2990 ESRI, 10714 in all). ### Why are the changes needed? SPARK-55790 committed the registry to both the JVM resources and `python/pyspark/sql/`, but nothing in PySpark reads the Python copy. The JVM has accepted any registry SRID since then; PySpark still raises `ST_INVALID_SRID_VALUE` for everything but 0, 3857 and 4326: ```python >>> from pyspark.sql.types import GeometryType >>> GeometryType(32610) pyspark.errors.exceptions.base.IllegalArgumentException: [ST_INVALID_SRID_VALUE] Invalid or unsupported SRID (spatial reference identifier) value: 32610. ``` For a Spark Connect client this is fatal before any data moves: a result schema with `geometry(32610)` is decoded into `GeometryType(32610)` on the client, and the query fails with the error above, although the server considers the type valid. A `pyspark-client` of any released version (4.1.x, 4.2.1, 4.3.0) behaves this way, so a server cannot return a projected geometry column to a Python client unless it hides the CRS and sends `GEOMETRY(ANY)`. ### Does this PR introduce _any_ user-facing change? Yes. `GeometryType(srid)` and `GeographyType(srid)` accept every SRID in the shipped PROJ registry, EPSG and ESRI, where they accepted 0, 3857 and 4326 (geography: 4326) before; `GeometryType.fromCRS`-style parsing (`_from_crs`) accepts the matching string IDs, `EPSG:4326` and `OGC:CRS83` included. Spark Connect clients can decode result schemas carrying such types. SRIDs outside the registry still raise `ST_INVALID_SRID_VALUE`, and a projected SRID is still not a valid `GeographyType`. ### How was this patch tested? - New `python/pyspark/sql/tests/test_geo_utils.py` (plain `unittest`, no Spark session), registered in `dev/sparktestsupport/modules.py`. - `test_geometrytype.py` / `test_geographytype.py`: valid SRIDs now include 4267, 4269, 2154, 32610, 4612 and ESRI 102100 / 104030; invalid ones add 9999 and 999999, and for geography 0, 3857 and 32610; valid CRS strings add `EPSG:4326`, `OGC:CRS83`, `EPSG:2154`, `EPSG:32610`, `ESRI:102100`; invalid ones add `EPSG:999999`, `INVALID:ID`, and for geography `SRID:0` and `EPSG:3857`. The Connect parity suites reuse these mixins. - Ran the three modules' mixins against the source tree with `unittest.TestCase` (22 tests pass). `ruff==0.14.8` format and check clean on the changed files; `mypy==1.8.0` reports nothing in them. - Not tested: building the wheels and checking that the CSV lands in them. The `package_data` glob follows the existing `**/*.json` entry, and `include_package_data=True` is already set. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Fable 5.1) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
