{"record":{"id":"46870be31159233e","repo":"influxdata/influxdb","slug":"schema-contains-repeated-column-name","errorCode":null,"errorMessage":"schema contains repeated column name","messagePattern":"schema contains repeated column name","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"core/mutable_batch/src/lib.rs","lineNumber":133,"sourceCode":"\n        let Self {\n            column_names,\n            columns,\n            row_count: _,\n        } = self;\n\n        // Convert to Vec<Option<_>> to remove each Column avoid copying the\n        // underlying data\n        let mut columns = columns.into_iter().map(Some).collect::<Vec<_>>();\n\n        let arrays: Result<Vec<_>, Error> = schema\n            .iter()\n            .map(|(_, field)| {\n                let column_index = column_names\n                    .get(field.name())\n                    .expect(\"schema contains non-existent or column\");\n                std::mem::take(&mut columns[*column_index])\n                    .expect(\"schema contains repeated column name\")\n                    .try_into_arrow()\n                    .context(ColumnSnafu {\n                        column: field.name(),\n                    })\n            })\n            .collect();\n\n        RecordBatch::try_new(schema.into(), arrays?).context(ArrowSnafu {})\n    }\n\n    /// Returns an iterator over the columns in this batch in no particular order\n    pub fn columns(&self) -> impl ExactSizeIterator<Item = (usize, &String, &Column)> + '_ {\n        self.column_names\n            .iter()\n            .map(move |(name, idx)| (*idx, name, &self.columns[*idx]))\n    }\n\n    /// Yield an iterator of column `(name, type)` tuples for all columns in","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/influxdata/influxdb/blob/d28e26e048401c53cbb98cf2d6ab0cf1e98048ca/core/mutable_batch/src/lib.rs#L115-L151","documentation":"In MutableBatch::try_into_arrow's conversion loop, the first occurrence of a field name consumes its column via std::mem::take (leaving None); a second schema field with the same name then finds None and panics with 'schema contains repeated column name'. Arrow schemas permit duplicate field names, so a projection or schema listing the same column twice triggers this.","triggerScenarios":"Passing Projection::Some with the same column name repeated; a schema built by concatenating two table schemas that both contain an identically named column; de-duplication lost during a merge.","commonSituations":"Programmatic projection construction from multiple sources without dedupe; wildcard 'SELECT *' plus explicit column names producing a duplicated list; schema merge during table evolution.","solutions":["Deduplicate projection names before calling try_into_arrow (e.g. collect into a BTreeSet/IndexSet)","Fix the schema construction that produced duplicate field names","Assert uniqueness up front: assert_eq!(names.len(), dedup(names).len()) in tests around projection-building code"],"exampleFix":"// before\nlet cols = [\"time\", \"cpu\", \"cpu\"];  // duplicate\nlet rb = batch.try_into_arrow(Projection::Some(&cols))?;\n\n// after\nlet cols: Vec<_> = cols.into_iter().collect::<std::collections::BTreeSet<_>>().into_iter().collect();\nlet rb = batch.try_into_arrow(Projection::Some(&cols))?;\n","handlingStrategy":"validation","validationCode":"// dedupe projection names before use\nlet deduped: Vec<&str> = {\n    let seen: std::collections::BTreeSet<&str> = projection.iter().copied().collect();\n    seen.into_iter().collect()\n};\nassert_eq!(deduped.len(), projection.len(), \"duplicate column names in projection\");\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Dedupe column lists at construction time (BTreeSet/IndexSet)","Review wildcard-plus-explicit-column query building for accidental duplicates","Unit-test projection builders with overlapping inputs"],"tags":["arrow","record-batch","mutable-batch","duplicate-column","panic","influxdb3"],"backgroundTag":"duplicate-column-name","analyzedSha":"d28e26e048401c53cbb98cf2d6ab0cf1e98048ca","analyzedAt":"2026-08-16T19:53:34.623Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}