uros-b commented on code in PR #60638:
URL: https://github.com/apache/spark/pull/60638#discussion_r4639382587


##########
python/packaging/classic/setup.py:
##########
@@ -342,7 +342,7 @@ def run(self):
             "pyspark.examples.src.main.python": "deps/examples",
         },
         package_data={
-            "pyspark": ["**/*.pyi", "**/py.typed", "**/*.json"],
+            "pyspark": ["**/*.pyi", "**/py.typed", "**/*.json", "**/*.csv"],

Review Comment:
   `"**/*.csv"` will matches recursively, so besides `sql/srs_registry.csv` 
which we want, here both the pyspark and pyspark-client wheels and sdists pick 
up every golden test CSV in the tree (40+ files it seems). Let's just simply 
use `"pyspark.sql": ["srs_registry.csv"]` instead (in both places).



##########
python/pyspark/sql/geo_utils.py:
##########
@@ -50,20 +59,57 @@ def __init__(self) -> None:
         self._string_id_to_srs: Dict[str, SpatialReferenceSystemInformation] = 
{}
         self._populate_srs_information_mapping()
 
-    # Helper method for building the SRID-to-SRS and stringID-to-SRS mappings.
+    # Helper method for building the SRID-to-SRS and stringID-to-SRS mappings. 
The steps and the
+    # entries mirror the JVM side (`SpatialReferenceSystemCache.java`), so 
that a PySpark client
+    # accepts exactly the SRIDs and CRS string IDs a Spark server does.
     def _populate_srs_information_mapping(self) -> None:
-        # Currently, we only support a limited set of SRID / CRS values, even 
on Scala side. The
-        # SRS list below will be updated soon, and the maps will be populated 
with more SRS data.
-        srs_list = [
-            SpatialReferenceSystemInformation(0, "SRID:0", False),
-            SpatialReferenceSystemInformation(3857, "EPSG:3857", False),
-            SpatialReferenceSystemInformation(4326, "OGC:CRS84", True),
-        ]
-        # Populate the mappings using the same SRS information objects, 
avoiding any duplication.
-        for srs in srs_list:
+        self._load_srs_registry()
+        self._add_spark_specific_entries()
+
+    # Loads the SRS registry resource: every PROJ-known EPSG and ESRI 
coordinate reference system.
+    def _load_srs_registry(self) -> None:
+        try:
+            registry = (
+                importlib.resources.files(__package__)
+                .joinpath(SRS_REGISTRY_RESOURCE)
+                .read_text(encoding="utf-8")
+            )
+        except (FileNotFoundError, OSError) as e:
+            raise PySparkRuntimeError(
+                f"SRS registry resource not found: 
pyspark.sql/{SRS_REGISTRY_RESOURCE}"
+            ) from e
+        for line in registry.splitlines():
+            if line.startswith("#") or line.startswith("srid,"):
+                continue
+            parts = line.split(",", 2)
+            if len(parts) != 3:
+                continue
+            srs = SpatialReferenceSystemInformation(
+                int(parts[0].strip()), parts[1].strip(), 
parts[2].strip().lower() == "true"
+            )
             self._srid_to_srs[srs.srid] = srs
             self._string_id_to_srs[srs.string_id] = srs
 
+    # Adds the entries Spark defines on top of the registry: SRID 0 for an 
unspecified CRS, and the
+    # OGC standardizations of WGS 84, NAD27 and NAD83, which become the 
canonical string IDs of
+    # their SRIDs while the EPSG string IDs keep resolving to the same SRS.
+    def _add_spark_specific_entries(self) -> None:
+        srid0 = SpatialReferenceSystemInformation(0, "SRID:0", False)
+        self._srid_to_srs[0] = srid0
+        self._string_id_to_srs["SRID:0"] = srid0
+        self._add_ogc_override(4326, "OGC:CRS84")  # OGC standardization of 
WGS 84

Review Comment:
   Should we also update equality checks now accordingly? We don't want Python 
and JVM type equality to diverge, for example 
`GeometryType._from_crs("EPSG:4326") == GeometryType(4326)` should be `True`. 
Same for GeographyType too. Before this PR every Python string ID was 
canonical, so this case could not happen, but now we need to ensure proper 
parity (on the JVM side, GeometryType.equals compares only the SRID, and 
GeographyType.equals compares SRID and algorithm, so proper behaviour is 
guaranteed).



##########
python/packaging/client/setup.py:
##########
@@ -206,7 +206,7 @@
         packages=connect_packages + test_packages,
         include_package_data=True,
         package_data={
-            "pyspark": ["**/*.pyi", "**/py.typed", "**/*.json"],
+            "pyspark": ["**/*.pyi", "**/py.typed", "**/*.json", "**/*.csv"],

Review Comment:
   (same comment as above)



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