{"record":{"id":"ab7af88fdeab1ed9","repo":"apache/iceberg","slug":"cannot-retrieve-uuid-for-table-table-name-ab7af8","errorCode":null,"errorMessage":"Cannot retrieve UUID for table <table.name()>","messagePattern":"Cannot retrieve UUID for table <table\\.name\\(\\)>","errorType":"exception","errorClass":"java.lang.UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/Spark3Util.java","lineNumber":1034,"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":1016,"sourceCodeEnd":1052,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/Spark3Util.java#L1016-L1052","documentation":"uuid() helper returns a table's metadata UUID, but only when the Table implements HasTableOperations or is a BaseMetadataTable. Any other Table implementation has no accessible operations/metadata, so this UnsupportedOperationException is thrown.","triggerScenarios":"Calling Spark3Util.uuid(table) with a Table wrapper that is neither HasTableOperations nor a BaseMetadataTable — e.g. custom Table implementations, mocked tables, or SparkTable delegates exposing unsupported inner tables.","commonSituations":"Building tools/metrics over tables from catalogs that return wrapped or lazy Table objects; using tables obtained through third-party catalog adapters instead of Iceberg's BaseTable.","solutions":["Obtain a BaseTable or HasTableOperations instance from the Iceberg catalog rather than a generic wrapper.","Unwrap the table (e.g. ((SparkTable) t).table()) before requesting the UUID.","For metadata tables (e.g. db.table.refs), use the table() accessor path handled by BaseMetadataTable.","Guard with instanceof checks and skip/report tables lacking operations instead of crashing."],"exampleFix":"// before\nTable t = someWrapperTable();\nString uuid = Spark3Util.uuid(t); // throws\n// after\nif (t instanceof BaseTable) {\n  String uuid = Spark3Util.uuid(((BaseTable) t).table());\n}","handlingStrategy":"type-guard","validationCode":"// Java\nboolean canGetUuid = table instanceof HasTableOperations\n    || table instanceof BaseMetadataTable\n    || (table instanceof BaseTable);","typeGuard":"String safeUuid(Table table) {\n  if (table instanceof HasTableOperations) {\n    return ((HasTableOperations) table).operations().current().uuid();\n  } else if (table instanceof BaseMetadataTable) {\n    return ((BaseMetadataTable) table).table().operations().current().uuid();\n  }\n  return null; // caller decides fallback\n}","tryCatchPattern":"try {\n  uuid = Spark3Util.uuid(table);\n} catch (UnsupportedOperationException e) {\n  uuid = null; // skip uuid-dependent reporting for this table\n}","preventionTips":["Get tables from Iceberg catalogs so they are BaseTable instances","Unwrap wrappers (e.g. SparkTable.table()) before metadata access","Treat uuid() as best-effort in tooling; handle null/absence gracefully","Avoid calling uuid on table types you don't control"],"tags":["spark","iceberg","uuid","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-14T16:17:12.679Z"}