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

Thrown by SqlAlterTable.execute (DROP TABLE path) when the resolved schema is neither a CatalogManagerSchema nor a BeamCalciteSchema. Dropping a table requires the schema to be one of Beam's supported schema types; any other Calcite Schema implementation is rejected.

Solutions

  1. Ensure the target schema is a Beam schema (BeamCalciteSchema or CatalogManagerSchema).
  2. Qualify the table name with a Beam-managed database/catalog path.
  3. Register the table within a Beam catalog rather than a raw Calcite schema.
  4. Check the statement's name resolution (catalog.database/table) for typos.

Example fix

// before
ALTER TABLE foreignSchema.mytable DROP COLUMN c; -- schema is a foreign Calcite Schema
// after
ALTER TABLE mydb.mytable DROP COLUMN c; -- mydb resolves to a BeamCalciteSchema
Defensive patterns

Strategy: type-guard

Validate before calling

// Java: confirm the resolved schema is Beam-managed before ALTER TABLE
Schema schema = pair.left.schema;
boolean ok = schema instanceof CatalogManagerSchema || schema instanceof BeamCalciteSchema;
if (!ok) throw new IllegalStateException("unsupported schema: " + schema.getClass());

Type guard

boolean isBeamSchema(Schema s) {
  return s instanceof org.apache.beam.sdk.extensions.sql.impl.BeamCalciteSchema
      || s instanceof org.apache.beam.sdk.extensions.sql.impl.CatalogManagerSchema;
}

Prevention

When it happens

Trigger: Executing `ALTER TABLE name DROP ...` (or the drop branch of SqlAlterTable) where pair.left.schema's concrete class is neither CatalogManagerSchema nor BeamCalciteSchema.

Common situations: Pointing the DDL at a third-party/foreign Calcite schema, running the statement against a schema registered by another framework, or referencing the wrong database/catalog path.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

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

  @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.
      throw SqlUtil.newContextException(
          name.getParserPosition(), RESOURCE.tableNotFound(name.toString()));
    }

    Map<String, String> setPropsMap = SqlDdlNodes.getStringMap(setProps);
    List<String> resetPropsList = SqlDdlNodes.getStringList(resetProps);
    List<String> columnsToDropList = SqlDdlNodes.getStringList(columnsToDrop);
    List<String> partitionsToAddList = SqlDdlNodes.getStringList(partitionsToAdd);
    List<String> partitionsToDropList = SqlDdlNodes.getStringList(partitionsToDrop);

View on GitHub (pinned to 12126d8942)