{"record":{"id":"f5e9201bdd5898b6","repo":"apache/iceberg","slug":"cannot-convert-spark-geography-with-mixed-srid-to","errorCode":null,"errorMessage":"Cannot convert Spark geography with mixed SRID to Iceberg","messagePattern":"Cannot convert Spark geography with mixed SRID to Iceberg","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/SparkTypeToType.java","lineNumber":180,"sourceCode":"    } else if (atomic instanceof TimestampNTZType) {\n      return Types.TimestampType.withoutZone();\n\n    } else if (atomic instanceof DecimalType) {\n      return Types.DecimalType.of(\n          ((DecimalType) atomic).precision(), ((DecimalType) atomic).scale());\n    } else if (atomic instanceof BinaryType) {\n      return Types.BinaryType.get();\n    } else if (atomic instanceof GeometryType) {\n      GeometryType geometry = (GeometryType) atomic;\n      if (geometry.isMixedSrid()) {\n        throw new UnsupportedOperationException(\n            \"Cannot convert Spark geometry with mixed SRID to Iceberg\");\n      }\n      return Types.GeometryType.of(geometry.crs());\n    } else if (atomic instanceof GeographyType) {\n      GeographyType geography = (GeographyType) atomic;\n      if (geography.isMixedSrid()) {\n        throw new UnsupportedOperationException(\n            \"Cannot convert Spark geography with mixed SRID to Iceberg\");\n      }\n      return Types.GeographyType.of(geography.crs(), convertAlgorithm(geography.algorithm()));\n    } else if (atomic instanceof NullType) {\n      return Types.UnknownType.get();\n    }\n\n    throw new UnsupportedOperationException(\"Not a supported type: \" + atomic.catalogString());\n  }\n\n  // Translates Spark's edge-interpolation algorithm to Iceberg's, mirroring\n  // TypeToSparkType#convertAlgorithm. Spark supports only the spherical algorithm today; anything\n  // else is rejected loudly rather than silently defaulting, so a new Spark algorithm surfaces here\n  // instead of being dropped.\n  private static EdgeAlgorithm convertAlgorithm(EdgeInterpolationAlgorithm algorithm) {\n    switch (algorithm.toString().toUpperCase(Locale.ROOT)) {\n      case \"SPHERICAL\":\n        return EdgeAlgorithm.SPHERICAL;","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/SparkTypeToType.java#L162-L198","documentation":"Same as the geometry case: Spark's GeographyType maps to Iceberg's geography type only when it has a single SRID. A Spark geography with mixed SRID cannot be represented in Iceberg, so type conversion throws UnsupportedOperationException.","triggerScenarios":"Converting a Spark schema containing a GeographyType column with isMixedSrid() == true to an Iceberg Type (SparkSchemaUtil.convert, Iceberg scans/writes involving that column).","commonSituations":"Geography columns assembled from sources with differing SRIDs, or geo connectors that leave SRID unset so Spark reports mixed SRID.","solutions":["Ensure the geography column has one consistent SRID at the source","Re-project all geographies to a single SRID before conversion","Drop the geography column from the schema being converted or store it as binary with explicit handling"],"exampleFix":"// before\nSparkSchemaUtil.convert(schemaWithMixedSridGeography);\n// after: normalize SRID upstream\nval fixed = df.withColumn(\"geo\", ST_SetSRID(col(\"geo\"), 4326));","handlingStrategy":"validation","validationCode":"org.apache.spark.sql.types.GeographyType g = (GeographyType) dataType;\nif (g.isMixedSrid()) throw new IllegalArgumentException(\"Geography column must have a single SRID before Iceberg conversion\");","typeGuard":"boolean isMixedSridGeography(DataType t) { return t instanceof GeographyType && ((GeographyType) t).isMixedSrid(); }","tryCatchPattern":"try { convert(schema); } catch (UnsupportedOperationException e) { if (e.getMessage().contains(\"mixed SRID\")) { /* normalize SRID */ } throw e; }","preventionTips":["Set a single SRID at data production time","Check isMixedSrid() during schema review before enabling Iceberg on geo datasets","Document the required CRS for geography columns"],"tags":["spark","geography","srid","type-conversion"],"backgroundTag":"unsupported-operation","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}