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
Beam SQL's `USE DATABASE` parser node resolves the named database schema via Calcite and requires it to be a CatalogManagerSchema, since the statement rewrites table paths against a managed catalog. Any other Calcite Schema implementation cannot support this, so an internal context exception naming the schema's Java class is thrown.
Solutions
- Register the target database through Beam's catalog manager so it resolves to CatalogManagerSchema.
- Check the database path syntax (dot-separated) and that it names a managed database.
- Remove or restructure custom SchemaPlus registrations that shadow Beam's catalog.
- Use table-qualified names instead of switching databases if the schema cannot be a CatalogManagerSchema.
Example fix
// before
statement.executeSql("USE DATABASE mydb"); // mydb resolves to a plain Calcite schema
// after
statement.executeSql("SELECT * FROM beam_catalog.mydb.mytable"); // or register mydb with Beam's catalog manager Defensive patterns
Strategy: validation
Validate before calling
// Verify database path components resolve to a managed catalog schema
List<String> components = Splitter.on('.').splitToList(path);
if (!catalogManager.containsDatabase(components)) {
throw new IllegalArgumentException(path + " is not a managed Beam database");
} Type guard
if (!(schema instanceof CatalogManagerSchema)) { /* fall back / fail fast */ } Prevention
- Validate dotted database paths against the managed catalog before USE DATABASE.
- Avoid custom SchemaPlus registrations that bypass Beam's catalog manager.
- Use qualified table names instead of switching databases when possible.
When it happens
Trigger: Executing `USE DATABASE <path>` where the resolved CalciteSchema's .schema is not an instance of CatalogManagerSchema.
Common situations: Pointing USE DATABASE at a schema registered outside Beam's catalog manager; malformed dotted paths resolved against the wrong schema; custom schema providers in the Calcite connection.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
- Attempting to 'USE CATALOG
- Attempting to create database
- Attempting to drop database
- Cannot get column index from
- Cannot get limit count from RelNode tree with root
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/821c15398ebe70b3.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/parser/SqlUseDatabase.java:71
public SqlOperator getOperator() {
return OPERATOR;
}
@Override
public List<SqlNode> getOperandList() {
return Collections.singletonList(databaseName);
}
@Override
public void execute(CalcitePrepare.Context context) {
final Pair<CalciteSchema, String> pair = SqlDdlNodes.schema(context, true, databaseName);
Schema schema = pair.left.schema;
String path = databaseName.toString();
List<String> components = Lists.newArrayList(Splitter.on(".").split(path));
TableName pathOverride = TableName.create(components, "");
if (!(schema instanceof CatalogManagerSchema)) {
throw SqlUtil.newContextException(
databaseName.getParserPosition(),
RESOURCE.internal(
"Attempting to create database '"
+ path
+ "' with unexpected Calcite Schema of type "
+ schema.getClass()));
}
CatalogManagerSchema catalogManagerSchema = (CatalogManagerSchema) schema;
CatalogSchema catalogSchema = catalogManagerSchema.getCatalogSchema(pathOverride);
// if database exists in a different catalog, we need to also switch to that catalog
if (pathOverride.catalog() != null
&& !pathOverride
.catalog()
.equals(catalogManagerSchema.getCurrentCatalogSchema().getCatalog().name())) {
SqlIdentifier catalogIdentifier =
new SqlIdentifier(pathOverride.catalog(), databaseName.getParserPosition());
catalogManagerSchema.useCatalog(catalogIdentifier);View on GitHub (pinned to 12126d8942)