{"record":{"id":"2a6e4ac4405c23b7","repo":"apache/beam","slug":"catalog-s-already-exists","errorCode":null,"errorMessage":"Catalog '%s' already exists.","messagePattern":"Catalog '(.+?)' already exists\\.","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":86,"sourceCode":"\n  @VisibleForTesting\n  public JdbcConnection connection() {\n    return connection;\n  }\n\n  public void createCatalog(\n      SqlIdentifier catalogIdentifier,\n      String type,\n      Map<String, String> properties,\n      boolean replace,\n      boolean ifNotExists) {\n    String name = SqlDdlNodes.name(catalogIdentifier);\n    if (catalogManager.getCatalog(name) != null) {\n      if (replace) {\n        LOG.info(\"Replacing existing catalog '{}'\", name);\n        catalogManager.dropCatalog(name);\n      } else if (!ifNotExists) {\n        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(","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/CatalogManagerSchema.java#L68-L104","documentation":"Thrown during CREATE CATALOG (or CREATE CATALOG OR REPLACE absent) when a catalog with the given name already exists in the CatalogManager. Beam's SQL shell raises it as a Calcite context exception at the statement's parser position. Use IF NOT EXISTS or OR REPLACE to allow the statement to proceed.","triggerScenarios":"Executing `CREATE CATALOG name ...` where catalogManager.getCatalog(name) != null, replace=false, and ifNotExists=false.","commonSituations":"Re-running DDL setup scripts that create catalogs idempotently without IF NOT EXISTS; Beam SQL shell interactive sessions repeating an earlier CREATE CATALOG.","solutions":["Add IF NOT EXISTS: CREATE CATALOG IF NOT EXISTS name ...","Use CREATE OR REPLACE CATALOG name ... to overwrite the existing catalog","Pick a different catalog name, or DROP CATALOG the existing one first"],"exampleFix":"// before\nCREATE CATALOG my_catalog TYPE ... \n// after\nCREATE CATALOG IF NOT EXISTS my_catalog TYPE ...","handlingStrategy":"try-catch","validationCode":"// check before running DDL\n// SELECT/inspect existing catalogs; skip CREATE if 'my_catalog' already registered","typeGuard":null,"tryCatchPattern":"try {\n    stmt.execute(\"CREATE CATALOG my_catalog ...\");\n} catch (Exception e) {\n    if (e.getMessage().contains(\"already exists\")) { /* skip or replace */ }\n}","preventionTips":["Use IF NOT EXISTS or OR REPLACE in idempotent setup scripts","Track which catalogs a session has already created"],"tags":["sql","beam-sql","ddl","catalog"],"backgroundTag":"file-already-exists","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"}