{"record":{"id":"da61a5dcd1ac3cef","repo":"apache/iceberg","slug":"cannot-retrieve-uuid-for-table","errorCode":null,"errorMessage":"Cannot retrieve UUID for table ","messagePattern":"Cannot retrieve UUID for table ","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/Spark3Util.java","lineNumber":995,"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  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":977,"sourceCodeEnd":1013,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/Spark3Util.java#L977-L1013","documentation":"Spark3Util.uuid() cannot determine a table's UUID because the given Table object does not expose TableOperations. Only tables backed by real Iceberg metadata (HasTableOperations) or metadata tables (BaseMetadataTable) have a UUID; other wrappers (e.g. Spark cached/wrapped tables or foreign catalog tables) do not.","triggerScenarios":"Calling Spark3Util.uuid(table) with a Table instance that is neither a HasTableOperations nor a BaseMetadataTable, e.g. a table wrapped by SparkCachedTableCatalog's cached Table or a custom Catalog implementation's Table.","commonSituations":"Running DESCRIBE TABLE EXTENDED or metadata queries through a Spark session whose catalog resolves tables to wrapped/proxied Table objects rather than the underlying BaseTable; custom catalog integrations returning non-standard Table implementations.","solutions":["Unwrap the table before calling uuid(): pass ((BaseTable) table).table() if the wrapper exposes the underlying table","If you own the Table implementation, implement HasTableOperations so the operations (and metadata UUID) are reachable","Verify the table was loaded through the Iceberg catalog, not a third-party catalog that returns non-Iceberg Table objects"],"exampleFix":"// before\nString uuid = Spark3Util.uuid(wrappedTable);\n// after\nTable base = (wrappedTable instanceof BaseTable) ? ((BaseTable) wrappedTable).table() : wrappedTable;\nString uuid = Spark3Util.uuid(base);","handlingStrategy":"type-guard","validationCode":"if (!(table instanceof BaseTable) && !(table instanceof HasTableOperations) && !(table instanceof BaseMetadataTable)) {\n  throw new IllegalArgumentException(\"Table \" + table.name() + \" has no Iceberg operations; UUID unavailable\");\n}","typeGuard":"boolean hasUuid(Table t) { return t instanceof HasTableOperations || t instanceof BaseMetadataTable; }","tryCatchPattern":"try { uuid = Spark3Util.uuid(table); } catch (UnsupportedOperationException e) { /* fall back to table.toString() or skip */ }","preventionTips":["Unwrap wrapped tables to the underlying BaseTable before metadata lookups","Require Table implementations used with Spark3Util to implement HasTableOperations"],"tags":["spark","unsupported-operation","table-metadata"],"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"}