apache/beam · error · SqlUtil.newContextException

Attempting to create database

Error message

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

What it means

Thrown by SqlCreateDatabase.execute when the schema resolved for the database name is not a CatalogManagerSchema. CREATE DATABASE must run against Beam's catalog manager; other Calcite Schema implementations are rejected with this type-mismatch message.

Solutions

  1. Use a top-level (or correctly catalog-qualified) database name that resolves to CatalogManagerSchema.
  2. Check the dot-separated name: with two components, the second-to-last must be a registered catalog.
  3. Ensure the session/Calcite connection is configured with Beam's catalog manager schema.
  4. Use CREATE CATALOG first if a new catalog is intended.

Example fix

// before
CREATE DATABASE wrongcatalog.mydb; -- resolves to non-manager schema
// after
CREATE DATABASE mycatalog.mydb;
Defensive patterns

Strategy: validation

Validate before calling

// Java: resolve and check schema type before CREATE DATABASE
Pair<CalciteSchema, String> pair = SqlDdlNodes.schema(context, true, databaseName);
if (!(pair.left.schema instanceof CatalogManagerSchema)) {
  throw new IllegalStateException("CREATE DATABASE must resolve to a managed catalog");
}

Type guard

boolean resolvesToManagedCatalog(String dottedName, CalciteCatalogReader reader) {
  return SqlDdlNodes.schema(null, true, /* name */ null) != null; // resolve then check instanceof CatalogManagerSchema
}

Prevention

When it happens

Trigger: Executing `CREATE DATABASE name ...` where the resolved schema (pair.left.schema from SqlDdlNodes.schema(context, true, databaseName)) is not a CatalogManagerSchema.

Common situations: Qualifying the database name with a catalog path that resolves into a non-manager schema, running DDL in a session without the catalog manager, or a typo producing a database name with the wrong number of dot-separated components.

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/8885e2f082d333cf. Report an issue: GitHub.

Appendix: source

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

    }
    writer.keyword("DATABASE");
    if (ifNotExists) {
      writer.keyword("IF NOT EXISTS");
    }
    databaseName.unparse(writer, leftPrec, rightPrec);
  }

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

    List<String> components = Lists.newArrayList(Splitter.on('.').split(databaseName.toString()));
    @Nullable String catalogName =
        components.size() > 1 ? components.get(components.size() - 2) : null;

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

    CatalogManagerSchema catalogManagerSchema = (CatalogManagerSchema) schema;
    CatalogSchema catalogSchema = catalogManagerSchema.getCurrentCatalogSchema();
    // override if a catalog name is present
    if (catalogName != null) {
      Schema overridden =
          checkStateNotNull(
              catalogManagerSchema.getSubSchema(catalogName),
              "Could not find Calcite Schema for catalog '%s'.",
              catalogName);
      checkState(

View on GitHub (pinned to 12126d8942)