HyukjinKwon opened a new pull request, #597:
URL: https://github.com/apache/spark-connect-rust/pull/597

   ### What changes were proposed in this pull request?
   
   The JSON of a Geometry or Geography in the Rust crate now names its SRID by 
the string ID that Spark's spatial reference system registry gives it, as Spark 
4.3.0 does (`GeometryType.jsonValue` is `geometry(<crs>)`, through 
`CartesianSpatialReferenceSystemMapper`/`GeographicSpatialReferenceSystemMapper`).
 So the JSON round-trips for every SRID that Spark supports, and the server 
reads it.
   
   - `crates/spark-connect/src/srs.rs` loads the registry once. The registry is 
`srs_registry.csv`, copied unchanged from Apache Spark 4.3.0's `sql/api` 
resources; Spark ships it with no extra LICENSE or NOTICE entry. On top of it 
come Spark's own entries: SRID 0 is `SRID:0`, and 4326, 4267 and 4269 are 
`OGC:CRS84`, `OGC:CRS27` and `OGC:CRS83`, which keep their EPSG IDs as aliases 
when reading. A Geography takes only geographic systems.
   - `from_json` reads the string IDs and their aliases, and rejects a CRS that 
Spark does not know (`ST_INVALID_CRS_VALUE`). `from_ddl` checks the SRID as 
Spark's parser does (`ST_INVALID_SRID_VALUE`).
   - The drop-in keeps the SRIDs of PySpark 4.3.0. PySpark's `geo_utils.py` 
knows only SRIDs 0, 3857 and 4326 (and 4326 for a Geography); it ships the CSV 
but does not read it. A schema from the server with a spatial type of another 
SRID now raises `ST_INVALID_SRID_VALUE` when its type is read, as PySpark does.
   - AGENTS.md section 4's out-of-date "known lossy case" and the spatial 
paragraph of `docs/types.md` are updated.
   
   ### Why are the changes needed?
   
   Before, `DataType::Geometry { srid: 2154 }` was written as 
`geometry(SRID:2154)`, which the server rejects with `ST_INVALID_CRS_VALUE`, 
and `from_json` could not read the `geometry(EPSG:2154)` that Spark writes. 
Only SRIDs 0, 3857 and 4326 round-tripped. On the server, `json_to_ddl` of a 
field typed `geometry(EPSG:2154)` gives `GEOMETRY(2154)`, while 
`geometry(SRID:2154)` fails.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes.
   - Rust API: a spatial type of any SRID that Spark supports writes and reads 
its Spark string ID. `from_json` rejects names that Spark does not know, and 
`from_ddl` rejects an SRID that Spark does not know, as Spark does. The lenient 
forms `srid:0`, `SRID:4326`, and 3857 as a geography now fail, as they do in 
Spark.
   - Python client: a schema from the server with a spatial type of an SRID 
that PySpark does not support now raises when the type is read, as in PySpark. 
Before, it returned the type.
   
   ### How was this patch tested?
   
   New tests, each checked to fail without the fix:
   - `types_roundtrip.rs`: `spatial_json_names_any_srid_of_spark_by_its_crs`, 
`spatial_json_rejects_a_crs_that_spark_does_not_take`, 
`spatial_ddl_checks_the_srid_as_spark_does`.
   - `e2e_session_catalog.rs`: 
`spatial_json_with_an_epsg_crs_is_read_by_the_server`. The server reads 
`geometry(EPSG:2154)` and `geography(EPSG:4269, ...)`, and a schema of 
`CAST(NULL AS GEOMETRY(2154))` reads back.
   - Python: `test_schema_spatial_srids_are_those_of_pyspark` (offline) and 
`test_spatial_schema_srids_are_those_of_pyspark` (e2e).
   - `srs.rs` unit tests.
   
   Also passing, with `TZ=UTC` and the upb protobuf backend, against Spark 
4.3.0:
   - Rust lib tests: 652 and 220 on the tree merged with the latest master.
   - CI's offline Python set: 3274 passed.
   - The Rust e2e suites for catalogs, coverage and functions.
   - `cargo fmt`, `scripts/audit_no_stubs.sh` and ruff.
   
   The embedded registry adds about 248 KB (+0.95%) to the extension.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5.5
   
   This pull request and its description were written by Isaac.
   


-- 
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]

Reply via email to