{"record":{"id":"5b74e0736952f9c3","repo":"apache/iceberg","slug":"iceberg-does-not-support-spark-geography-edge-algo-5b74e0","errorCode":null,"errorMessage":"Iceberg does not support Spark geography edge algorithm: ","messagePattern":"Iceberg does not support Spark geography edge algorithm: ","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":200,"sourceCode":"      }\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;\n      default:\n        throw new UnsupportedOperationException(\n            \"Iceberg does not support Spark geography edge algorithm: \" + algorithm);\n    }\n  }\n}\n","sourceCodeStart":182,"sourceCodeEnd":205,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/SparkTypeToType.java#L182-L205","documentation":"When converting a Spark GeographyType to Iceberg, convertAlgorithm maps Spark's edge-interpolation algorithm to Iceberg's EdgeAlgorithm. Spark only supports SPHERICAL today, so any other algorithm value hits the default branch and throws this UnsupportedOperationException. The loud failure avoids silently defaulting a new Spark algorithm to the wrong semantics.","triggerScenarios":"Schema conversion of a geography column whose EdgeInterpolationAlgorithm is not SPHERICAL (e.g. a new/unknown algorithm introduced by a Spark upgrade or plugin).","commonSituations":"Running a newer Spark with a new geography algorithm against an older iceberg-spark; corrupted or exotic algorithm values from third-party spatial libraries; copy-pasted DDL with an algorithm string that isn't SPHERICAL.","solutions":["Upgrade iceberg-spark to a version supporting the Spark geography edge algorithm","Recreate the geography column with the SPHERICAL algorithm (the only supported one)","Convert the column to geometry (crs only) if edge semantics don't matter for your use","Check algorithm values with st_ functions/DESCRIBE before writing to Iceberg"],"exampleFix":"// before\n// geography(geom, 'SOME_NEW_ALGORITHM') -> throws on conversion\n// after\ndf.withColumn(\"geom\", functions.expr(\"st_geogfromwkb(st_aswkb(geom), true /* spherical */)\")); // SPHERICAL","handlingStrategy":"validation","validationCode":"if (!\"SPHERICAL\".equalsIgnoreCase(String.valueOf(sparkGeogType.algorithm()))) {\n  throw new IllegalStateException(\"Only SPHERICAL geography is supported by Iceberg\");\n}","typeGuard":"if (dt instanceof org.apache.spark.sql.types.GeographyType g\n    && !\"SPHERICAL\".equalsIgnoreCase(String.valueOf(g.algorithm()))) {\n  return false; // not convertible until recreated with SPHERICAL\n}","tryCatchPattern":"try {\n  icebergType = converter.convert(sparkSchema);\n} catch (UnsupportedOperationException e) {\n  if (e.getMessage().contains(\"edge algorithm\")) {\n    // recreate the column with SPHERICAL or convert to geometry\n  }\n}","preventionTips":["Always create geography columns with the SPHERICAL algorithm","Check Spark upgrade notes for new EdgeInterpolationAlgorithm values before adopting","Pin iceberg-spark versions that match your Spark geography features","Fall back to geometry (crs-only) when edge semantics are irrelevant"],"tags":["spark","spatial","geography","edge-algorithm","enum"],"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-14T16:17:12.679Z"}