{"record":{"id":"947398933b915021","repo":"apache/iceberg","slug":"sparkcachedtablecatalog-does-not-support-table-inv","errorCode":null,"errorMessage":"SparkCachedTableCatalog does not support table invalidation","messagePattern":"SparkCachedTableCatalog does not support table invalidation","errorType":"exception","errorClass":"java.lang.UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/SparkCachedTableCatalog.java","lineNumber":91,"sourceCode":"    Preconditions.checkArgument(\n        table.snapshotId() == null, \"Cannot time travel based on both table identifier and AS OF\");\n    return table.copyWithSnapshotId(Long.parseLong(version));\n  }\n\n  @Override\n  public SparkTable loadTable(Identifier ident, long timestampMicros) throws NoSuchTableException {\n    SparkTable table = load(ident);\n    Preconditions.checkArgument(\n        table.snapshotId() == null, \"Cannot time travel based on both table identifier and AS OF\");\n    // Spark passes microseconds but Iceberg uses milliseconds for snapshots\n    long timestampMillis = TimeUnit.MICROSECONDS.toMillis(timestampMicros);\n    long snapshotId = SnapshotUtil.snapshotIdAsOfTime(table.table(), timestampMillis);\n    return table.copyWithSnapshotId(snapshotId);\n  }\n\n  @Override\n  public void invalidateTable(Identifier ident) {\n    throw new UnsupportedOperationException(CLASS_NAME + \" does not support table invalidation\");\n  }\n\n  @Override\n  public SparkTable createTable(\n      Identifier ident, StructType schema, Transform[] partitions, Map<String, String> properties)\n      throws TableAlreadyExistsException {\n    throw new UnsupportedOperationException(CLASS_NAME + \" does not support creating tables\");\n  }\n\n  @Override\n  public SparkTable alterTable(Identifier ident, TableChange... changes) {\n    throw new UnsupportedOperationException(CLASS_NAME + \" does not support altering tables\");\n  }\n\n  @Override\n  public boolean dropTable(Identifier ident) {\n    throw new UnsupportedOperationException(CLASS_NAME + \" does not support dropping tables\");\n  }","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/SparkCachedTableCatalog.java#L73-L109","documentation":"Capability guard in SparkCachedTableCatalog.invalidateTable: cached-table loads are resolved per lookup from the underlying catalog, so there is no cache entry to invalidate and the operation is refused. The message names the catalog class; Spark should direct invalidation at the real catalog.","triggerScenarios":"Calling invalidateTable(ident) on SparkCachedTableCatalog, e.g. when Spark's cache invalidation machinery refreshes tables after writes, or direct calls via the TableCatalog interface.","commonSituations":"Mixing cached-table references with normal writes and expecting auto-refresh; Spark's CatalogImpl.invalidateTable walking all registered catalogs including the cached one.","solutions":["Remove/re-cache the cached table (UNCACHE TABLE) instead of invalidating it","Refresh via the underlying real catalog's invalidateTable","Update Iceberg — newer versions route invalidation through the table cache (SparkTableCache) instead of throwing"],"exampleFix":"// before\nspark.catalog().invalidateTable(\"spark_catalog_cached.db.tbl\"); // throws\n// after\nspark.sql(\"UNCACHE TABLE cached_tbl\");\nspark.catalog().invalidateTable(\"spark_catalog.db.tbl\");","handlingStrategy":"fallback","validationCode":"if (catalog instanceof SparkCachedTableCatalog) { invalidateViaRealCatalog(ident); return; }","typeGuard":null,"tryCatchPattern":"try { catalog.invalidateTable(ident); } catch (UnsupportedOperationException e) { spark.sql(\"UNCACHE TABLE \" + name); realCatalog.invalidateTable(ident); }","preventionTips":["Invalidate via the real catalog; refresh cached tables with UNCACHE/RECACHE","Upgrade Iceberg versions where invalidation is routed through SparkTableCache","Do not assume all TableCatalog implementations support invalidation"],"tags":["spark","catalog","cache"],"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"}