You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by we...@apache.org on 2026/04/02 01:24:49 UTC

(spark) branch master updated: [SPARK-55981][SQL] Allow Geo Types with SRID's from the pre-built registry

This is an automated email from the ASF dual-hosted git repository.

wenchen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 00b9451f4809 [SPARK-55981][SQL] Allow Geo Types with SRID's from the pre-built registry
00b9451f4809 is described below

commit 00b9451f480934375c5cadc723d1a0b11da6a34b
Author: Szehon Ho <sz...@gmail.com>
AuthorDate: Thu Apr 2 09:24:32 2026 +0800

    [SPARK-55981][SQL] Allow Geo Types with SRID's from the pre-built registry
    
    ### What changes were proposed in this pull request?
    This is based on PR: https://github.com/apache/spark/pull/54571, which pre-compiles a list of SRID's from Proj.
    
    Once that is in, we can activate these SRID's in the Geometry and Geography types
    
    We also have some overrides to support OGC standard as well.
    
    Note: some of these changes were from uros-db initially in https://github.com/apache/spark/pull/54543, thanks!
    
    ### Why are the changes needed?
    Support standard SRID's for new Geo types
    
    ### Does this PR introduce _any_ user-facing change?
    Geo types not released yet
    
    ### How was this patch tested?
    Add unit tests
    
    ### Was this patch authored or co-authored using generative AI tooling?
    Yes
    
    Closes #54780 from szehon-ho/srid.
    
    Authored-by: Szehon Ho <sz...@gmail.com>
    Signed-off-by: Wenchen Fan <we...@databricks.com>
---
 .../types/SpatialReferenceSystemCache.java         | 110 +++++++++++++++++---
 .../org/apache/spark/sql/types/GeographyType.scala |   2 +-
 .../types/SpatialReferenceSystemMapperSuite.java   | 115 +++++++++++++++++++--
 .../apache/spark/sql/GeographyDataFrameSuite.scala |  10 ++
 .../apache/spark/sql/GeometryDataFrameSuite.scala  |  12 +++
 .../spark/sql/types/GeographyTypeSuite.scala       |  45 ++++++--
 .../apache/spark/sql/types/GeometryTypeSuite.scala |  22 +++-
 .../spark/sql/types/JavaGeographyTypeSuite.java    |   9 +-
 .../spark/sql/types/JavaGeometryTypeSuite.java     |  11 +-
 9 files changed, 293 insertions(+), 43 deletions(-)

diff --git a/sql/api/src/main/java/org/apache/spark/sql/internal/types/SpatialReferenceSystemCache.java b/sql/api/src/main/java/org/apache/spark/sql/internal/types/SpatialReferenceSystemCache.java
index 34ea42271352..4aea617a9cb8 100644
--- a/sql/api/src/main/java/org/apache/spark/sql/internal/types/SpatialReferenceSystemCache.java
+++ b/sql/api/src/main/java/org/apache/spark/sql/internal/types/SpatialReferenceSystemCache.java
@@ -19,15 +19,27 @@ package org.apache.spark.sql.internal.types;
 
 import org.apache.spark.annotation.Unstable;
 
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
 import java.util.HashMap;
-import java.util.List;
+import java.util.Map;
 
 /**
  * Class for maintaining the mappings between supported SRID/CRS values and the corresponding SRS.
+ *
+ * The registry is populated from a CSV resource file generated from the PROJ library's EPSG
+ * database (see dev/generate_srs_registry.py). Additional Spark-specific entries and aliases
+ * are added for storage format compatibility (e.g. OGC:CRS84 for Parquet/Delta/Iceberg).
  */
 @Unstable
 public class SpatialReferenceSystemCache {
 
+  private static final String SRS_REGISTRY_RESOURCE =
+      "/org/apache/spark/sql/srs_registry.csv";
+
   // Private constructor to prevent external instantiation of this singleton class.
   private SpatialReferenceSystemCache() {
     populateSpatialReferenceSystemInformationMapping();
@@ -60,21 +72,79 @@ public class SpatialReferenceSystemCache {
 
   // Helper method for building the SRID-to-SRS and stringID-to-SRS mappings.
   private void populateSpatialReferenceSystemInformationMapping() {
-    // Currently, we only support a limited set of SRID / CRS values. However, we will soon extend
-    // this to support all the SRIDs supported by relevant authorities and libraries. The SRS list
-    // below will be updated accordingly, and the maps will be populated with more complete data.
-    List<SpatialReferenceSystemInformation> srsInformationList = List.of(
-      new SpatialReferenceSystemInformation(0, "SRID:0", false),
-      new SpatialReferenceSystemInformation(3857, "EPSG:3857", false),
-      new SpatialReferenceSystemInformation(4326, "OGC:CRS84", true)
-    );
-    // Populate the mappings using the same SRS information objects, avoiding any duplication.
-    for (SpatialReferenceSystemInformation srsInformation: srsInformationList) {
-      sridToSrs.put(srsInformation.srid(), srsInformation);
-      stringIdToSrs.put(srsInformation.stringId(), srsInformation);
+    loadSrsRegistryCsv();
+    addSparkSpecificEntries();
+  }
+
+  /**
+   * Load SRS entries from the CSV resource file generated from the PROJ EPSG database.
+   * The CSV has a header row (srid,string_id,is_geographic) and comment lines starting with '#'.
+   */
+  private void loadSrsRegistryCsv() {
+    try (InputStream is = getClass().getResourceAsStream(SRS_REGISTRY_RESOURCE)) {
+      if (is == null) {
+        throw new IllegalStateException(
+            "SRS registry resource not found: " + SRS_REGISTRY_RESOURCE);
+      }
+      try (BufferedReader reader =
+               new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
+        String line;
+        while ((line = reader.readLine()) != null) {
+          if (line.startsWith("#") || line.startsWith("srid,")) {
+            continue;
+          }
+          String[] parts = line.split(",", 3);
+          if (parts.length != 3) {
+            continue;
+          }
+          int srid = Integer.parseInt(parts[0].trim());
+          String stringId = parts[1].trim();
+          boolean isGeographic = Boolean.parseBoolean(parts[2].trim());
+          SpatialReferenceSystemInformation srsInfo =
+              new SpatialReferenceSystemInformation(srid, stringId, isGeographic);
+          sridToSrs.put(srid, srsInfo);
+          stringIdToSrs.put(stringId, srsInfo);
+        }
+      }
+    } catch (IllegalStateException e) {
+      throw e;
+    } catch (Exception e) {
+      throw new IllegalStateException(
+          "Failed to load SRS registry from " + SRS_REGISTRY_RESOURCE, e);
     }
   }
 
+  /**
+   * Add Spark-specific SRS entries and aliases that are not part of the PROJ EPSG database.
+   */
+  private void addSparkSpecificEntries() {
+    // SRID 0: Spark convention for Cartesian coordinate system with no defined SRS.
+    SpatialReferenceSystemInformation srid0 =
+        new SpatialReferenceSystemInformation(0, "SRID:0", false);
+    sridToSrs.put(0, srid0);
+    stringIdToSrs.put("SRID:0", srid0);
+
+    // OGC standardizations: override primary string IDs, keep EPSG as aliases.
+    addOgcOverride(4326, "OGC:CRS84");  // OGC standardization of WGS 84
+    addOgcOverride(4267, "OGC:CRS27");  // OGC standardization of NAD27
+    addOgcOverride(4269, "OGC:CRS83");  // OGC standardization of NAD83
+  }
+
+  /**
+   * Override a PROJ EPSG entry with an OGC string ID, keeping the EPSG string ID as an alias.
+   */
+  private void addOgcOverride(int srid, String ogcStringId) {
+    SpatialReferenceSystemInformation existing = sridToSrs.get(srid);
+    if (existing == null) {
+      throw new RuntimeException("SRID " + srid + " should already be in the SRS registry");
+    }
+    SpatialReferenceSystemInformation ogcEntry =
+        new SpatialReferenceSystemInformation(srid, ogcStringId, existing.isGeographic());
+    sridToSrs.put(srid, ogcEntry);
+    stringIdToSrs.put(ogcStringId, ogcEntry);
+    stringIdToSrs.put(existing.stringId(), ogcEntry);
+  }
+
   // Returns the SRS corresponding to the input SRID. If not supported, returns `null`.
   public SpatialReferenceSystemInformation getSrsInfo(int srid) {
     return sridToSrs.getOrDefault(srid, null);
@@ -84,4 +154,18 @@ public class SpatialReferenceSystemCache {
   public SpatialReferenceSystemInformation getSrsInfo(String stringId) {
     return stringIdToSrs.getOrDefault(stringId, null);
   }
+
+  /**
+   * Returns an unmodifiable view of the SRID-to-SRS map.
+   */
+  public Map<Integer, SpatialReferenceSystemInformation> getSridToSrs() {
+    return Collections.unmodifiableMap(sridToSrs);
+  }
+
+  /**
+   * Returns an unmodifiable view of the string CRS ID-to-SRS map.
+   */
+  public Map<String, SpatialReferenceSystemInformation> getStringIdToSrs() {
+    return Collections.unmodifiableMap(stringIdToSrs);
+  }
 }
diff --git a/sql/api/src/main/scala/org/apache/spark/sql/types/GeographyType.scala b/sql/api/src/main/scala/org/apache/spark/sql/types/GeographyType.scala
index f74cddc02ac4..5b572e94bb5a 100644
--- a/sql/api/src/main/scala/org/apache/spark/sql/types/GeographyType.scala
+++ b/sql/api/src/main/scala/org/apache/spark/sql/types/GeographyType.scala
@@ -193,7 +193,7 @@ object GeographyType extends SpatialType {
         errorClass = "ST_INVALID_SRID_VALUE",
         messageParameters = Map("srid" -> srid.toString))
     }
-    new GeographyType(GEOGRAPHY_DEFAULT_CRS, GEOGRAPHY_DEFAULT_ALGORITHM)
+    new GeographyType(crs, GEOGRAPHY_DEFAULT_ALGORITHM)
   }
 
   def apply(crs: String): GeographyType = {
diff --git a/sql/core/src/test/java/org/apache/spark/sql/internal/types/SpatialReferenceSystemMapperSuite.java b/sql/core/src/test/java/org/apache/spark/sql/internal/types/SpatialReferenceSystemMapperSuite.java
index 2d71377ce674..c1a756973915 100644
--- a/sql/core/src/test/java/org/apache/spark/sql/internal/types/SpatialReferenceSystemMapperSuite.java
+++ b/sql/core/src/test/java/org/apache/spark/sql/internal/types/SpatialReferenceSystemMapperSuite.java
@@ -21,6 +21,7 @@ import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
 import java.util.List;
+import java.util.Map;
 
 public class SpatialReferenceSystemMapperSuite {
 
@@ -50,23 +51,36 @@ public class SpatialReferenceSystemMapperSuite {
 
   @Test
   public void getStringIdReturnsCorrectStringIdForValidSrid() {
-    // GEOMETRY.
+    // GEOMETRY: Spark-specific and OGC override entries.
     Assertions.assertEquals("SRID:0", CartesianSpatialReferenceSystemMapper.getStringId(0));
     Assertions.assertEquals("EPSG:3857", CartesianSpatialReferenceSystemMapper.getStringId(3857));
     Assertions.assertEquals("OGC:CRS84", CartesianSpatialReferenceSystemMapper.getStringId(4326));
-    // GEOGRAPHY.
+    Assertions.assertEquals("OGC:CRS27", CartesianSpatialReferenceSystemMapper.getStringId(4267));
+    Assertions.assertEquals("OGC:CRS83", CartesianSpatialReferenceSystemMapper.getStringId(4269));
+    // GEOMETRY: PROJ-sourced registry entries (no override).
+    Assertions.assertEquals("EPSG:32601", CartesianSpatialReferenceSystemMapper.getStringId(32601));
+    Assertions.assertEquals(
+        "ESRI:102013", CartesianSpatialReferenceSystemMapper.getStringId(102013));
+    // GEOGRAPHY: Spark-specific and OGC override entries.
     Assertions.assertEquals("OGC:CRS84", GeographicSpatialReferenceSystemMapper.getStringId(4326));
+    Assertions.assertEquals("OGC:CRS27", GeographicSpatialReferenceSystemMapper.getStringId(4267));
+    Assertions.assertEquals("OGC:CRS83", GeographicSpatialReferenceSystemMapper.getStringId(4269));
+    // GEOGRAPHY: PROJ-sourced registry entries (no override).
+    Assertions.assertEquals("EPSG:4612", GeographicSpatialReferenceSystemMapper.getStringId(4612));
+    Assertions.assertEquals(
+        "ESRI:37001", GeographicSpatialReferenceSystemMapper.getStringId(37001));
   }
 
   @Test
   public void getStringIdReturnsNullForInvalidSrid() {
-    // GEOMETRY.
+    // GEOMETRY: SRIDs not in the registry.
     Assertions.assertNull(CartesianSpatialReferenceSystemMapper.getStringId(-2));
     Assertions.assertNull(CartesianSpatialReferenceSystemMapper.getStringId(-1));
     Assertions.assertNull(CartesianSpatialReferenceSystemMapper.getStringId(1));
     Assertions.assertNull(CartesianSpatialReferenceSystemMapper.getStringId(2));
     Assertions.assertNull(CartesianSpatialReferenceSystemMapper.getStringId(9999));
-    // GEOGRAPHY.
+    Assertions.assertNull(CartesianSpatialReferenceSystemMapper.getStringId(999999));
+    // GEOGRAPHY: non-geographic or invalid SRIDs.
     Assertions.assertNull(GeographicSpatialReferenceSystemMapper.getStringId(-2));
     Assertions.assertNull(GeographicSpatialReferenceSystemMapper.getStringId(-1));
     Assertions.assertNull(GeographicSpatialReferenceSystemMapper.getStringId(0));
@@ -74,6 +88,7 @@ public class SpatialReferenceSystemMapperSuite {
     Assertions.assertNull(GeographicSpatialReferenceSystemMapper.getStringId(2));
     Assertions.assertNull(GeographicSpatialReferenceSystemMapper.getStringId(3857));
     Assertions.assertNull(GeographicSpatialReferenceSystemMapper.getStringId(9999));
+    Assertions.assertNull(GeographicSpatialReferenceSystemMapper.getStringId(999999));
   }
 
   @Test
@@ -82,19 +97,103 @@ public class SpatialReferenceSystemMapperSuite {
     Assertions.assertEquals(0, CartesianSpatialReferenceSystemMapper.getSrid("SRID:0"));
     Assertions.assertEquals(3857, CartesianSpatialReferenceSystemMapper.getSrid("EPSG:3857"));
     Assertions.assertEquals(4326, CartesianSpatialReferenceSystemMapper.getSrid("OGC:CRS84"));
+    Assertions.assertEquals(4267, CartesianSpatialReferenceSystemMapper.getSrid("OGC:CRS27"));
+    Assertions.assertEquals(4269, CartesianSpatialReferenceSystemMapper.getSrid("OGC:CRS83"));
+    Assertions.assertEquals(4326, CartesianSpatialReferenceSystemMapper.getSrid("EPSG:4326"));
+    Assertions.assertEquals(4267, CartesianSpatialReferenceSystemMapper.getSrid("EPSG:4267"));
+    Assertions.assertEquals(4269, CartesianSpatialReferenceSystemMapper.getSrid("EPSG:4269"));
+    Assertions.assertEquals(32601, CartesianSpatialReferenceSystemMapper.getSrid("EPSG:32601"));
     // GEOGRAPHY.
     Assertions.assertEquals(4326, GeographicSpatialReferenceSystemMapper.getSrid("OGC:CRS84"));
   }
 
   @Test
   public void getSridReturnsNullForInvalidStringId() {
-    // GEOMETRY.
+    // GEOMETRY: String IDs not in the registry.
     Assertions.assertNull(CartesianSpatialReferenceSystemMapper.getSrid("INVALID:ID"));
-    Assertions.assertNull(CartesianSpatialReferenceSystemMapper.getSrid("EPSG:9999"));
-    // GEOGRAPHY.
+    Assertions.assertNull(CartesianSpatialReferenceSystemMapper.getSrid("EPSG:999999"));
+    // GEOGRAPHY: non-geographic or invalid string IDs.
     Assertions.assertNull(GeographicSpatialReferenceSystemMapper.getSrid("INVALID:ID"));
-    Assertions.assertNull(GeographicSpatialReferenceSystemMapper.getSrid("EPSG:9999"));
+    Assertions.assertNull(GeographicSpatialReferenceSystemMapper.getSrid("EPSG:999999"));
     Assertions.assertNull(GeographicSpatialReferenceSystemMapper.getSrid("SRID:0"));
     Assertions.assertNull(GeographicSpatialReferenceSystemMapper.getSrid("EPSG:3857"));
   }
+
+  /**
+   * The SRID map and CRS string-id map must be consistent inverses: canonical string ID from an
+   * SRID entry resolves back to that entry, and every CRS key resolves to the canonical entry for
+   * its SRID.
+   */
+  @Test
+  public void testMapValidity() {
+    SpatialReferenceSystemCache cache = SpatialReferenceSystemCache.getInstance();
+    Map<Integer, SpatialReferenceSystemInformation> sridToSrs = cache.getSridToSrs();
+    Map<String, SpatialReferenceSystemInformation> stringIdToSrs = cache.getStringIdToSrs();
+
+    for (Map.Entry<Integer, SpatialReferenceSystemInformation> e : sridToSrs.entrySet()) {
+      int srid = e.getKey();
+      SpatialReferenceSystemInformation bySrid = e.getValue();
+      Assertions.assertEquals(
+          srid,
+          bySrid.srid(),
+          "sridToSrs key must match SpatialReferenceSystemInformation.srid()");
+      SpatialReferenceSystemInformation byCanonicalCrs =
+          stringIdToSrs.get(bySrid.stringId());
+      Assertions.assertNotNull(
+          byCanonicalCrs,
+          "Canonical CRS string ID must exist in stringIdToSrs: srid=" + srid);
+      Assertions.assertSame(
+          bySrid,
+          byCanonicalCrs,
+          "sridToSrs entry must match stringIdToSrs for canonical string ID");
+    }
+
+    for (Map.Entry<String, SpatialReferenceSystemInformation> e : stringIdToSrs.entrySet()) {
+      String crsKey = e.getKey();
+      SpatialReferenceSystemInformation byCrs = e.getValue();
+      SpatialReferenceSystemInformation bySrid = sridToSrs.get(byCrs.srid());
+      Assertions.assertNotNull(
+          bySrid,
+          "CRS key must refer to a known SRID: crsKey=" + crsKey);
+      Assertions.assertSame(
+          bySrid,
+          byCrs,
+          "stringIdToSrs entry must match sridToSrs for that SRID (crsKey=" + crsKey + ")");
+    }
+  }
+
+  /**
+   * Validates expected registry scale: geographic SRID count and CRS string-id counts by
+   * authority prefix (empty authority for {@code SRID:0}, plus OGC, EPSG, ESRI).
+   */
+  @Test
+  public void testSpatialReferenceSystemContents() {
+    SpatialReferenceSystemCache cache = SpatialReferenceSystemCache.getInstance();
+    Map<Integer, SpatialReferenceSystemInformation> sridToSrs = cache.getSridToSrs();
+
+    int emptyAuthoritySrid0 = 0;
+    int ogc = 0;
+    int epsg = 0;
+    int esri = 0;
+    for (SpatialReferenceSystemInformation srs : sridToSrs.values()) {
+      String stringId = srs.stringId();
+      if ("SRID:0".equals(stringId)) {
+        emptyAuthoritySrid0++;
+      } else if (stringId.startsWith("OGC:")) {
+        ogc++;
+      } else if (stringId.startsWith("EPSG:")) {
+        epsg++;
+      } else if (stringId.startsWith("ESRI:")) {
+        esri++;
+      }
+    }
+    Assertions.assertEquals(1, emptyAuthoritySrid0, "SRID:0 (empty authority)");
+    Assertions.assertEquals(3, ogc, "OGC CRS string IDs");
+    Assertions.assertEquals(7720, epsg, "EPSG CRS string IDs");
+    Assertions.assertEquals(2919, esri, "ESRI CRS string IDs");
+    Assertions.assertEquals(
+        10643,
+        sridToSrs.size(),
+        "total SRID entries (SRID:0 + OGC + EPSG + ESRI)");
+  }
 }
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/GeographyDataFrameSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/GeographyDataFrameSuite.scala
index 537c943e94ae..4fe1269873c3 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/GeographyDataFrameSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/GeographyDataFrameSuite.scala
@@ -129,6 +129,16 @@ class GeographyDataFrameSuite extends QueryTest with SharedSparkSession {
     )
   }
 
+  test("createDataFrame and round-trip with Geography SRIDs") {
+    Seq(4267, 4269).foreach { srid =>
+      val geog = Geography.fromWKB(point1, srid)
+      val schema = StructType(Seq(StructField("g", GeographyType(srid), nullable = false)))
+      checkAnswer(
+        spark.createDataFrame(sparkContext.parallelize(Seq(Row(geog))), schema),
+        Seq(Row(geog)))
+    }
+  }
+
   test("createDataFrame APIs with Geography.fromWKB") {
     // 1. Test createDataFrame with RDD of Geography objects
     val geography1 = Geography.fromWKB(point1, 4326)
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/GeometryDataFrameSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/GeometryDataFrameSuite.scala
index 07d10d5ac60e..ff997d3f3fb2 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/GeometryDataFrameSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/GeometryDataFrameSuite.scala
@@ -130,6 +130,18 @@ class GeometryDataFrameSuite extends QueryTest with SharedSparkSession {
     )
   }
 
+  test("createDataFrame and round-trip with Geometry SRIDs") {
+    // Covers PROJ-sourced SRIDs, the Spark-specific SRID 0,
+    // and OGC-overridden SRIDs (4326, 4267, 4269).
+    Seq(0, 3857, 2000, 4326, 4267, 4269, 102100).foreach { srid =>
+      val geom = Geometry.fromWKB(point1, srid)
+      val schema = StructType(Seq(StructField("g", GeometryType(srid), nullable = false)))
+      checkAnswer(
+        spark.createDataFrame(sparkContext.parallelize(Seq(Row(geom))), schema),
+        Seq(Row(geom)))
+    }
+  }
+
   test("createDataFrame APIs with Geometry.fromWKB") {
     // 1. Test createDataFrame with RDD of Geometry objects
     val geometry1 = Geometry.fromWKB(point1, 0)
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/types/GeographyTypeSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/types/GeographyTypeSuite.scala
index d3dadd2429f5..8b4698ba9da0 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/types/GeographyTypeSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/types/GeographyTypeSuite.scala
@@ -30,7 +30,7 @@ class GeographyTypeSuite extends SparkFunSuite {
   // These tests verify the basic behavior of the GeographyType logical type.
 
   test("GEOGRAPHY type with specified invalid SRID") {
-    val srids: Seq[Int] = Seq(-4612, -4326, -2, -1, 1, 2, 3126, 4612)
+    val srids: Seq[Int] = Seq(-4612, -4326, -2, -1, 1, 2, 3126, 3857, 999999)
     srids.foreach { srid =>
       checkError(
         exception = intercept[SparkIllegalArgumentException] {
@@ -44,7 +44,7 @@ class GeographyTypeSuite extends SparkFunSuite {
   }
 
   test("GEOGRAPHY type with specified valid SRID") {
-    val srids: Seq[Int] = Seq(4326)
+    val srids: Seq[Int] = Seq(4326, 4267, 4269, 4612)
     srids.foreach { srid =>
       val g = GeographyType(srid)
       assert(g.srid == srid)
@@ -56,15 +56,19 @@ class GeographyTypeSuite extends SparkFunSuite {
       assert(g.typeName == s"geography($srid)")
       assert(g.simpleString == s"geography($srid)")
       assert(g.sql == s"GEOGRAPHY($srid)")
-      // GeographyType with mixed SRID cannot accept any other SRID value.
-      assert(g.acceptsGeographyType(GeographyType(4326)))
+      // GeographyType with a fixed SRID cannot accept a different SRID value.
+      assert(g.acceptsGeographyType(GeographyType(srid)))
+      val otherSrid = if (srid == 4267) 4326 else 4267
+      assert(!g.acceptsGeographyType(GeographyType(otherSrid)))
       assert(!g.acceptsGeographyType(GeographyType("ANY")))
     }
   }
 
   test("GEOGRAPHY type with specified valid CRS and algorithm") {
     val typeInformation: Seq[(Int, String, EdgeInterpolationAlgorithm)] = Seq(
-      (4326, "OGC:CRS84", EdgeInterpolationAlgorithm.SPHERICAL)
+      (4326, "OGC:CRS84", EdgeInterpolationAlgorithm.SPHERICAL),
+      (4267, "OGC:CRS27", EdgeInterpolationAlgorithm.SPHERICAL),
+      (4269, "OGC:CRS83", EdgeInterpolationAlgorithm.SPHERICAL)
     )
     typeInformation.foreach { case (srid, crs, algorithm) =>
       val g = GeographyType(crs, algorithm)
@@ -80,8 +84,10 @@ class GeographyTypeSuite extends SparkFunSuite {
       assert(g.typeName == s"geography($srid)")
       assert(g.simpleString == s"geography($srid)")
       assert(g.sql == s"GEOGRAPHY($srid)")
-      // GeographyType with mixed SRID cannot accept any other SRID value.
-      assert(g.acceptsGeographyType(GeographyType(4326)))
+      // GeographyType with a fixed SRID cannot accept a different SRID value.
+      assert(g.acceptsGeographyType(GeographyType(srid)))
+      val otherSrid = if (srid == 4267) 4326 else 4267
+      assert(!g.acceptsGeographyType(GeographyType(otherSrid)))
       assert(!g.acceptsGeographyType(GeographyType("ANY")))
     }
   }
@@ -134,6 +140,16 @@ class GeographyTypeSuite extends SparkFunSuite {
       "geography(4326)",
       "geography(OGC:CRS84, SPHERICAL)"
     )
+    assertStringRepresentation(
+      GeographyType(4267),
+      "geography(4267)",
+      "geography(OGC:CRS27, SPHERICAL)"
+    )
+    assertStringRepresentation(
+      GeographyType(4269),
+      "geography(4269)",
+      "geography(OGC:CRS83, SPHERICAL)"
+    )
   }
 
   // These tests verify the JSON parsing of different GEOGRAPHY types.
@@ -143,12 +159,17 @@ class GeographyTypeSuite extends SparkFunSuite {
       "\"geography\"",
       "\"geography(OGC:CRS84)\"",
       "\"geography(   OGC:CRS84 )\"",
+      "\"geography(OGC:CRS27)\"",
+      "\"geography(OGC:CRS83)\"",
+      "\"geography(EPSG:4612)\"",
       "\"geography(spherical)\"",
       "\"geography(SPHERICAL)\"",
       "\"geography(  spherical)\"",
       "\"geography(OGC:CRS84,    spherical    )\"",
       "\"geography( OGC:CRS84   , spherical )\"",
-      "\"geography( OGC:CRS84   , SPHERICAL )\""
+      "\"geography( OGC:CRS84   , SPHERICAL )\"",
+      "\"geography(OGC:CRS27, SPHERICAL)\"",
+      "\"geography(OGC:CRS83, SPHERICAL)\""
     )
     validGeographies.foreach { geog =>
       DataType.fromJson(geog).isInstanceOf[GeographyType]
@@ -186,7 +207,10 @@ class GeographyTypeSuite extends SparkFunSuite {
   test("GEOGRAPHY data type SQL parsing with valid SRID") {
     val validGeographies = Seq(
       "GEOGRAPHY(ANY)",
-      "GEOGRAPHY(4326)"
+      "GEOGRAPHY(4326)",
+      "GEOGRAPHY(4267)",
+      "GEOGRAPHY(4269)",
+      "GEOGRAPHY(4612)"
     )
     validGeographies.foreach { geog =>
       val dt = DataType.fromDDL(geog)
@@ -221,6 +245,9 @@ class GeographyTypeSuite extends SparkFunSuite {
   test("PhysicalDataType maps GeographyType to PhysicalGeographyType") {
     val geometryTypes: Seq[DataType] = Seq(
       GeographyType(4326),
+      GeographyType(4267),
+      GeographyType(4269),
+      GeographyType(4612),
       GeographyType("ANY")
     )
     geometryTypes.foreach { geometryType =>
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/types/GeometryTypeSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/types/GeometryTypeSuite.scala
index 9ae96eedef41..7e124ae130a4 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/types/GeometryTypeSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/types/GeometryTypeSuite.scala
@@ -30,7 +30,7 @@ class GeometryTypeSuite extends SparkFunSuite {
   // These tests verify the basic behavior of the GeometryType logical type.
 
   test("GEOMETRY type with specified invalid SRID") {
-    val srids: Seq[Int] = Seq(-4612, -4326, -2, -1, 1, 2)
+    val srids: Seq[Int] = Seq(-4612, -4326, -2, -1, 1, 2, 999, 99999)
     srids.foreach { srid =>
       checkError(
         exception = intercept[SparkIllegalArgumentException] {
@@ -44,7 +44,8 @@ class GeometryTypeSuite extends SparkFunSuite {
   }
 
   test("GEOMETRY type with specified valid SRID") {
-    val srids: Seq[Int] = Seq(0, 3857, 4326)
+    // SRID 0 (Spark Cartesian), 3857 (Web Mercator), and OGC-overridden geographic SRIDs.
+    val srids: Seq[Int] = Seq(0, 3857, 4326, 4267, 4269)
     srids.foreach { srid =>
       val g = GeometryType(srid)
       assert(g.srid == srid)
@@ -121,6 +122,8 @@ class GeometryTypeSuite extends SparkFunSuite {
     assertStringRepresentation(GeometryType(0), "geometry(0)", "geometry(SRID:0)")
     assertStringRepresentation(GeometryType(3857), "geometry(3857)", "geometry(EPSG:3857)")
     assertStringRepresentation(GeometryType(4326), "geometry(4326)", "geometry(OGC:CRS84)")
+    assertStringRepresentation(GeometryType(4267), "geometry(4267)", "geometry(OGC:CRS27)")
+    assertStringRepresentation(GeometryType(4269), "geometry(4269)", "geometry(OGC:CRS83)")
   }
 
   // These tests verify the JSON parsing of different GEOMETRY types.
@@ -128,7 +131,10 @@ class GeometryTypeSuite extends SparkFunSuite {
   test("GEOMETRY data type JSON parsing with valid CRS") {
     val validGeometries = Seq(
       "\"geometry\"",
-      "\"geometry(OGC:CRS84)\""
+      "\"geometry(OGC:CRS84)\"",
+      "\"geometry(EPSG:3857)\"",
+      "\"geometry(EPSG:32601)\"",
+      "\"geometry(ESRI:102013)\""
     )
     validGeometries.foreach { geom =>
       DataType.fromJson(geom).isInstanceOf[GeometryType]
@@ -170,7 +176,11 @@ class GeometryTypeSuite extends SparkFunSuite {
       "GEOMETRY(ANY)",
       "GEOMETRY(0)",
       "GEOMETRY(3857)",
-      "GEOMETRY(4326)"
+      "GEOMETRY(4326)",
+      "GEOMETRY(4267)",
+      "GEOMETRY(4269)",
+      "GEOMETRY(2000)",
+      "GEOMETRY(102100)"
     )
     validGeometries.foreach { geom =>
       val dt = DataType.fromDDL(geom)
@@ -207,6 +217,10 @@ class GeometryTypeSuite extends SparkFunSuite {
       GeometryType(0),
       GeometryType(3857),
       GeometryType(4326),
+      GeometryType(4267),
+      GeometryType(4269),
+      GeometryType(2000),
+      GeometryType(102100),
       GeometryType("ANY")
     )
     geometryTypes.foreach { geometryType =>
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/types/JavaGeographyTypeSuite.java b/sql/core/src/test/scala/org/apache/spark/sql/types/JavaGeographyTypeSuite.java
index 738c253f3367..1fd70162140d 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/types/JavaGeographyTypeSuite.java
+++ b/sql/core/src/test/scala/org/apache/spark/sql/types/JavaGeographyTypeSuite.java
@@ -33,8 +33,8 @@ public class JavaGeographyTypeSuite {
 
   @Test
   public void geographyTypeWithSpecifiedValidSridTest() {
-    // Valid SRID values for GEOGRAPHY. Note that only 4326 is supported for now.
-    Stream.of(4326).forEach(srid -> {
+    // Valid SRID values for GEOGRAPHY (geographic SRIDs from the registry).
+    Stream.of(4326, 4267, 4269, 4612).forEach(srid -> {
       DataType geographyType = DataTypes.createGeographyType(srid);
       Assertions.assertEquals("GEOGRAPHY(" + srid + ")", geographyType.sql());
       Assertions.assertEquals("geography(" + srid + ")", geographyType.typeName());
@@ -62,8 +62,9 @@ public class JavaGeographyTypeSuite {
 
   @Test
   public void geographyTypeWithSpecifiedValidCrsTest() {
-    // Valid CRS values for GEOGRAPHY. Note that only "OGC:CRS84" is supported for now.
-    Stream.of("OGC:CRS84").forEach(crs -> {
+    // Valid CRS values for GEOGRAPHY (including OGC overrides and EPSG aliases).
+    Stream.of("OGC:CRS84", "OGC:CRS27", "OGC:CRS83", "EPSG:4326", "EPSG:4267", "EPSG:4269",
+        "EPSG:4612").forEach(crs -> {
       Integer srid = GeographicSpatialReferenceSystemMapper.getSrid(crs);
       DataType geographyType = DataTypes.createGeographyType(crs);
       Assertions.assertEquals("GEOGRAPHY(" + srid + ")", geographyType.sql());
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/types/JavaGeometryTypeSuite.java b/sql/core/src/test/scala/org/apache/spark/sql/types/JavaGeometryTypeSuite.java
index dd19de0f7c32..867957884d23 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/types/JavaGeometryTypeSuite.java
+++ b/sql/core/src/test/scala/org/apache/spark/sql/types/JavaGeometryTypeSuite.java
@@ -33,8 +33,8 @@ public class JavaGeometryTypeSuite {
 
   @Test
   public void geometryTypeWithSpecifiedValidSridTest() {
-    // Valid SRID values for GEOMETRY.
-    Stream.of(0, 3857, 4326).forEach(srid -> {
+    // Valid SRID values for GEOMETRY
+    Stream.of(0, 3857, 4326, 4267, 4269, 2000, 102100).forEach(srid -> {
       DataType geometryType = DataTypes.createGeometryType(srid);
       Assertions.assertEquals("GEOMETRY(" + srid + ")", geometryType.sql());
       Assertions.assertEquals("geometry(" + srid + ")", geometryType.typeName());
@@ -62,8 +62,11 @@ public class JavaGeometryTypeSuite {
 
   @Test
   public void geometryTypeWithSpecifiedValidCrsTest() {
-    // Valid CRS values for GEOMETRY.
-    Stream.of("SRID:0", "EPSG:3857", "OGC:CRS84").forEach(crs -> {
+    // Valid CRS values for GEOMETRY (including Spark overrides)
+    Stream.of(
+        "SRID:0", "EPSG:3857", "OGC:CRS84", "EPSG:4326", "OGC:CRS27", "EPSG:4267", "OGC:CRS83", "EPSG:4269",
+        "EPSG:2000", "ESRI:102100")
+        .forEach(crs -> {
       Integer srid = CartesianSpatialReferenceSystemMapper.getSrid(crs);
       DataType geometryType = DataTypes.createGeometryType(crs);
       Assertions.assertEquals("GEOMETRY(" + srid + ")", geometryType.sql());


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org