{"record":{"id":"b9a2de0cf3f84309","repo":"prestodb/presto","slug":"iceberg-invalid-snapshot-id","errorCode":"ICEBERG_INVALID_SNAPSHOT_ID","errorMessage":"Invalid snapshot [%s] for table: %s","messagePattern":"Invalid snapshot \\[(.+?)\\] for table: (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergAbstractMetadata.java","lineNumber":1564,"sourceCode":"                Optional.empty());\n    }\n\n    @Override\n    public Optional<SystemTable> getSystemTable(ConnectorSession session, SchemaTableName tableName)\n    {\n        IcebergTableName name = IcebergTableName.from(tableName.getTableName());\n        if (name.getTableType() == DATA || name.getTableType() == CHANGELOG) {\n            return Optional.empty();\n        }\n        SchemaTableName icebergTableName = new SchemaTableName(tableName.getSchemaName(), name.getTableName());\n        if (!tableExists(session, icebergTableName)) {\n            return Optional.empty();\n        }\n\n        Table icebergTable = getIcebergTable(session, icebergTableName);\n\n        if (name.getSnapshotId().isPresent() && icebergTable.snapshot(name.getSnapshotId().get()) == null) {\n            throw new PrestoException(ICEBERG_INVALID_SNAPSHOT_ID, format(\"Invalid snapshot [%s] for table: %s\", name.getSnapshotId().get(), icebergTable));\n        }\n\n        return getIcebergSystemTable(tableName, icebergTable);\n    }\n\n    @Override\n    public void truncateTable(ConnectorSession session, ConnectorTableHandle tableHandle)\n    {\n        shouldRunInAutoCommitTransaction(\"TRUNCATE TABLE\");\n        IcebergTableHandle handle = (IcebergTableHandle) tableHandle;\n        Table icebergTable = getIcebergTable(session, handle.getSchemaTableName());\n        removeScanFiles(handle, icebergTable, TupleDomain.all());\n    }\n\n    @Override\n    public ConnectorDistributedProcedureHandle beginCallDistributedProcedure(\n            ConnectorSession session,\n            QualifiedObjectName procedureName,","sourceCodeStart":1546,"sourceCodeEnd":1582,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergAbstractMetadata.java#L1546-L1582","documentation":"When a table handle carries an explicit snapshot id, getIcebergSystemTable verifies the snapshot actually exists on the loaded Iceberg table via table.snapshot(snapshotId). A null result means the id doesn't correspond to any snapshot of this table (expired, wrong table, or garbage id), and ICEBERG_INVALID_SNAPSHOT_ID is thrown.","triggerScenarios":"Querying iceberg.t FOR VERSION AS OF <id> (or via a system table like snapshots/history with an explicit snapshot) where the id was expired by snapshot expiry/retention, belongs to a different table, or was mistyped.","commonSituations":"Snapshot ids invalidated by expire_snapshots / retention cleanup; copying a snapshot id between environments or tables; using an id from before a table was dropped and recreated.","solutions":["Run SELECT * FROM iceberg.t\".snapshots (or SHOW SNAPSHOTS equivalent) to list valid snapshot ids and pick a current one.","Increase retention / stop expiring the needed snapshot, then retry with its id.","Verify the id belongs to the same table you're querying; correct typos or use FOR TIMESTAMP AS OF with a known timestamp instead."],"exampleFix":"// before\nSELECT * FROM iceberg.t FOR VERSION AS OF 123456789; -- expired\n// after\nSELECT * FROM iceberg.t\".snapshots; -- find valid id\nSELECT * FROM iceberg.t FOR VERSION AS OF 987654321;","handlingStrategy":"validation","validationCode":"Set<Long> validIds = icebergTable.snapshots().stream()\n    .map(Snapshot::snapshotId).collect(toSet());\nif (!validIds.contains(requestedSnapshotId)) {\n    throw new IllegalArgumentException(\"Snapshot \" + requestedSnapshotId + \" not on table \" + tableName);\n}","typeGuard":null,"tryCatchPattern":"try {\n    return queryForSnapshot(tableName, snapshotId);\n} catch (PrestoException e) {\n    if (e.getErrorCode().code() == ICEBERG_INVALID_SNAPSHOT_ID) {\n        long latest = latestSnapshotId(tableName); // from snapshots system table\n        return queryForSnapshot(tableName, latest);\n    }\n    throw e;\n}","preventionTips":["List snapshots from the snapshots system table before pinning an id.","Account for snapshot expiry/retention jobs when choosing historical ids.","Never reuse snapshot ids across tables or environments."],"tags":["iceberg","snapshot","time-travel","invalid-snapshot-id"],"backgroundTag":"invalid-snapshot-id","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}