{"record":{"id":"f16e294d0f8ffeed","repo":"prestodb/presto","slug":"iceberg-invalid-spec-id","errorCode":"ICEBERG_INVALID_SPEC_ID","errorMessage":"Given spec id does not exist: %s","messagePattern":"Given spec id does not exist: (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-iceberg/src/main/java/com/facebook/presto/iceberg/procedure/RewriteManifestsProcedure.java","lineNumber":82,"sourceCode":"                \"rewrite_manifests\",\n                ImmutableList.of(\n                        new Argument(\"schema\", VARCHAR),\n                        new Argument(\"table_name\", VARCHAR),\n                        new Argument(\"spec_id\", INTEGER, false, null)),\n                REWRITE_MANIFESTS.bindTo(this));\n    }\n\n    public void rewriteManifests(ConnectorSession clientSession, String schemaName, String tableName, Integer specId)\n    {\n        try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(getClass().getClassLoader())) {\n            SchemaTableName schemaTableName = new SchemaTableName(schemaName, tableName);\n            IcebergAbstractMetadata metadata = (IcebergAbstractMetadata) metadataFactory.create();\n            Table icebergTable = getIcebergTable(metadata, clientSession, schemaTableName);\n            RewriteManifests rewriteManifests = icebergTable.rewriteManifests().clusterBy(file -> \"file\");\n            int targetSpecId;\n            if (specId != null) {\n                if (!icebergTable.specs().containsKey(specId)) {\n                    throw new PrestoException(ICEBERG_INVALID_SPEC_ID, \"Given spec id does not exist: \" + specId);\n                }\n                targetSpecId = specId;\n            }\n            else {\n                targetSpecId = icebergTable.spec().specId();\n            }\n            rewriteManifests.rewriteIf(manifest -> manifest.partitionSpecId() == targetSpecId).commit();\n            metadata.commit();\n        }\n    }\n}\n","sourceCodeStart":64,"sourceCodeEnd":94,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-iceberg/src/main/java/com/facebook/presto/iceberg/procedure/RewriteManifestsProcedure.java#L64-L94","documentation":"RewriteManifestsProcedure accepts an optional specId parameter identifying which partition spec's manifests to rewrite. Before using it, the procedure verifies the id exists in the Iceberg table's specs() map. If not, it throws ICEBERG_INVALID_SPEC_ID because rewriting manifests against a non-existent spec would corrupt manifest metadata.","triggerScenarios":"CALL system.rewrite_manifests with spec_id => <n> where <n> is not a spec id of the target table — typically a stale or guessed id after the table's partition spec evolved (ids are monotonically assigned per spec change).","commonSituations":"Hard-coded spec_id from an earlier table version that was replaced via ALTER TABLE SET PROPERTIES; confusing spec_id with partition values or spec field ids; copying a spec id from a different table.","solutions":["List the table's current spec ids (e.g. inspect the table metadata / specs) and pass an existing one","Omit the spec_id argument so the procedure defaults to the table's current spec (icebergTable.spec().specId())","If the spec was intentionally removed, rewrite manifests without spec_id and let Iceberg handle legacy specs"],"exampleFix":"// before\nCALL system.rewrite_manifests(table => 'db.t', spec_id => 7); -- spec 7 no longer exists\n// after\nCALL system.rewrite_manifests(table => 'db.t'); -- uses current spec","handlingStrategy":"validation","validationCode":"int specId = ...;\nif (!icebergTable.specs().containsKey(specId)) {\n    throw new IllegalArgumentException(\"Unknown spec id: \" + specId +\n        \"; known ids: \" + icebergTable.specs().keySet());\n}","typeGuard":"boolean isValidSpecId(Table icebergTable, int specId) {\n    return icebergTable.specs().containsKey(specId);\n}","tryCatchPattern":"try {\n    runRewriteManifests(specId);\n} catch (PrestoException e) {\n    if (ICEBERG_INVALID_SPEC_ID.equals(e.getErrorCode())) {\n        // fall back to the table's current spec id\n        runRewriteManifests(null);\n    }\n}","preventionTips":["Prefer omitting spec_id so the current spec is used automatically","Re-read spec ids after any partition-spec change (ALTER TABLE SET PROPERTIES)","Do not hard-code spec ids across environments or table versions"],"tags":["iceberg","partition-spec","procedure-argument"],"backgroundTag":"invalid-identifier","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"}