{"record":{"id":"0450893c3c129881","repo":"apache/iceberg","slug":"cannot-convert-spark-geometry-with-mixed-srid-to-i","errorCode":null,"errorMessage":"Cannot convert Spark geometry with mixed SRID to Iceberg","messagePattern":"Cannot convert Spark geometry 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":173,"sourceCode":"\n    } else if (atomic instanceof DateType) {\n      return Types.DateType.get();\n\n    } else if (atomic instanceof TimestampType) {\n      return Types.TimestampType.withZone();\n\n    } 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","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/SparkTypeToType.java#L155-L191","documentation":"Spark's GeometryType is converted to Iceberg's geometry type during schema translation, but Iceberg requires a single SRID (coordinate reference system). A Spark geometry whose SRID is mixed (contains multiple/unknown SRIDs) cannot be represented in Iceberg, so conversion throws UnsupportedOperationException.","triggerScenarios":"Converting a Spark schema containing a GeometryType column with isMixedSrid() == true to an Iceberg Type — e.g. via SparkSchemaUtil.convert or when reading/writing a Spark dataframe with such geometry columns against Iceberg.","commonSituations":"Geometry data loaded without a declared CRS/SRID, unioned geometries with differing SRIDs, or Spark geo types produced by connectors that leave SRID unspecified.","solutions":["Fix the source data so the geometry column has a single, well-defined SRID","Cast/re-project geometries to a common SRID before handing the schema to Iceberg","Use a different (non-Iceberg) storage format for mixed-SRID geometry data"],"exampleFix":"// before: geometry column with mixed SRIDs converted directly\nTypes.StructType converted = SparkSchemaUtil.convert(sparkSchema);\n// after: re-project to a single SRID first\ndf = df.withColumn(\"geom\", ST_Transform(col(\"geom\"), 4326));","handlingStrategy":"validation","validationCode":"org.apache.spark.sql.types.GeometryType g = (GeometryType) dataType;\nif (g.isMixedSrid()) throw new IllegalArgumentException(\"Geometry column must have a single SRID before Iceberg conversion\");","typeGuard":"boolean isMixedSridGeometry(DataType t) { return t instanceof GeometryType && ((GeometryType) t).isMixedSrid(); }","tryCatchPattern":"try { convert(schema); } catch (UnsupportedOperationException e) { if (e.getMessage().contains(\"mixed SRID\")) { /* re-project geometry */ } throw e; }","preventionTips":["Normalize SRIDs upstream (ST_Transform / ST_SetSRID) before ingestion","Validate geo columns' SRID in ingestion pipelines","Keep geo library and Spark geo support versions aligned"],"tags":["spark","geometry","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"}