{"record":{"id":"a7e4cc1d10aaf816","repo":"apache/beam","slug":"attempting-to-drop-database-s-with-unexpected-calcite-schema","errorCode":null,"errorMessage":"Attempting to drop database '%s' with unexpected Calcite Schema of type %s","messagePattern":"Attempting to drop database '(.+?)' with unexpected Calcite Schema of type (.+?)","errorType":"validation","errorClass":"SqlUtil.newContextException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/parser/SqlDropDatabase.java","lineNumber":76,"sourceCode":"    writer.keyword(getOperator().getName());\n    if (ifExists) {\n      writer.keyword(\"IF EXISTS\");\n    }\n    databaseName.unparse(writer, leftPrec, rightPrec);\n    if (cascade) {\n      writer.keyword(\"CASCADE\");\n    } else {\n      writer.keyword(\"RESTRICT\");\n    }\n  }\n\n  @Override\n  public void execute(CalcitePrepare.Context context) {\n    final Pair<CalciteSchema, String> pair = SqlDdlNodes.schema(context, true, databaseName);\n    Schema schema = pair.left.schema;\n\n    if (!(schema instanceof CatalogManagerSchema)) {\n      throw SqlUtil.newContextException(\n          databaseName.getParserPosition(),\n          RESOURCE.internal(\n              \"Attempting to drop database '\"\n                  + databaseName\n                  + \"' with unexpected Calcite Schema of type \"\n                  + schema.getClass()));\n    }\n\n    List<String> components = Lists.newArrayList(Splitter.on(\".\").split(databaseName.toString()));\n    TableName pathOverride = TableName.create(components, \"\");\n    CatalogManagerSchema catalogManagerSchema = (CatalogManagerSchema) schema;\n    CatalogSchema catalogSchema =\n        pathOverride.catalog() != null\n            ? catalogManagerSchema.getCatalogSchema(pathOverride)\n            : catalogManagerSchema.getCurrentCatalogSchema();\n    catalogSchema.dropDatabase(databaseName, cascade, ifExists);\n  }\n","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/parser/SqlDropDatabase.java#L58-L94","documentation":"DROP DATABASE requires the resolved schema to be a CatalogManagerSchema; any other Calcite Schema type triggers this internal error in execute(). Only catalog-managed schemas track databases that can be dropped.","triggerScenarios":"`DROP DATABASE <name>` executed where the name resolves to a non-CatalogManagerSchema — e.g. in a session without the catalog manager, or when the identifier resolves to a plain schema.","commonSituations":"Running catalog DDL in a default Beam SQL connection without multi-catalog support; typos in the database name; scripts shared between catalog-enabled and non-catalog environments.","solutions":["Ensure the target database was created with CREATE DATABASE under a CatalogManagerSchema","Enable/use a session with catalog management enabled","Verify the database name resolution (typos, wrong catalog prefix)","Use DROP SCHEMA semantics appropriate to your setup if not using catalogs"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (!(schema instanceof CatalogManagerSchema)) {\n  throw new IllegalStateException(\"DROP DATABASE requires a catalog-managed session\");\n}","typeGuard":"boolean supportsDatabases(Schema s) { return s instanceof CatalogManagerSchema; }","tryCatchPattern":null,"preventionTips":["Verify catalog support is enabled before running database DDL","Check identifier resolution/typos","Keep catalog DDL in catalog-enabled environments only"],"tags":["sql","ddl","database","internal-error"],"backgroundTag":"internal-invariant-violation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}