{"record":{"id":"ecb721e00bf86c85","repo":"OtterMind/Chat2DB","slug":"presto-schema-name-is-required-when-catalog-name-i","errorCode":null,"errorMessage":"Presto schema name is required when catalog name is provided","messagePattern":"Presto schema name is required when catalog name is provided","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"chat2db-community-server/chat2db-community-plugins/chat2db-community-presto/src/main/java/ai/chat2db/plugin/presto/PrestoMetaData.java","lineNumber":33,"sourceCode":"        String sql = buildShowCreateTableSql(identifierProcessor, databaseName, schemaName, tableName);\n        return DefaultSQLExecutor.getInstance().execute(connection, sql, resultSet -> {\n            if (resultSet.next()) {\n                return resultSet.getString(1);\n            }\n            return null;\n        });\n    }\n\n    static String buildShowCreateTableSql(ISQLIdentifierProcessor identifierProcessor, String catalogName,\n                                          String schemaName, String tableName) {\n        if (isBlank(tableName)) {\n            throw new IllegalArgumentException(\"Presto table name must not be blank\");\n        }\n\n        boolean hasCatalog = !isBlank(catalogName);\n        boolean hasSchema = !isBlank(schemaName);\n        if (hasCatalog && !hasSchema) {\n            throw new IllegalArgumentException(\"Presto schema name is required when catalog name is provided\");\n        }\n\n        StringBuilder qualifiedName = new StringBuilder();\n        if (hasCatalog) {\n            qualifiedName.append(identifierProcessor.quoteIdentifierAlways(catalogName)).append('.');\n        }\n        if (hasSchema) {\n            qualifiedName.append(identifierProcessor.quoteIdentifierAlways(schemaName)).append('.');\n        }\n        qualifiedName.append(identifierProcessor.quoteIdentifierAlways(tableName));\n        return \"SHOW CREATE TABLE \" + qualifiedName;\n    }\n\n    private static boolean isBlank(String value) {\n        return value == null || value.isBlank();\n    }\n}\n","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-plugins/chat2db-community-presto/src/main/java/ai/chat2db/plugin/presto/PrestoMetaData.java#L15-L51","documentation":"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.","triggerScenarios":"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\").","commonSituations":"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.","solutions":["Pass a non-blank schema name whenever a catalog name is provided","Use the default schema for the catalog if the user has not selected one (e.g., \"default\" for hive)","Skip the catalog prefix entirely if no schema is available, calling with a blank catalog"],"exampleFix":"// before — catalog without schema\nmetaData.tableDDL(conn, \"hive\", null, \"my_table\");\n\n// after — provide the schema\nmetaData.tableDDL(conn, \"hive\", \"default\", \"my_table\");","handlingStrategy":"validation","validationCode":"boolean hasCatalog = catalogName != null && !catalogName.isBlank();\nboolean hasSchema = schemaName != null && !schemaName.isBlank();\nif (hasCatalog && !hasSchema) {\n    schemaName = \"default\"; // or throw\n}\nString sql = PrestoMetaData.buildShowCreateTableSql(processor, catalogName, schemaName, tableName);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always provide a schema name when a catalog name is set","Use the catalog's default schema if the user has not selected one","Omit the catalog prefix if no schema context is available"],"tags":["presto","metadata","validation","identifier"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}