{"record":{"id":"239d8923826c1baa","repo":"prestodb/presto","slug":"dropping-a-table-added-modified-in-the-same-transa","errorCode":null,"errorMessage":"dropping a table added/modified in the same transaction is not supported","messagePattern":"dropping a table added/modified in the same transaction is not supported","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/SemiTransactionalHiveMetastore.java","lineNumber":474,"sourceCode":"\n    public synchronized void dropTable(HdfsContext context, String databaseName, String tableName)\n    {\n        setShared();\n        // Dropping table with partition actions requires cleaning up staging data, which is not implemented yet.\n        checkNoPartitionAction(databaseName, tableName);\n        SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);\n        Action<TableAndMore> oldTableAction = tableActions.get(schemaTableName);\n        if (oldTableAction == null || oldTableAction.getType() == ActionType.ALTER) {\n            tableActions.put(schemaTableName, new Action<>(ActionType.DROP, null, context));\n            return;\n        }\n        switch (oldTableAction.getType()) {\n            case DROP:\n                throw new TableNotFoundException(schemaTableName);\n            case ADD:\n            case ALTER:\n            case INSERT_EXISTING:\n                throw new UnsupportedOperationException(\"dropping a table added/modified in the same transaction is not supported\");\n            default:\n                throw new IllegalStateException(\"Unknown action type\");\n        }\n    }\n\n    public synchronized void replaceView(MetastoreContext metastoreContext, String databaseName, String tableName, Table table, PrincipalPrivileges principalPrivileges)\n    {\n        setExclusive((delegate, hdfsEnvironment) -> {\n            MetastoreOperationResult operationResult = delegate.replaceTable(metastoreContext, databaseName, tableName, table, principalPrivileges);\n            return buildCommitHandle(new SchemaTableName(databaseName, tableName), operationResult);\n        });\n    }\n\n    public synchronized void renameTable(MetastoreContext metastoreContext, String databaseName, String tableName, String newDatabaseName, String newTableName)\n    {\n        setExclusive((delegate, hdfsEnvironment) -> {\n            MetastoreOperationResult operationResult = delegate.renameTable(metastoreContext, databaseName, tableName, newDatabaseName, newTableName);\n            return buildCommitHandle(new SchemaTableName(databaseName, tableName), operationResult);","sourceCodeStart":456,"sourceCodeEnd":492,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/SemiTransactionalHiveMetastore.java#L456-L492","documentation":"If a table was created or altered earlier in the same transaction, dropping it cannot be represented by the buffered action model (the drop would have to undo a not-yet-committed action), so dropTable throws UnsupportedOperationException. This is an in-transaction state conflict, not a metastore failure.","triggerScenarios":"Calling dropTable for a table whose existing action in this transaction is ADD, ALTER, or INSERT_EXISTING (e.g. createTable then dropTable, or alterTable then dropTable before commit).","commonSituations":"Cleanup/rollback logic that drops tables it just created inside the same transaction; retry logic that alters then decides to drop; speculative write jobs that create a table and abandon it in one transaction.","solutions":["Commit (or abort) the current transaction before dropping the table","Track tables created in-transaction and abort/roll back the transaction instead of issuing dropTable","Move the drop into a separate transaction after commit"],"exampleFix":"// before\nmetastore.createTable(ctx, table, privileges);\nmetastore.dropTable(ctx, db, tbl, false);\n// after\nmetastore.createTable(ctx, table, privileges);\n// to abandon, abort the transaction instead of dropping\nmetastore.abort();","handlingStrategy":"validation","validationCode":"// only drop tables the transaction did not create or alter\nif (tablesCreatedOrAlteredInTx.contains(new SchemaTableName(db, tbl))) {\n    throw new IllegalStateException(\"Abort transaction instead of dropping in-transaction table\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    metastore.dropTable(ctx, db, tbl, false);\n} catch (UnsupportedOperationException e) {\n    metastore.abort(); // abandon the whole transaction instead\n}","preventionTips":["Roll back with abort(), not dropTable, for tables created in the same transaction","Track in-transaction DDL per table name","Commit before dropping anything the transaction modified"],"tags":["hive","transaction","unsupported-operation","ddl"],"backgroundTag":"unsupported-operation-in-transaction","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"}