{"record":{"id":"c39c06574fd10382","repo":"prestodb/presto","slug":"already-exists-c39c06","errorCode":"ALREADY_EXISTS","errorMessage":"Schema already exists: '${schemaName}'","messagePattern":"Schema already exists: '(.+?)'","errorType":"error_code","errorClass":"SchemaAlreadyExistsException","httpStatus":null,"severity":"error","filePath":"presto-kudu/src/main/java/com/facebook/presto/kudu/schema/SchemaEmulationByTableNameConvention.java","lineNumber":61,"sourceCode":"\npublic class SchemaEmulationByTableNameConvention\n        implements SchemaEmulation\n{\n    private final String commonPrefix;\n    private final String rawSchemasTableName;\n    private KuduTable rawSchemasTable;\n\n    public SchemaEmulationByTableNameConvention(String commonPrefix)\n    {\n        this.commonPrefix = commonPrefix;\n        this.rawSchemasTableName = commonPrefix + \"$schemas\";\n    }\n\n    @Override\n    public void createSchema(KuduClient client, String schemaName)\n    {\n        if (DEFAULT_SCHEMA.equals(schemaName)) {\n            throw new SchemaAlreadyExistsException(schemaName);\n        }\n        else {\n            try {\n                KuduTable schemasTable = getSchemasTable(client);\n                KuduSession session = client.newSession();\n                try {\n                    Upsert upsert = schemasTable.newUpsert();\n                    upsert.getRow().addString(0, schemaName);\n                    session.apply(upsert);\n                }\n                finally {\n                    session.close();\n                }\n            }\n            catch (KuduException e) {\n                throw new PrestoException(GENERIC_INTERNAL_ERROR, e);\n            }\n        }","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-kudu/src/main/java/com/facebook/presto/kudu/schema/SchemaEmulationByTableNameConvention.java#L43-L79","documentation":"Thrown by SchemaEmulationByTableNameConvention.createSchema when the requested schema cannot be created because it already effectively exists. This happens specifically when schemaName is 'default', which is always implicitly present under table-name-convention emulation, so creating it again conflicts (ALREADY_EXISTS).","triggerScenarios":"Calling createSchema('default') — e.g. CREATE SCHEMA default — on a Kudu catalog using schema emulation by table name convention.","commonSituations":"Bootstrap/idempotent setup scripts that unconditionally CREATE SCHEMA IF NOT EXISTS-style code paths hitting the default schema; ORMs provisioning all standard schemas; automation that re-runs initialization.","solutions":["Skip creating 'default'; it always exists under this emulation mode","Guard creation so the default schema is never passed to createSchema","If you need real distinct schemas, switch emulation mode or use a connector with native schema support"],"exampleFix":"// before\nconnector.createSchema(client, schemaName); // schemaName could be \"default\"\n// after\nif (!\"default\".equals(schemaName)) {\n    connector.createSchema(client, schemaName);\n}","handlingStrategy":"validation","validationCode":"if (\"default\".equals(schemaName)) {\n    return; // default schema always exists; skip creation\n}","typeGuard":null,"tryCatchPattern":"try {\n    metadata.createSchema(...);\n} catch (PrestoException e) {\n    if (e.getErrorCode().getCode() == StandardErrorCode.ALREADY_EXISTS.getCode()) {\n        // treat as no-op for idempotent provisioning\n    }\n}","preventionTips":["Never call createSchema for 'default' under table-name-convention emulation","Make provisioning scripts idempotent by treating ALREADY_EXISTS as success","Use CREATE SCHEMA IF NOT EXISTS semantics where available"],"tags":["presto","kudu","schema","already-exists"],"backgroundTag":"schema-already-exists","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"}