{"record":{"id":"96dd8d55e61c23c5","repo":"apache/beam","slug":"schema-name-is-registered-twice","errorCode":null,"errorMessage":"Schema ${name} is registered twice.","messagePattern":"Schema (.+?) is registered twice\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/BeamSqlEnv.java","lineNumber":197,"sourceCode":"      autoLoadUdfs = false;\n      pipelineOptions = null;\n      ruleSets = BeamRuleSets.getRuleSets();\n    }\n\n    private BeamSqlEnvBuilder(CatalogManager catalogManager) {\n      this.catalogManager = catalogManager;\n      this.queryPlannerClassName = CALCITE_PLANNER;\n      this.schemaMap = new HashMap<>();\n      this.functionSet = new HashSet<>();\n      this.autoLoadUdfs = false;\n      this.pipelineOptions = null;\n      this.ruleSets = BeamRuleSets.getRuleSets();\n    }\n\n    /** Add a top-level schema backed by the table provider. */\n    public BeamSqlEnvBuilder addSchema(String name, TableProvider tableProvider) {\n      if (schemaMap.containsKey(name)) {\n        throw new RuntimeException(\"Schema \" + name + \" is registered twice.\");\n      }\n\n      schemaMap.put(name, tableProvider);\n      return this;\n    }\n\n    /** Set the current (default) schema. */\n    public BeamSqlEnvBuilder setCurrentSchema(String name) {\n      currentSchemaName = name;\n      return this;\n    }\n\n    /** Set the ruleSet used for query optimizer. */\n    public BeamSqlEnvBuilder setRuleSets(Collection<RuleSet> ruleSets) {\n      this.ruleSets = ruleSets;\n      return this;\n    }\n","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/BeamSqlEnv.java#L179-L215","documentation":"BeamSqlEnvBuilder.addSchema refuses to register two top-level schemas under the same name, throwing RuntimeException to keep the schema map unambiguous. Duplicate names would make table resolution nondeterministic.","triggerScenarios":"Calling addSchema(name, provider) (or addSchemaForTest) twice with the same schema name in one BeamSqlEnvBuilder chain, e.g. adding 'default' when it is already registered by the builder/environment.","commonSituations":"Builder reuse across pipelines, test setups registering a schema that the environment already added, loops that re-add on retries.","solutions":["Check schemaMap / builder state before calling addSchema and skip if the name exists","Use a distinct schema name for each provider","Rebuild a fresh BeamSqlEnvBuilder instead of reusing one that already registered the schema"],"exampleFix":"// before\nbuilder.addSchema(\"db\", provider);\nbuilder.addSchema(\"db\", provider); // throws\n// after\nif (!builder.hasSchema(\"db\")) builder.addSchema(\"db\", provider);","handlingStrategy":"validation","validationCode":"if (envBuilder.getSchemaNames().contains(name)) { /* skip or rename */ }","typeGuard":null,"tryCatchPattern":"try { builder.addSchema(name, provider); } catch (RuntimeException e) { log.warn(\"Schema {} already registered\", name); }","preventionTips":["Track registered schema names in a set","Use unique schema names per provider","Don't reuse builders across pipelines"],"tags":["sql","configuration","duplicate-registration"],"backgroundTag":"conflicting-config-options","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"}