apache/beam · error · SqlUtil.newContextException

Attempting to drop database

Error message

Attempting to drop database '%s' with unexpected Calcite Schema of type %s

What it means

DROP DATABASE requires the resolved schema to be a CatalogManagerSchema; any other Calcite Schema type triggers this internal error in execute(). Only catalog-managed schemas track databases that can be dropped.

Solutions

  1. Ensure the target database was created with CREATE DATABASE under a CatalogManagerSchema
  2. Enable/use a session with catalog management enabled
  3. Verify the database name resolution (typos, wrong catalog prefix)
  4. Use DROP SCHEMA semantics appropriate to your setup if not using catalogs
Defensive patterns

Strategy: validation

Validate before calling

if (!(schema instanceof CatalogManagerSchema)) {
  throw new IllegalStateException("DROP DATABASE requires a catalog-managed session");
}

Type guard

boolean supportsDatabases(Schema s) { return s instanceof CatalogManagerSchema; }

Prevention

When it happens

Trigger: `DROP DATABASE <name>` executed where the name resolves to a non-CatalogManagerSchema — e.g. in a session without the catalog manager, or when the identifier resolves to a plain schema.

Common situations: Running catalog DDL in a default Beam SQL connection without multi-catalog support; typos in the database name; scripts shared between catalog-enabled and non-catalog environments.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/parser/SqlDropDatabase.java:76

    writer.keyword(getOperator().getName());
    if (ifExists) {
      writer.keyword("IF EXISTS");
    }
    databaseName.unparse(writer, leftPrec, rightPrec);
    if (cascade) {
      writer.keyword("CASCADE");
    } else {
      writer.keyword("RESTRICT");
    }
  }

  @Override
  public void execute(CalcitePrepare.Context context) {
    final Pair<CalciteSchema, String> pair = SqlDdlNodes.schema(context, true, databaseName);
    Schema schema = pair.left.schema;

    if (!(schema instanceof CatalogManagerSchema)) {
      throw SqlUtil.newContextException(
          databaseName.getParserPosition(),
          RESOURCE.internal(
              "Attempting to drop database '"
                  + databaseName
                  + "' with unexpected Calcite Schema of type "
                  + schema.getClass()));
    }

    List<String> components = Lists.newArrayList(Splitter.on(".").split(databaseName.toString()));
    TableName pathOverride = TableName.create(components, "");
    CatalogManagerSchema catalogManagerSchema = (CatalogManagerSchema) schema;
    CatalogSchema catalogSchema =
        pathOverride.catalog() != null
            ? catalogManagerSchema.getCatalogSchema(pathOverride)
            : catalogManagerSchema.getCurrentCatalogSchema();
    catalogSchema.dropDatabase(databaseName, cascade, ifExists);
  }

View on GitHub (pinned to 12126d8942)