{"record":{"id":"c59d9a4413444e1e","repo":"dbt-labs/dbt-core","slug":"table-rename-renamed-columns-length-does-not","errorCode":null,"errorMessage":"Table.rename: renamed_columns length ({}) does not match number of columns ({})","messagePattern":"Table\\.rename: renamed_columns length \\((.+?)\\) does not match number of columns \\((.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-agate/src/table.rs","lineNumber":798,"sourceCode":"    }\n\n    /// Rename columns and/or rows.\n    ///\n    /// PRECONDITION:\n    /// - if `renamed_columns` is `Some`, its length must be equal to\n    ///   the number of columns in the table.\n    /// - if `renamed_rows` is `Some`, its length must be equal to\n    ///   the number of rows in the table.\n    pub fn rename(\n        &self,\n        renamed_columns: Option<Vec<String>>,\n        renamed_rows: Option<Arc<StringViewArray>>,\n        slug_columns: bool,\n        slug_rows: bool,\n    ) -> Result<AgateTable, Error> {\n        if let Some(ref columns) = renamed_columns {\n            if columns.len() != self.num_columns() {\n                return Err(Error::new(\n                    ErrorKind::InvalidArgument,\n                    format!(\n                        \"Table.rename: renamed_columns length ({}) does not match number of columns ({})\",\n                        columns.len(),\n                        self.num_columns()\n                    ),\n                ));\n            }\n        }\n        if let Some(ref rows) = renamed_rows {\n            if rows.len() != self.num_rows() {\n                return Err(Error::new(\n                    ErrorKind::InvalidArgument,\n                    format!(\n                        \"Table.rename: renamed_rows length ({}) does not match number of rows ({})\",\n                        rows.len(),\n                        self.num_rows()\n                    ),","sourceCodeStart":780,"sourceCodeEnd":816,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-agate/src/table.rs#L780-L816","documentation":"Table.rename validates that a provided renamed_columns array has exactly one entry per column of the table. The array's length did not match the table's column count, so the positional renaming would be ambiguous and the call is rejected.","triggerScenarios":"Calling rename with an array of new column names shorter or longer than the table's number of columns, e.g. renaming a 5-column table with a 3-element array.","commonSituations":"Reusing a hardcoded name list against a table whose schema changed after upstream transformations; building the list before knowing the final column set; copy-pasted rename calls from another table.","solutions":["Compute the name list from the table's actual column count (num_columns) before calling rename.","Use the map form {\"old\": \"new\"} to rename only selected columns without matching lengths.","Print the table's column count and the array length to find where they diverge."],"exampleFix":"// before\nrename(Some(vec![\"a\", \"b\"]), None, false, false) // table has 3 columns\n// after\nrename(Some(vec![\"a\", \"b\", \"c\"]), None, false, false)","handlingStrategy":"validation","validationCode":"if renamed.len() != table.num_columns() {\n    return Err(format!(\"expected {} names, got {}\", table.num_columns(), renamed.len()));\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"renamed_columns length\") => {\n        eprintln!(\"{e}; check table schema and name list sizes\");\n        // rebuild names from table.num_columns() and retry\n    }\n    other => other?,\n}","preventionTips":["Derive name lists from table.num_columns() at call time, not from hardcoded values.","Prefer the map form when renaming a subset of columns.","Re-validate lengths after any upstream transformation that changes schema."],"tags":["argument-validation","rename","length-mismatch"],"backgroundTag":"invalid-argument-value","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}