{"record":{"id":"8885e2f082d333cf","repo":"apache/beam","slug":"attempting-to-create-database-s-with-unexpected-calcite","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/SqlCreateDatabase.java","lineNumber":86,"sourceCode":"    }\n    writer.keyword(\"DATABASE\");\n    if (ifNotExists) {\n      writer.keyword(\"IF NOT EXISTS\");\n    }\n    databaseName.unparse(writer, leftPrec, rightPrec);\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\n    List<String> components = Lists.newArrayList(Splitter.on('.').split(databaseName.toString()));\n    @Nullable String catalogName =\n        components.size() > 1 ? components.get(components.size() - 2) : null;\n\n    if (!(schema instanceof CatalogManagerSchema)) {\n      throw SqlUtil.newContextException(\n          databaseName.getParserPosition(),\n          RESOURCE.internal(\n              \"Attempting to create database '\"\n                  + databaseName\n                  + \"' with unexpected Calcite Schema of type \"\n                  + schema.getClass()));\n    }\n\n    CatalogManagerSchema catalogManagerSchema = (CatalogManagerSchema) schema;\n    CatalogSchema catalogSchema = catalogManagerSchema.getCurrentCatalogSchema();\n    // override if a catalog name is present\n    if (catalogName != null) {\n      Schema overridden =\n          checkStateNotNull(\n              catalogManagerSchema.getSubSchema(catalogName),\n              \"Could not find Calcite Schema for catalog '%s'.\",\n              catalogName);\n      checkState(","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/parser/SqlCreateDatabase.java#L68-L104","documentation":"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.","triggerScenarios":"Executing `CREATE DATABASE name ...` where the resolved schema (pair.left.schema from SqlDdlNodes.schema(context, true, databaseName)) is not a CatalogManagerSchema.","commonSituations":"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.","solutions":["Use a top-level (or correctly catalog-qualified) database name that resolves to CatalogManagerSchema.","Check the dot-separated name: with two components, the second-to-last must be a registered catalog.","Ensure the session/Calcite connection is configured with Beam's catalog manager schema.","Use CREATE CATALOG first if a new catalog is intended."],"exampleFix":"// before\nCREATE DATABASE wrongcatalog.mydb; -- resolves to non-manager schema\n// after\nCREATE DATABASE mycatalog.mydb;","handlingStrategy":"validation","validationCode":"// Java: resolve and check schema type before CREATE DATABASE\nPair<CalciteSchema, String> pair = SqlDdlNodes.schema(context, true, databaseName);\nif (!(pair.left.schema instanceof CatalogManagerSchema)) {\n  throw new IllegalStateException(\"CREATE DATABASE must resolve to a managed catalog\");\n}","typeGuard":"boolean resolvesToManagedCatalog(String dottedName, CalciteCatalogReader reader) {\n  return SqlDdlNodes.schema(null, true, /* name */ null) != null; // resolve then check instanceof CatalogManagerSchema\n}","tryCatchPattern":null,"preventionTips":["Keep database names to at most catalog.database form.","Ensure the referenced catalog exists before CREATE DATABASE catalog.db.","Run DDL in a session configured with Beam's catalog manager.","Split names on '.' and validate component count before executing."],"tags":["sql","ddl","database","type-mismatch"],"backgroundTag":"type-mismatch","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"}