apache/beam · error · SqlUtil.newContextException

Attempting to drop a table using unexpected Calcite Schema…

Error message

Attempting to drop a table using unexpected Calcite Schema of type %s

What it means

DROP TABLE expects the resolved schema to be catalog-managed (CatalogManagerSchema yielding a BeamCalciteSchema) or directly a BeamCalciteSchema. Any other schema type cannot host Beam tables to drop, so execute() raises this internal error with the actual schema class.

Solutions

  1. Target only schemas created via Beam's catalog/BeamCalciteSchema APIs
  2. Use the default Beam catalog for DDL operations
  3. Wrap custom schemas through Beam's schema provider instead of raw CalciteSchema
  4. Double-check the table's qualified name binds to a Beam-managed schema
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(schema instanceof BeamCalciteSchema) && !(schema instanceof CatalogManagerSchema)) {
  throw new IllegalArgumentException("DROP TABLE requires a Beam-managed schema");
}

Type guard

boolean isBeamSchema(Schema s) {
  return s instanceof BeamCalciteSchema || s instanceof CatalogManagerSchema;
}

Prevention

When it happens

Trigger: `DROP TABLE <name>` resolving to a plain/custom Calcite Schema implementation rather than a BeamCalciteSchema or catalog-managed schema.

Common situations: Embedding Beam SQL with hand-registered non-Beam schemas; pointing the DROP at a foreign Calcite adapter's schema; test harnesses with plain Calcite schemas.

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/8746e3a1807e41f2. Report an issue: GitHub.

Appendix: source

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

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

    BeamCalciteSchema beamCalciteSchema;
    if (schema instanceof CatalogManagerSchema) {
      CatalogManagerSchema catalogManagerSchema = (CatalogManagerSchema) schema;
      CatalogSchema catalogSchema =
          pathOverride.catalog() != null
              ? catalogManagerSchema.getCatalogSchema(pathOverride)
              : catalogManagerSchema.getCurrentCatalogSchema();
      beamCalciteSchema = catalogSchema.getDatabaseSchema(pathOverride);
    } else if (schema instanceof BeamCalciteSchema) {
      beamCalciteSchema = (BeamCalciteSchema) schema;
    } else {
      throw SqlUtil.newContextException(
          name.getParserPosition(),
          RESOURCE.internal(
              "Attempting to drop a table using unexpected Calcite Schema of type "
                  + schema.getClass()));
    }

    if (beamCalciteSchema.getTable(pair.right) == null) {
      // Table does not exist.
      if (!ifExists) {
        // They did not specify IF EXISTS, so give error.
        throw SqlUtil.newContextException(
            name.getParserPosition(), RESOURCE.tableNotFound(name.toString()));
      }
      return;
    }

    beamCalciteSchema.getTableProvider().dropTable(pair.right);
  }

View on GitHub (pinned to 12126d8942)