{"record":{"id":"429963b99a010955","repo":"apache/iceberg","slug":"spark-does-not-support-geography-edge-algorithm","errorCode":null,"errorMessage":"Spark does not support geography edge algorithm: ","messagePattern":"Spark does not support geography edge algorithm: ","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/TypeToSparkType.java","lineNumber":192,"sourceCode":"    // IllegalArgumentException).\n    return GeometryType$.MODULE$.apply(geometry.crs());\n  }\n\n  private DataType geographyType(Types.GeographyType geography) {\n    // The spec requires a geography CRS to be geographic; Spark recognizes only OGC:CRS84, so any\n    // other CRS throws SparkIllegalArgumentException (an IllegalArgumentException).\n    return GeographyType$.MODULE$.apply(geography.crs(), convertAlgorithm(geography.algorithm()));\n  }\n\n  // Translates Iceberg's edge-interpolation algorithm to Spark's. Spark supports only the spherical\n  // algorithm (the Iceberg default); every other algorithm is rejected with a clear error. Shared\n  // with PruneColumnsWithoutReordering, which compares algorithms across the two type systems.\n  static EdgeInterpolationAlgorithm convertAlgorithm(EdgeAlgorithm algorithm) {\n    switch (algorithm) {\n      case SPHERICAL:\n        return SPARK_SPHERICAL;\n      default:\n        throw new UnsupportedOperationException(\n            \"Spark does not support geography edge algorithm: \" + algorithm);\n    }\n  }\n\n  private Metadata fieldMetadata(int fieldId) {\n    if (MetadataColumns.metadataFieldIds().contains(fieldId)) {\n      return new MetadataBuilder().putBoolean(METADATA_COL_ATTR_KEY, true).build();\n    }\n\n    return Metadata.empty();\n  }\n}\n","sourceCodeStart":174,"sourceCodeEnd":205,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/TypeToSparkType.java#L174-L205","documentation":"Spark's geometry support recognizes only the spherical edge interpolation algorithm; convertAlgorithm maps Iceberg edge algorithms to Spark's and throws UnsupportedOperationException for any other (e.g. planar/edge algorithms from the geo spec). The comment notes PruneColumnsWithoutReordering compares algorithms across type systems.","triggerScenarios":"Converting a geography-typed column whose edge algorithm is not SPHERICAL — tables created by engines/spec writers using non-spherical geography edges, read or pruned via Spark.","commonSituations":"Geo tables produced by non-Spark engines using planar edges; schema evolution changing the geography edge algorithm; cross-engine catalog access.","solutions":["Recreate or rewrite the geography column with the SPHERICAL algorithm","Prune the geography column from the Spark read projection","Upgrade Spark/Iceberg if support for the algorithm is added later"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"Types.GeographyType geo = (Types.GeographyType) t; boolean ok = geo.algorithm() == EdgeAlgorithm.SPHERICAL;","typeGuard":"boolean isSphericalGeography(Type t) { return t instanceof Types.GeographyType g && g.algorithm() == EdgeAlgorithm.SPHERICAL; }","tryCatchPattern":"try { convertAlgorithm(alg); } catch (UnsupportedOperationException e) { LOG.error(\"Unsupported edge algorithm {}\", alg, e); throw e; }","preventionTips":["Use SPHERICAL edges for geography columns shared with Spark","Document engine-specific geo limitations for shared tables","Prune geography columns when edges are incompatible"],"tags":["spark","geospatial","unsupported-value"],"backgroundTag":"unsupported-enum-value","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}