apache/beam · error · SqlUtil.newContextException

Database ' ' does not exist.

Error message

Database '%s' does not exist.

What it means

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.

Solutions

  1. Add IF EXISTS: `DROP DATABASE IF EXISTS name`.
  2. Confirm the database name spelling/case.
  3. Check the catalog actually contains the database before dropping.
  4. Make teardown scripts idempotent with IF EXISTS.

Example fix

// before
DROP DATABASE staging;
// after
DROP DATABASE IF EXISTS staging;
Defensive patterns

Strategy: validation

Validate before calling

// Java: only drop when present
if (catalog.databaseExists(name)) {
  stmt.execute("DROP DATABASE " + name);
}

Try / catch

// Java
catch (SQLException e) {
  if (e.getMessage().matches("(?s).*Database '.*' does not exist\\.")) {
    LOG.info("nothing to drop");
  } else throw e;
}

Prevention

When it happens

Trigger: Executing `DROP DATABASE name` where the catalog reports the database does not exist and the statement lacks IF EXISTS.

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/a3d858b276ffc0d3. Report an issue: GitHub.

Appendix: source

Thrown at sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/CatalogSchema.java:153

      return;
    }

    catalog.useDatabase(name);
    LOG.info("Switched to database '{}'.", name);
  }

  public void dropDatabase(SqlIdentifier identifier, boolean cascade, boolean ifExists) {
    String name = SqlDdlNodes.name(identifier);
    try {
      LOG.info("Dropping database '{}'", name);
      boolean dropped = catalog.dropDatabase(name, cascade);

      if (dropped) {
        LOG.info("Successfully dropped database '{}'", name);
      } else if (ifExists) {
        LOG.info("Database '{}' does not exist.", name);
      } else {
        throw SqlUtil.newContextException(
            identifier.getParserPosition(),
            RESOURCE.internal(String.format("Database '%s' does not exist.", name)));
      }
    } catch (Exception e) {
      throw SqlUtil.newContextException(
          identifier.getParserPosition(),
          RESOURCE.internal(
              format("Encountered an error when dropping database '%s': %s", name, e)));
    }

    subSchemas.remove(name);
  }

  @Override
  public @Nullable Table getTable(String s) {
    @Nullable BeamCalciteSchema beamCalciteSchema = currentDatabase();
    return beamCalciteSchema != null ? beamCalciteSchema.getTable(s) : null;
  }

View on GitHub (pinned to 12126d8942)