{"record":{"id":"8746e3a1807e41f2","repo":"apache/beam","slug":"attempting-to-drop-a-table-using-unexpected-calcite-schema-8746e3","errorCode":null,"errorMessage":"Attempting to drop a table using unexpected Calcite Schema of type %s","messagePattern":"Attempting to drop a table using 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/SqlDropTable.java","lineNumber":65,"sourceCode":"\n  @Override\n  public void execute(CalcitePrepare.Context context) {\n    final Pair<CalciteSchema, String> pair = SqlDdlNodes.schema(context, true, name);\n    TableName pathOverride = TableName.create(name.toString());\n    Schema schema = pair.left.schema;\n\n    BeamCalciteSchema beamCalciteSchema;\n    if (schema instanceof CatalogManagerSchema) {\n      CatalogManagerSchema catalogManagerSchema = (CatalogManagerSchema) schema;\n      CatalogSchema catalogSchema =\n          pathOverride.catalog() != null\n              ? catalogManagerSchema.getCatalogSchema(pathOverride)\n              : catalogManagerSchema.getCurrentCatalogSchema();\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 drop a table using unexpected Calcite Schema of type \"\n                  + schema.getClass()));\n    }\n\n    if (beamCalciteSchema.getTable(pair.right) == null) {\n      // Table does not exist.\n      if (!ifExists) {\n        // They did not specify IF EXISTS, so give error.\n        throw SqlUtil.newContextException(\n            name.getParserPosition(), RESOURCE.tableNotFound(name.toString()));\n      }\n      return;\n    }\n\n    beamCalciteSchema.getTableProvider().dropTable(pair.right);\n  }","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/parser/SqlDropTable.java#L47-L83","documentation":"DROP TABLE expects the resolved schema to be catalog-managed (CatalogManagerSchema yielding a BeamCalciteSchema) or directly a BeamCalciteSchema. Any other schema type cannot host Beam tables to drop, so execute() raises this internal error with the actual schema class.","triggerScenarios":"`DROP TABLE <name>` resolving to a plain/custom Calcite Schema implementation rather than a BeamCalciteSchema or catalog-managed schema.","commonSituations":"Embedding Beam SQL with hand-registered non-Beam schemas; pointing the DROP at a foreign Calcite adapter's schema; test harnesses with plain Calcite schemas.","solutions":["Target only schemas created via Beam's catalog/BeamCalciteSchema APIs","Use the default Beam catalog for DDL operations","Wrap custom schemas through Beam's schema provider instead of raw CalciteSchema","Double-check the table's qualified name binds to a Beam-managed schema"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"if (!(schema instanceof BeamCalciteSchema) && !(schema instanceof CatalogManagerSchema)) {\n  throw new IllegalArgumentException(\"DROP TABLE requires a Beam-managed schema\");\n}","typeGuard":"boolean isBeamSchema(Schema s) {\n  return s instanceof BeamCalciteSchema || s instanceof CatalogManagerSchema;\n}","tryCatchPattern":null,"preventionTips":["Point DDL only at BeamCalciteSchema-backed connections","Avoid mixing foreign Calcite adapter schemas with Beam DDL","Validate schema type before executing DDL in embedded setups"],"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"}