{"record":{"id":"140a8e75a7452105","repo":"apache/beam","slug":"duplicate-table-name-table-getname","errorCode":null,"errorMessage":"Duplicate table name: ${table.getName()}","messagePattern":"Duplicate table name: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/meta/store/InMemoryMetaStore.java","lineNumber":54,"sourceCode":"@SuppressWarnings({\n  \"nullness\" // TODO(https://github.com/apache/beam/issues/20497)\n})\npublic class InMemoryMetaStore implements MetaStore {\n  private Map<String, Table> tables = new HashMap<>();\n  private Map<String, TableProvider> providers = new HashMap<>();\n\n  @Override\n  public String getTableType() {\n    return \"store\";\n  }\n\n  @Override\n  public void createTable(Table table) {\n    validateTableType(table);\n\n    // first assert the table name is unique\n    if (tables.containsKey(table.getName())) {\n      throw new IllegalArgumentException(\"Duplicate table name: \" + table.getName());\n    }\n\n    // invoke the provider's create\n    getProvider(table.getType()).createTable(table);\n\n    // store to the global metastore\n    tables.put(table.getName(), table);\n  }\n\n  @Override\n  public void dropTable(String tableName) {\n    if (!tables.containsKey(tableName)) {\n      throw new IllegalArgumentException(\"No such table: \" + tableName);\n    }\n\n    Table table = tables.get(tableName);\n    getProvider(table.getType()).dropTable(tableName);\n    tables.remove(tableName);","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/meta/store/InMemoryMetaStore.java#L36-L72","documentation":"InMemoryMetaStore.createTable enforces that table names are unique within the in-memory metastore. If a table with the same name already exists, it throws IllegalArgumentException before delegating to the provider. This mirrors relational catalog semantics where names are primary keys.","triggerScenarios":"Calling metaStore.createTable(table) twice with the same table.getName(), or re-running setup code (e.g. in tests or notebooks) that registers the same DDL twice without dropping first.","commonSituations":"Re-executed JUnit @BeforeAll setup; interactive SQL sessions re-running CREATE TABLE; hot-reloading app code that rebuilds the metastore into a shared instance.","solutions":["Call dropTable(name) before createTable, or ignore if it already exists.","Use getTable(name) to check existence first and skip creation.","Use a fresh InMemoryMetaStore instance per run/test to guarantee a clean catalog."],"exampleFix":"// before\nmetaStore.createTable(table);\n// after\nif (metaStore.getTable(table.getName()) == null) {\n  metaStore.createTable(table);\n}","handlingStrategy":"validation","validationCode":"if (metaStore.getTable(table.getName()) != null) {\n  metaStore.dropTable(table.getName()); // or skip creation\n}\nmetaStore.createTable(table);","typeGuard":null,"tryCatchPattern":"try {\n  metaStore.createTable(table);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Duplicate table name\")) { /* already created: ignore or drop+recreate */ }\n}","preventionTips":["Make setup idempotent with existence checks.","Use a fresh InMemoryMetaStore per test/run.","Centralize table creation in one guarded helper."],"tags":["beam-sql","metastore","duplicate-key"],"backgroundTag":"file-already-exists","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"}