{"record":{"id":"0cfd12e7d373e1cb","repo":"apache/iceberg","slug":"cannot-select-snapshot-in-table-tabletype","errorCode":null,"errorMessage":"Cannot select snapshot in table: ${tableType}","messagePattern":"Cannot select snapshot in table: (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/BaseAllMetadataTableScan.java","lineNumber":49,"sourceCode":"import org.apache.iceberg.util.ParallelIterable;\nimport org.slf4j.Logger;\nimport org.slf4j.LoggerFactory;\n\nabstract class BaseAllMetadataTableScan extends BaseMetadataTableScan {\n  private static final Logger LOG = LoggerFactory.getLogger(BaseAllMetadataTableScan.class);\n\n  BaseAllMetadataTableScan(Table table, Schema schema, MetadataTableType tableType) {\n    super(table, schema, tableType);\n  }\n\n  BaseAllMetadataTableScan(\n      Table table, Schema schema, MetadataTableType tableType, TableScanContext context) {\n    super(table, schema, tableType, context);\n  }\n\n  @Override\n  public TableScan useSnapshot(long scanSnapshotId) {\n    throw new UnsupportedOperationException(\"Cannot select snapshot in table: \" + tableType());\n  }\n\n  @Override\n  public TableScan useRef(String ref) {\n    throw new UnsupportedOperationException(\"Cannot select ref in table: \" + tableType());\n  }\n\n  @Override\n  public TableScan asOfTime(long timestampMillis) {\n    throw new UnsupportedOperationException(\"Cannot select snapshot in table: \" + tableType());\n  }\n\n  @Override\n  public CloseableIterable<FileScanTask> planFiles() {\n    String metadataTableName = table().name() + \".\" + tableType().name().toLowerCase(Locale.ROOT);\n    LOG.info(\n        \"Scanning metadata table {} with filter {}.\",\n        metadataTableName,","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/BaseAllMetadataTableScan.java#L31-L67","documentation":"BaseAllMetadataTableScan.useSnapshot() always throws UnsupportedOperationException because 'all_*' metadata tables (all_data_files, all_manifests, all_delete_files, all_entries) aggregate across all snapshots, so selecting a single snapshot is meaningless. Time-travel/ref-selection APIs are intentionally unsupported on these scans.","triggerScenarios":"Calling tableScan.useSnapshot(id) on a scan of an all_* metadata table, e.g. table.scan(\"all_data_files\").useSnapshot(123L).","commonSituations":"Reusing generic scan-building code that applies time travel to every table, including metadata tables; Spark SQL queries with FOR VERSION AS OF against all_* tables.","solutions":["Remove the useSnapshot call when scanning all_* metadata tables","Scan the regular (non-all) metadata table such as the files/entries table if per-snapshot data is needed","Restrict snapshot selection in generic query planners to non-metadata tables (check tableType before calling useSnapshot)"],"exampleFix":"// before\nscan = table.scan(\"all_data_files\").useSnapshot(snapshotId);\n// after\nscan = table.scan(\"all_data_files\"); // all_* tables span all snapshots; no time travel\n","handlingStrategy":"validation","validationCode":"boolean isAllMetadataTable = tableName.contains(\".all_\");\nif (!isAllMetadataTable) {\n  scan = scan.useSnapshot(snapshotId);\n}","typeGuard":"null","tryCatchPattern":"try { scan.useSnapshot(id); } catch (UnsupportedOperationException e) { /* scanning all_* table; skip snapshot selection */ }","preventionTips":["Check the metadata table type before applying time-travel refinements","In engine planners, only emit FOR VERSION AS OF for non-metadata tables","Remember all_* tables inherently span all snapshots"],"tags":["unsupported-operation","metadata-table","time-travel"],"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"}