{"record":{"id":"353aa65d8e224517","repo":"apache/iceberg","slug":"cannot-retrieve-uuid-for-table-table-name","errorCode":null,"errorMessage":"Cannot retrieve UUID for table ${table.name()}","messagePattern":"Cannot retrieve UUID for table (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/Spark3Util.java","lineNumber":1051,"sourceCode":"\n    Preconditions.checkArgument(\n        namespace.length <= 1,\n        \"Cannot convert %s to a Spark v1 identifier, namespace contains more than 1 part\",\n        identifier);\n\n    String table = identifier.name();\n    Option<String> database = namespace.length == 1 ? Option.apply(namespace[0]) : Option.empty();\n    return org.apache.spark.sql.catalyst.TableIdentifier.apply(table, database);\n  }\n\n  public static String baseTableUUID(org.apache.iceberg.Table table) {\n    if (table instanceof HasTableOperations) {\n      TableOperations ops = ((HasTableOperations) table).operations();\n      return ops.current().uuid();\n    } else if (table instanceof BaseMetadataTable) {\n      return ((BaseMetadataTable) table).table().operations().current().uuid();\n    } else {\n      throw new UnsupportedOperationException(\"Cannot retrieve UUID for table \" + table.name());\n    }\n  }\n\n  private static class DescribeSortOrderVisitor implements SortOrderVisitor<String> {\n    private static final DescribeSortOrderVisitor INSTANCE = new DescribeSortOrderVisitor();\n\n    private DescribeSortOrderVisitor() {}\n\n    @Override\n    public String field(\n        String sourceName,\n        int sourceId,\n        org.apache.iceberg.SortDirection direction,\n        NullOrder nullOrder) {\n      return String.format(\"%s %s %s\", sourceName, direction, nullOrder);\n    }\n\n    @Override","sourceCodeStart":1033,"sourceCodeEnd":1069,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/Spark3Util.java#L1033-L1069","documentation":"uuid(Table) retrieves a table's UUID from its TableOperations metadata. It supports plain Iceberg tables (HasTableOperations) and metadata tables (BaseMetadataTable); any other Table implementation whose operations/metadata are not accessible throws UnsupportedOperationException.","triggerScenarios":"Calling Spark3Util.uuid(table) with a Table wrapper that neither implements HasTableOperations nor is a BaseMetadataTable — e.g. a custom or third-party Table implementation, or a wrapped/serializable table hiding its operations.","commonSituations":"Using uuid() in Spark plans/actions against a proxied table (e.g. certain cached or mocking wrappers); integrating a custom catalog whose Table impl doesn't expose operations; version drift where a wrapper class stopped implementing HasTableOperations.","solutions":["Ensure you pass the underlying org.apache.iceberg.Table (unwrap wrappers before calling uuid())","Make custom Table implementations implement HasTableOperations so operations() is accessible","For metadata tables, wrap them in a BaseMetadataTable subclass or fetch the UUID from the base table directly"],"exampleFix":"// before\nTable wrapped = new MyWrapperTable(inner);\nString uuid = Spark3Util.uuid(wrapped); // throws\n// after\nString uuid = Spark3Util.uuid(inner); // underlying table implements HasTableOperations","handlingStrategy":"type-guard","validationCode":"if (!(table instanceof HasTableOperations) && !(table instanceof BaseMetadataTable)) { /* obtain UUID another way */ }","typeGuard":"boolean hasAccessibleUuid(Table t) { return t instanceof HasTableOperations || t instanceof BaseMetadataTable; }","tryCatchPattern":"try { return Spark3Util.uuid(table); } catch (UnsupportedOperationException e) { return null; /* fall back to table.name() as key */ }","preventionTips":["Unwrap custom Table wrappers before calling uuid()","Implement HasTableOperations in custom Table implementations","Prefer using table UUID captured at load time from TableMetadata"],"tags":["spark","table-metadata","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}