{"record":{"id":"b71d0508174dd396","repo":"apache/beam","slug":"attempting-to-create-a-table-with-unexpected-calcite-schema","errorCode":null,"errorMessage":"Attempting to create a table with unexpected Calcite Schema of type %s","messagePattern":"Attempting to create a table 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/SqlCreateExternalTable.java","lineNumber":167,"sourceCode":"            name.getParserPosition(), RESOURCE.tableExists(pair.right));\n      }\n      return;\n    }\n\n    Schema schema = pair.left.schema;\n\n    BeamCalciteSchema beamCalciteSchema;\n    if (schema instanceof CatalogManagerSchema) {\n      TableName pathOverride = TableName.create(name.toString());\n      CatalogManagerSchema catalogManagerSchema = (CatalogManagerSchema) schema;\n      catalogManagerSchema.maybeRegisterProvider(pathOverride, SqlDdlNodes.getString(type));\n\n      CatalogSchema catalogSchema = catalogManagerSchema.getCatalogSchema(pathOverride);\n      beamCalciteSchema = catalogSchema.getDatabaseSchema(pathOverride);\n    } else if (schema instanceof BeamCalciteSchema) {\n      beamCalciteSchema = (BeamCalciteSchema) schema;\n    } else {\n      throw SqlUtil.newContextException(\n          name.getParserPosition(),\n          RESOURCE.internal(\n              \"Attempting to create a table with unexpected Calcite Schema of type \"\n                  + schema.getClass()));\n    }\n    Table table = toTable();\n\n    if (partitionFields != null) {\n      checkArgument(\n          beamCalciteSchema.getTableProvider().supportsPartitioning(table),\n          \"Invalid use of 'PARTITIONED BY()': Table '%s' of type '%s' \"\n              + \"does not support partitioning.\",\n          name(name),\n          SqlDdlNodes.getString(type));\n    }\n\n    beamCalciteSchema.getTableProvider().createTable(table);\n  }","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/parser/SqlCreateExternalTable.java#L149-L185","documentation":"Internal invariant error in SqlCreateExternalTable.execute: after resolving the schema, Beam expects it to be either a CatalogManagerSchema-resolvable catalog schema or a BeamCalciteSchema. Any other Calcite Schema implementation cannot host a Beam external table, so the DDL aborts with RESOURCE.internal.","triggerScenarios":"CREATE EXTERNAL TABLE executed against a Calcite schema that is neither a catalog-managed schema yielding a BeamCalciteSchema nor a BeamCalciteSchema itself — e.g. a custom/plain CalciteSchema registered into the connection's root schema.","commonSituations":"Embedding Beam SQL with a hand-built Calcite SchemaPlus; plugging third-party Calcite adapters into Beam's DDL path; test harnesses that register plain CalciteTest schemas.","solutions":["Register a BeamCalciteSchema (or a CatalogManagerSchema-managed catalog) as the target schema for Beam SQL DDL","Use the default Beam SQL catalog/database instead of a custom root schema","If embedding, wrap your schema via Beam's schema provider APIs rather than raw CalciteSchema","File/inspect Beam issue if this occurs with a stock setup"],"exampleFix":"// before\nrootSchema.add(\"mydb\", new AbstractSchema()); // plain Calcite schema\n// after\nrootSchema.add(\"mydb\", BeamCalciteSchema.create(new BeamSqlTable...schema)); // or use CatalogManagerSchema","handlingStrategy":"type-guard","validationCode":"if (!(schema instanceof BeamCalciteSchema) && !(schema instanceof CatalogManagerSchema)) {\n  throw new IllegalArgumentException(\"CREATE EXTERNAL TABLE requires a Beam-managed schema\");\n}","typeGuard":"boolean isBeamSchema(Schema s) {\n  return s instanceof BeamCalciteSchema || s instanceof CatalogManagerSchema;\n}","tryCatchPattern":null,"preventionTips":["Register only BeamCalciteSchema/CatalogManagerSchema for Beam SQL DDL","Avoid adding raw AbstractSchema implementations to the root used by Beam SQL","Test embedded setups against a stock BeamSqlEnv first"],"tags":["sql","ddl","internal-error"],"backgroundTag":"internal-invariant-violation","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"}