{"record":{"id":"a3d858b276ffc0d3","repo":"apache/beam","slug":"database-s-does-not-exist","errorCode":null,"errorMessage":"Database '%s' does not exist.","messagePattern":"Database '(.+?)' does not exist\\.","errorType":"validation","errorClass":"SqlUtil.newContextException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/CatalogSchema.java","lineNumber":153,"sourceCode":"      return;\n    }\n\n    catalog.useDatabase(name);\n    LOG.info(\"Switched to database '{}'.\", name);\n  }\n\n  public void dropDatabase(SqlIdentifier identifier, boolean cascade, boolean ifExists) {\n    String name = SqlDdlNodes.name(identifier);\n    try {\n      LOG.info(\"Dropping database '{}'\", name);\n      boolean dropped = catalog.dropDatabase(name, cascade);\n\n      if (dropped) {\n        LOG.info(\"Successfully dropped database '{}'\", name);\n      } else if (ifExists) {\n        LOG.info(\"Database '{}' does not exist.\", name);\n      } else {\n        throw SqlUtil.newContextException(\n            identifier.getParserPosition(),\n            RESOURCE.internal(String.format(\"Database '%s' does not exist.\", name)));\n      }\n    } catch (Exception e) {\n      throw SqlUtil.newContextException(\n          identifier.getParserPosition(),\n          RESOURCE.internal(\n              format(\"Encountered an error when dropping database '%s': %s\", name, e)));\n    }\n\n    subSchemas.remove(name);\n  }\n\n  @Override\n  public @Nullable Table getTable(String s) {\n    @Nullable BeamCalciteSchema beamCalciteSchema = currentDatabase();\n    return beamCalciteSchema != null ? beamCalciteSchema.getTable(s) : null;\n  }","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/CatalogSchema.java#L135-L171","documentation":"Thrown by CatalogSchema.dropDatabase when DROP DATABASE (without IF EXISTS) targets a database the catalog does not have. The catalog's drop returned no success and ifExists was false, so a context exception is raised at the statement's parser position.","triggerScenarios":"Executing `DROP DATABASE name` where the catalog reports the database does not exist and the statement lacks IF EXISTS.","commonSituations":"Cleanup/teardown scripts run against an environment where the database was already dropped, typos in the name, or running DDL against a fresh catalog in CI.","solutions":["Add IF EXISTS: `DROP DATABASE IF EXISTS name`.","Confirm the database name spelling/case.","Check the catalog actually contains the database before dropping.","Make teardown scripts idempotent with IF EXISTS."],"exampleFix":"// before\nDROP DATABASE staging;\n// after\nDROP DATABASE IF EXISTS staging;","handlingStrategy":"validation","validationCode":"// Java: only drop when present\nif (catalog.databaseExists(name)) {\n  stmt.execute(\"DROP DATABASE \" + name);\n}","typeGuard":null,"tryCatchPattern":"// Java\ncatch (SQLException e) {\n  if (e.getMessage().matches(\"(?s).*Database '.*' does not exist\\\\.\")) {\n    LOG.info(\"nothing to drop\");\n  } else throw e;\n}","preventionTips":["Use DROP DATABASE IF EXISTS in all teardown scripts.","Keep create/drop scripts symmetric and idempotent.","Confirm the target catalog before dropping.","Watch for name typos and case mismatches."],"tags":["sql","ddl","database","not-found"],"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"}