{"record":{"id":"d0e4c5e944b431ff","repo":"apache/iceberg","slug":"org-apache-iceberg-spark-sparkrewritetablecatalog","errorCode":null,"errorMessage":"org.apache.iceberg.spark.SparkRewriteTableCatalog does not support listing tables","messagePattern":"org\\.apache\\.iceberg\\.spark\\.SparkRewriteTableCatalog does not support listing tables","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/SparkRewriteTableCatalog.java","lineNumber":42,"sourceCode":"import org.apache.iceberg.spark.source.SparkTable;\nimport org.apache.spark.sql.catalyst.analysis.NoSuchTableException;\nimport org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException;\nimport org.apache.spark.sql.connector.catalog.Identifier;\nimport org.apache.spark.sql.connector.catalog.TableCatalog;\nimport org.apache.spark.sql.connector.catalog.TableChange;\nimport org.apache.spark.sql.connector.catalog.TableInfo;\nimport org.apache.spark.sql.util.CaseInsensitiveStringMap;\n\npublic class SparkRewriteTableCatalog implements TableCatalog, SupportsFunctions {\n\n  private static final String CLASS_NAME = SparkRewriteTableCatalog.class.getName();\n  private static final SparkTableCache TABLE_CACHE = SparkTableCache.get();\n\n  private String name = null;\n\n  @Override\n  public Identifier[] listTables(String[] namespace) {\n    throw new UnsupportedOperationException(CLASS_NAME + \" does not support listing tables\");\n  }\n\n  @Override\n  public SparkRewriteTable loadTable(Identifier ident) throws NoSuchTableException {\n    validateNoNamespace(ident);\n\n    String groupId = ident.name();\n    Table table = TABLE_CACHE.get(groupId);\n\n    if (table == null) {\n      throw new NoSuchTableException(ident);\n    }\n\n    return new SparkRewriteTable(table, groupId);\n  }\n\n  @Override\n  public SparkTable loadTable(Identifier ident, String version) throws NoSuchTableException {","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/SparkRewriteTableCatalog.java#L24-L60","documentation":"SparkRewriteTableCatalog is a special-purpose catalog used only for Spark rewrite (compact/maintain) procedures operating on cached table instances; it cannot enumerate namespaces or tables, so listTables always throws UnsupportedOperationException.","triggerScenarios":"Calling SparkRewriteTableCatalog.listTables(namespace), or invoking Spark procedures (e.g. rewrite_data_files) in a context where the SQL engine asks the catalog to list tables, such as SHOW TABLES or pattern-matching identifier resolution.","commonSituations":"Running SHOW TABLES / SHOW NAMESPACES against the rewrite catalog; configuring the rewrite catalog as a default catalog; tooling that introspects catalogs generically.","solutions":["Do not use SparkRewriteTableCatalog for discovery; it is only valid as the catalog passed to rewrite procedures.","Use the real Iceberg catalog (SparkCatalog/HadoopCatalog/HiveCatalog) for listing tables.","Configure SHOW TABLES against the source catalog, not the rewrite catalog."],"exampleFix":"// before\nspark.sql(\"SHOW TABLES IN rewrite_catalog.db\");\n// after\nspark.sql(\"SHOW TABLES IN my_catalog.db\"); // real catalog, then pass rewrite_catalog to the rewrite procedure","handlingStrategy":"validation","validationCode":"if (catalog instanceof SparkRewriteTableCatalog) {\n  throw new IllegalArgumentException(\"Rewrite catalog cannot list tables; use the source catalog\");\n}","typeGuard":"boolean supportsListing(CatalogPlugin c) {\n  return !(c instanceof SparkRewriteTableCatalog);\n}","tryCatchPattern":"try {\n  Identifier[] tables = catalog.listTables(ns);\n} catch (UnsupportedOperationException e) {\n  Identifier[] tables = realCatalog.listTables(ns); // fall back to the source catalog\n}","preventionTips":["Treat SparkRewriteTableCatalog as a procedure-scoped adapter, not a general catalog.","Point SHOW TABLES / introspection at the real Iceberg catalog.","Never set the rewrite catalog as the session default catalog.","Gate generic catalog tooling with capability checks."],"tags":["spark","rewrite","unsupported-operation","catalog"],"backgroundTag":"operation-not-supported","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"}