{"record":{"id":"9d20fcd8a6b89952","repo":"prestodb/presto","slug":"target-table-already-exists","errorCode":null,"errorMessage":"Target table already exists: ","messagePattern":"Target table already exists: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/testing/TestingMetadata.java","lineNumber":184,"sourceCode":"    @Override\n    public List<SchemaTableName> listTables(ConnectorSession session, Optional<String> schemaName)\n    {\n        ImmutableList.Builder<SchemaTableName> builder = ImmutableList.builder();\n        for (SchemaTableName tableName : tables.keySet()) {\n            if (schemaName.map(tableName.getSchemaName()::equals).orElse(true)) {\n                builder.add(tableName);\n            }\n        }\n        return builder.build();\n    }\n\n    @Override\n    public void renameTable(ConnectorSession session, ConnectorTableHandle tableHandle, SchemaTableName newTableName)\n    {\n        // TODO: use locking to do this properly\n        ConnectorTableMetadata table = getTableMetadata(session, tableHandle);\n        if (tables.putIfAbsent(newTableName, table) != null) {\n            throw new IllegalArgumentException(\"Target table already exists: \" + newTableName);\n        }\n        tables.remove(table.getTable(), table);\n    }\n\n    @Override\n    public void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, boolean ignoreExisting)\n    {\n        ConnectorTableMetadata existingTable = tables.putIfAbsent(tableMetadata.getTable(), tableMetadata);\n        if (existingTable != null && !ignoreExisting) {\n            throw new IllegalArgumentException(\"Target table already exists: \" + tableMetadata.getTable());\n        }\n    }\n\n    @Override\n    public void dropTable(ConnectorSession session, ConnectorTableHandle tableHandle)\n    {\n        tables.remove(getTableName(tableHandle));\n    }","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/testing/TestingMetadata.java#L166-L202","documentation":"TestingMetadata.renameTable (and related DDL paths): the rename/create target table already exists in this in-memory test connector. This sentinel guard lets tests exercise already-exists behavior without a real metastore.","triggerScenarios":"Thrown at presto-main-base/src/main/java/com/facebook/presto/testing/TestingMetadata.java:184 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Choose a new table name that does not exist","Drop the target table first in the test","Use the replace/overwrite flag where the test API supports it"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}