{"record":{"id":"821c15398ebe70b3","repo":"apache/beam","slug":"attempting-to-create-database-s-with-unexpected-calcite-821c15","errorCode":null,"errorMessage":"Attempting to create database '%s' with unexpected Calcite Schema of type %s","messagePattern":"Attempting to create database '(.+?)' with unexpected Calcite Schema of type (.+?)","errorType":"validation","errorClass":"SqlUtil.newContextException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/parser/SqlUseDatabase.java","lineNumber":71,"sourceCode":"  public SqlOperator getOperator() {\n    return OPERATOR;\n  }\n\n  @Override\n  public List<SqlNode> getOperandList() {\n    return Collections.singletonList(databaseName);\n  }\n\n  @Override\n  public void execute(CalcitePrepare.Context context) {\n    final Pair<CalciteSchema, String> pair = SqlDdlNodes.schema(context, true, databaseName);\n    Schema schema = pair.left.schema;\n    String path = databaseName.toString();\n    List<String> components = Lists.newArrayList(Splitter.on(\".\").split(path));\n    TableName pathOverride = TableName.create(components, \"\");\n\n    if (!(schema instanceof CatalogManagerSchema)) {\n      throw SqlUtil.newContextException(\n          databaseName.getParserPosition(),\n          RESOURCE.internal(\n              \"Attempting to create database '\"\n                  + path\n                  + \"' with unexpected Calcite Schema of type \"\n                  + schema.getClass()));\n    }\n\n    CatalogManagerSchema catalogManagerSchema = (CatalogManagerSchema) schema;\n    CatalogSchema catalogSchema = catalogManagerSchema.getCatalogSchema(pathOverride);\n    // if database exists in a different catalog, we need to also switch to that catalog\n    if (pathOverride.catalog() != null\n        && !pathOverride\n            .catalog()\n            .equals(catalogManagerSchema.getCurrentCatalogSchema().getCatalog().name())) {\n      SqlIdentifier catalogIdentifier =\n          new SqlIdentifier(pathOverride.catalog(), databaseName.getParserPosition());\n      catalogManagerSchema.useCatalog(catalogIdentifier);","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/parser/SqlUseDatabase.java#L53-L89","documentation":"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.","triggerScenarios":"Executing `USE DATABASE <path>` where the resolved CalciteSchema's .schema is not an instance of CatalogManagerSchema.","commonSituations":"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.","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."],"exampleFix":"// before\nstatement.executeSql(\"USE DATABASE mydb\"); // mydb resolves to a plain Calcite schema\n// after\nstatement.executeSql(\"SELECT * FROM beam_catalog.mydb.mytable\"); // or register mydb with Beam's catalog manager","handlingStrategy":"validation","validationCode":"// Verify database path components resolve to a managed catalog schema\nList<String> components = Splitter.on('.').splitToList(path);\nif (!catalogManager.containsDatabase(components)) {\n  throw new IllegalArgumentException(path + \" is not a managed Beam database\");\n}","typeGuard":"if (!(schema instanceof CatalogManagerSchema)) { /* fall back / fail fast */ }","tryCatchPattern":null,"preventionTips":["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."],"tags":["sql","calcite","database","beam"],"backgroundTag":"incompatible-source-type","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}