{"record":{"id":"aec6080e5c5b65c0","repo":"apache/beam","slug":"cannot-use-catalog-s-not-found","errorCode":null,"errorMessage":"Cannot use catalog: '%s' not found.","messagePattern":"Cannot use 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":104,"sourceCode":"        throw SqlUtil.newContextException(\n            catalogIdentifier.getParserPosition(),\n            RESOURCE.internal(String.format(\"Catalog '%s' already exists.\", name)));\n      } else {\n        LOG.info(\"Catalog '{}' already exists\", name);\n        return;\n      }\n    }\n\n    catalogManager.createCatalog(name, type, properties);\n    CatalogSchema catalogSchema =\n        new CatalogSchema(connection, checkStateNotNull(catalogManager.getCatalog(name)));\n    catalogSubSchemas.put(name, catalogSchema);\n  }\n\n  public void useCatalog(SqlIdentifier catalogIdentifier) {\n    String name = catalogIdentifier.toString();\n    if (catalogManager.getCatalog(catalogIdentifier.toString()) == null) {\n      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(","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/CatalogManagerSchema.java#L86-L122","documentation":"Context exception thrown by CatalogManagerSchema.useCatalog when the USE CATALOG statement names a catalog that is not registered in the catalog manager. The SQL parser accepted the identifier, but at resolution time no catalog of that name exists in this session, so the statement is rejected with parser-position context pointing at the identifier.","triggerScenarios":"Executing `USE CATALOG name` where catalogManager.getCatalog(name) returns null, typically a typo or a catalog that was never created or was dropped.","commonSituations":"Typo in catalog name; running scripts against a fresh environment where CREATE CATALOG was not executed; catalog dropped in an earlier statement of the same session.","solutions":["Create the catalog first with CREATE CATALOG IF NOT EXISTS name ...","Verify available catalog names and correct the spelling","Ensure prior DDL statements in the script succeeded before USE CATALOG runs"],"exampleFix":"// before\nUSE CATALOG my_catlog;\n// after\nCREATE CATALOG IF NOT EXISTS my_catalog TYPE ...;\nUSE CATALOG my_catalog;","handlingStrategy":"try-catch","validationCode":"// ensure the catalog exists before USE\nstmt.execute(\"CREATE CATALOG IF NOT EXISTS \" + name + \" ...\");","typeGuard":null,"tryCatchPattern":"try {\n    stmt.execute(\"USE CATALOG \" + name);\n} catch (Exception e) {\n    if (e.getMessage().contains(\"not found\")) { stmt.execute(\"CREATE CATALOG IF NOT EXISTS \" + name + \" ...\"); }\n}","preventionTips":["Always create catalogs before switching to them","Verify catalog name spelling against registered catalogs"],"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"}