OtterMind/Chat2DB · error · IllegalArgumentException

Presto schema name is required when catalog name is provided

Error message

Presto schema name is required when catalog name is provided

What it means

Thrown by PrestoMetaData.buildShowCreateTableSql when a catalog name is provided but no schema name. In Presto/Trino, a fully-qualified table reference is catalog.schema.table — providing a catalog without a schema produces an ambiguous or invalid identifier. The check at line 32 tests hasCatalog && !hasSchema.

Source

Thrown at chat2db-community-server/chat2db-community-plugins/chat2db-community-presto/src/main/java/ai/chat2db/plugin/presto/PrestoMetaData.java:33

        String sql = buildShowCreateTableSql(identifierProcessor, databaseName, schemaName, tableName);
        return DefaultSQLExecutor.getInstance().execute(connection, sql, resultSet -> {
            if (resultSet.next()) {
                return resultSet.getString(1);
            }
            return null;
        });
    }

    static String buildShowCreateTableSql(ISQLIdentifierProcessor identifierProcessor, String catalogName,
                                          String schemaName, String tableName) {
        if (isBlank(tableName)) {
            throw new IllegalArgumentException("Presto table name must not be blank");
        }

        boolean hasCatalog = !isBlank(catalogName);
        boolean hasSchema = !isBlank(schemaName);
        if (hasCatalog && !hasSchema) {
            throw new IllegalArgumentException("Presto schema name is required when catalog name is provided");
        }

        StringBuilder qualifiedName = new StringBuilder();
        if (hasCatalog) {
            qualifiedName.append(identifierProcessor.quoteIdentifierAlways(catalogName)).append('.');
        }
        if (hasSchema) {
            qualifiedName.append(identifierProcessor.quoteIdentifierAlways(schemaName)).append('.');
        }
        qualifiedName.append(identifierProcessor.quoteIdentifierAlways(tableName));
        return "SHOW CREATE TABLE " + qualifiedName;
    }

    private static boolean isBlank(String value) {
        return value == null || value.isBlank();
    }
}

View on GitHub (pinned to 5ee1e990e7)

Solutions

  1. Pass a non-blank schema name whenever a catalog name is provided
  2. Use the default schema for the catalog if the user has not selected one (e.g., "default" for hive)
  3. Skip the catalog prefix entirely if no schema is available, calling with a blank catalog

Example fix

// before — catalog without schema
metaData.tableDDL(conn, "hive", null, "my_table");

// after — provide the schema
metaData.tableDDL(conn, "hive", "default", "my_table");
Defensive patterns

Strategy: validation

Validate before calling

boolean hasCatalog = catalogName != null && !catalogName.isBlank();
boolean hasSchema = schemaName != null && !schemaName.isBlank();
if (hasCatalog && !hasSchema) {
    schemaName = "default"; // or throw
}
String sql = PrestoMetaData.buildShowCreateTableSql(processor, catalogName, schemaName, tableName);

Prevention

When it happens

Trigger: Calling PrestoMetaData.tableDDL with a non-blank catalog/databaseName but a blank or null schemaName. For example: tableDDL(conn, "hive", null, "my_table") or tableDDL(conn, "hive", "", "my_table").

Common situations: A datasource configured with a catalog but the schema context was not resolved; a UI state where the database/catalog is set but the schema dropdown was cleared; programmatic callers that pass a catalog from one source but omit the schema.

Related errors


AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14). Data as JSON: /api/errors/ecb721e00bf86c85. Report an issue: GitHub.