{"record":{"id":"e6ff46c2e6ff12f9","repo":"prestodb/presto","slug":"not-found-e6ff46","errorCode":"NOT_FOUND","errorMessage":"Branch '%s' does not exist in table %S","messagePattern":"Branch '(.+?)' does not exist in table %S","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergUtil.java","lineNumber":397,"sourceCode":"                .collect(toImmutableList());\n    }\n\n    public static Optional<Long> resolveSnapshotIdByName(Table table, IcebergTableName name)\n    {\n        if (name.getSnapshotId().isPresent()) {\n            if (table.snapshot(name.getSnapshotId().get()) == null) {\n                throw new PrestoException(ICEBERG_INVALID_SNAPSHOT_ID, format(\"Invalid snapshot [%s] for table: %s\", name.getSnapshotId().get(), table));\n            }\n            return name.getSnapshotId();\n        }\n\n        if (name.getBranchName().isPresent()) {\n            String branchName = name.getBranchName().get();\n            SnapshotRef branchRef = table.refs().get(branchName);\n            if (branchRef != null && branchRef.isBranch()) {\n                return Optional.of(branchRef.snapshotId());\n            }\n            throw new PrestoException(NOT_FOUND, format(\"Branch '%s' does not exist in table %S\", branchName, table));\n        }\n\n        if (name.getTableType() == IcebergTableType.CHANGELOG) {\n            return Optional.ofNullable(SnapshotUtil.oldestAncestor(table)).map(Snapshot::snapshotId);\n        }\n\n        return tryGetCurrentSnapshot(table).map(Snapshot::snapshotId);\n    }\n\n    public static long getSnapshotIdTimeOperator(Table table, long millisUtc, VersionOperator operator)\n    {\n        return table.history().stream()\n                .filter(logEntry -> operator == VersionOperator.EQUAL ? logEntry.timestampMillis() <= millisUtc : logEntry.timestampMillis() < millisUtc)\n                .max(comparing(HistoryEntry::timestampMillis))\n                .orElseThrow(() -> new PrestoException(ICEBERG_INVALID_TABLE_TIMESTAMP, format(\"No history found based on timestamp for table %s\", table.name())))\n                .snapshotId();\n    }\n","sourceCodeStart":379,"sourceCodeEnd":415,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergUtil.java#L379-L415","documentation":"Thrown by resolveSnapshotIdByName when a table name references a branch (e.g. 'table@branch' syntax) that is not an existing branch ref in the Iceberg table metadata. The code checks table.refs() for the name and whether it is actually a branch; if not found or not a branch, it throws NOT_FOUND. This ensures branch-based reads/writes target a real Iceberg branch.","triggerScenarios":"Calling resolveSnapshotIdByName with an IcebergTableName carrying a branchName that either does not exist in table.refs(), or exists as a non-branch ref (e.g. a tag). Note the format string uses %S so the branch name is printed uppercase in the message.","commonSituations":"Typo in the branch name in the SQL (table@maim instead of @main); referencing a branch that was deleted or never created (CREATE BRANCH not run); accidentally using a tag name where a branch is expected; case-sensitivity mismatch between SQL and the created branch name.","solutions":["Verify the branch exists: SELECT name FROM \"catalog.db.t$refs\" WHERE type = 'BRANCH'","Create the missing branch with ALTER TABLE ... CREATE BRANCH (or ALTER TABLE ... CREATE BRANCH AS OF the desired snapshot)","Fix the branch-name typo or case in the query","If the ref is a tag, use tag syntax (FOR VERSION AS OF tag) instead of branch syntax"],"exampleFix":"// before\nSELECT * FROM catalog.db.t@audit_branch; -- branch never created\n// after\nALTER TABLE catalog.db.t CREATE BRANCH audit_branch;\nSELECT * FROM catalog.db.t@audit_branch;","handlingStrategy":"validation","validationCode":"// Check refs before using branch syntax\nboolean ok = table.refs().containsKey(branchName)\n          && table.refs().get(branchName).isBranch();\nif (!ok) throw new IllegalArgumentException(\"Not a branch: \" + branchName);","typeGuard":"boolean isBranch(Table table, String name) {\n    SnapshotRef ref = table.refs().get(name);\n    return ref != null && ref.isBranch();\n}","tryCatchPattern":"try {\n    return resolveSnapshotIdByName(table, name);\n} catch (PrestoException e) {\n    if (e.getErrorCode() == StandardErrorCode.NOT_FOUND) {\n        throw new UserError(\"Branch not found; valid branches: \" + table.refs().keySet());\n    }\n    throw e;\n}","preventionTips":["List refs via \"table$refs\" and filter type = 'BRANCH' before branch queries","Use CREATE BRANCH before referencing a new branch in SQL","Remember tags are not branches — use the right syntax for each ref kind","Watch case sensitivity: branch names are matched exactly (the message prints %S uppercase, which can mislead)"],"tags":["iceberg","branch","not-found","presto"],"backgroundTag":"branch-not-found","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"}