{"record":{"id":"66746dcc970eaeab","repo":"apache/iceberg","slug":"cannot-convert-spark-geography-with-mixed-srid-to-66746d","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":"java.lang.UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.2/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.2/spark/src/main/java/org/apache/iceberg/spark/SparkTypeToType.java#L162-L198","documentation":"SparkTypeToType rejects Spark GeographyType columns whose coordinates use mixed SRIDs, since an Iceberg GeographyType must carry exactly one CRS/SRID. The UnsupportedOperationException is thrown during Spark-to-Iceberg type conversion instead of producing a lossy mapping.","triggerScenarios":"Schema conversion of a Spark DataFrame containing a geography column where geometry instances reference more than one SRID.","commonSituations":"Ingesting geodetic data combined from different sources (e.g. EPSG:4326 and EPSG:4269) into one geography column; upstream libraries that leave SRID unset on some geometries, triggering mixed detection.","solutions":["Reproject all geography values to one SRID (typically EPSG:4326) before conversion","Separate values by SRID into distinct geography columns","Convert to geometry or binary if a single-SRID geography contract cannot be enforced","Add an upstream validation step asserting a single SRID before writing"],"exampleFix":"// before\n// schema: geography(geom) with mixed SRIDs -> throws on conversion\n// after\ndf.withColumn(\"geom\", functions.expr(\"st_transform(geom, 'EPSG:4326')\")); // uniform SRID geography","handlingStrategy":"validation","validationCode":"if (sparkGeogType.isMixedSrid()) {\n  throw new IllegalStateException(\"Normalize geography SRID before Iceberg conversion\");\n}","typeGuard":"if (dt instanceof org.apache.spark.sql.types.GeographyType t && t.isMixedSrid()) {\n  return false; // not convertible until reprojected\n}","tryCatchPattern":"try {\n  icebergType = converter.convert(sparkSchema);\n} catch (UnsupportedOperationException e) {\n  if (e.getMessage().contains(\"mixed SRID\")) {\n    // reproject to one SRID (typically EPSG:4326) and retry\n  }\n}","preventionTips":["Normalize geodetic data to one SRID before loading","Split multi-SRID sources into separate columns","Add SRID assertions to spatial pipelines","Prefer geometry over geography when CRS discipline cannot be enforced"],"tags":["spark","spatial","geography","srid","type-conversion"],"backgroundTag":"unsupported-dtype","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"}