{"record":{"id":"fc76dde395cdfc23","repo":"apache/beam","slug":"unable-to-drop-active-catalog-s-please-switch-to-another","errorCode":null,"errorMessage":"Unable to drop active catalog '%s'. Please switch to another catalog first.","messagePattern":"Unable to drop active catalog '(.+?)'\\. Please switch to another catalog first\\.","errorType":"validation","errorClass":"SqlUtil.newContextException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/CatalogManagerSchema.java","lineNumber":131,"sourceCode":"\n    catalogManager.useCatalog(name);\n    LOG.info(\"Switched to catalog '{}' (type: {})\", name, catalogManager.currentCatalog().type());\n  }\n\n  public void dropCatalog(SqlIdentifier identifier, boolean ifExists) {\n    String name = SqlDdlNodes.name(identifier);\n    if (catalogManager.getCatalog(name) == null) {\n      if (!ifExists) {\n        throw SqlUtil.newContextException(\n            identifier.getParserPosition(),\n            RESOURCE.internal(String.format(\"Cannot drop catalog: '%s' not found.\", name)));\n      }\n      LOG.info(\"Ignoring 'DROP CATALOG` call for non-existent catalog: {}\", name);\n      return;\n    }\n\n    if (catalogManager.currentCatalog().name().equals(name)) {\n      throw SqlUtil.newContextException(\n          identifier.getParserPosition(),\n          RESOURCE.internal(\n              String.format(\n                  \"Unable to drop active catalog '%s'. Please switch to another catalog first.\",\n                  name)));\n    }\n\n    catalogManager.dropCatalog(name);\n    LOG.info(\"Successfully dropped catalog '{}'\", name);\n    catalogSubSchemas.remove(name);\n  }\n\n  // A BeamCalciteSchema may be used to interact with multiple TableProviders.\n  // If such a TableProvider is not registered in the BeamCalciteSchema, this method\n  // will attempt to do so.\n  public void maybeRegisterProvider(TableName path, String type) {\n    type = type.toLowerCase();\n    CatalogSchema catalogSchema = getCatalogSchema(path);","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/CatalogManagerSchema.java#L113-L149","documentation":"Raised by DROP CATALOG when attempting to drop the catalog that is currently in use (the session's active catalog). Beam refuses to avoid leaving the session without a current catalog, and throws a Calcite context exception instructing the user to switch first.","triggerScenarios":"Executing `DROP CATALOG name` while catalogManager.currentCatalog().name().equals(name), i.e. the session's active catalog equals the one being dropped.","commonSituations":"Cleanup scripts that drop all catalogs while still attached to one; interactive sessions forgetting a prior `USE CATALOG default` switch.","solutions":["Switch to another catalog first: USE CATALOG <other-catalog>; then re-run the DROP","Order teardown scripts so the active catalog is dropped last","Check the current catalog before issuing DROP CATALOG"],"exampleFix":"// before\nDROP CATALOG my_catalog;  -- my_catalog is active\n// after\nUSE CATALOG default_catalog;\nDROP CATALOG my_catalog;","handlingStrategy":"try-catch","validationCode":"// switch away from the active catalog before dropping\nstmt.execute(\"USE CATALOG default_catalog\");\nstmt.execute(\"DROP CATALOG \" + name);","typeGuard":null,"tryCatchPattern":"try {\n    stmt.execute(\"DROP CATALOG \" + name);\n} catch (Exception e) {\n    if (e.getMessage().contains(\"active catalog\")) {\n        stmt.execute(\"USE CATALOG default_catalog\");\n        stmt.execute(\"DROP CATALOG \" + name);\n    }\n}","preventionTips":["Always switch to a default catalog before cleanup","Design teardown order: use other catalog first, drop active last"],"tags":["sql","beam-sql","ddl","catalog"],"backgroundTag":"invalid-state-transition","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"}