prestodb/presto · error · SchemaAlreadyExistsException

ALREADY_EXISTS

ALREADY_EXISTS

Error message

Schema already exists: '${schemaName}'

What it means

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).

Source

Thrown at presto-kudu/src/main/java/com/facebook/presto/kudu/schema/SchemaEmulationByTableNameConvention.java:61

public class SchemaEmulationByTableNameConvention
        implements SchemaEmulation
{
    private final String commonPrefix;
    private final String rawSchemasTableName;
    private KuduTable rawSchemasTable;

    public SchemaEmulationByTableNameConvention(String commonPrefix)
    {
        this.commonPrefix = commonPrefix;
        this.rawSchemasTableName = commonPrefix + "$schemas";
    }

    @Override
    public void createSchema(KuduClient client, String schemaName)
    {
        if (DEFAULT_SCHEMA.equals(schemaName)) {
            throw new SchemaAlreadyExistsException(schemaName);
        }
        else {
            try {
                KuduTable schemasTable = getSchemasTable(client);
                KuduSession session = client.newSession();
                try {
                    Upsert upsert = schemasTable.newUpsert();
                    upsert.getRow().addString(0, schemaName);
                    session.apply(upsert);
                }
                finally {
                    session.close();
                }
            }
            catch (KuduException e) {
                throw new PrestoException(GENERIC_INTERNAL_ERROR, e);
            }
        }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Skip creating 'default'; it always exists under this emulation mode
  2. Guard creation so the default schema is never passed to createSchema
  3. If you need real distinct schemas, switch emulation mode or use a connector with native schema support

Example fix

// before
connector.createSchema(client, schemaName); // schemaName could be "default"
// after
if (!"default".equals(schemaName)) {
    connector.createSchema(client, schemaName);
}
Defensive patterns

Strategy: validation

Validate before calling

if ("default".equals(schemaName)) {
    return; // default schema always exists; skip creation
}

Try / catch

try {
    metadata.createSchema(...);
} catch (PrestoException e) {
    if (e.getErrorCode().getCode() == StandardErrorCode.ALREADY_EXISTS.getCode()) {
        // treat as no-op for idempotent provisioning
    }
}

Prevention

When it happens

Trigger: Calling createSchema('default') — e.g. CREATE SCHEMA default — on a Kudu catalog using schema emulation by table name convention.

Common situations: 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.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/c39c06574fd10382. Report an issue: GitHub.