{"record":{"id":"ca7d01303773020a","repo":"apache/beam","slug":"cannot-drop-catalog-s-not-found","errorCode":null,"errorMessage":"Cannot drop catalog: '%s' not found.","messagePattern":"Cannot drop catalog: '(.+?)' not found\\.","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":122,"sourceCode":"      throw SqlUtil.newContextException(\n          catalogIdentifier.getParserPosition(),\n          RESOURCE.internal(String.format(\"Cannot use catalog: '%s' not found.\", name)));\n    }\n\n    if (catalogManager.currentCatalog().name().equals(name)) {\n      LOG.info(\"Catalog '{}' is already in use.\", name);\n      return;\n    }\n\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);","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/CatalogManagerSchema.java#L104-L140","documentation":"Raised by DROP CATALOG when the target catalog does not exist and IF EXISTS was not specified. Beam throws a Calcite context exception at the statement's parser position; with IF EXISTS the drop is silently ignored.","triggerScenarios":"Executing `DROP CATALOG name` where catalogManager.getCatalog(name) == null and ifExists=false.","commonSituations":"Teardown scripts assuming catalogs exist; double-execution of DROP scripts; dropping a catalog that was created under a different name.","solutions":["Use DROP CATALOG IF EXISTS name to make the statement idempotent","Verify the catalog name with the available catalogs before dropping","Skip the statement if the catalog was already removed"],"exampleFix":"// before\nDROP CATALOG my_catalog;\n// after\nDROP CATALOG IF EXISTS my_catalog;","handlingStrategy":"try-catch","validationCode":"// make idempotent at the source\nString sql = \"DROP CATALOG IF EXISTS \" + name;","typeGuard":null,"tryCatchPattern":"try {\n    stmt.execute(\"DROP CATALOG \" + name);\n} catch (Exception e) {\n    if (e.getMessage().contains(\"not found\")) { /* already dropped; ignore */ }\n}","preventionTips":["Use IF EXISTS in all teardown scripts","Do not assume catalog existence across environments"],"tags":["sql","beam-sql","ddl","catalog"],"backgroundTag":"resource-not-found","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"}