{"record":{"id":"213488624af21e95","repo":"dbt-labs/dbt-core","slug":"table-group-by-key-error-creating-grouper-for-key","errorCode":null,"errorMessage":"Table.group_by_key: error creating grouper for key '{key}': {e}","messagePattern":"Table\\.group_by_key: error creating grouper for key '(.+?)': (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-agate/src/table.rs","lineNumber":858,"sourceCode":"    }\n\n    fn group_by_key(\n        &self,\n        key: &str,\n        key_name: &str,\n        key_type: Option<crate::DataType>,\n    ) -> Result<TableSet, Error> {\n        let column = self\n            .column_names_iter()\n            .position(|n| n == key)\n            .map(|idx| Column::new(idx, Arc::clone(&self.repr)));\n\n        let key_type = key_type.or_else(|| column.as_ref().and_then(|c| c.data_type().cloned()));\n\n        // TODO: cast the values in `column` according to `key_type`, create a new\n        // table with the casted column, and use that table to create the grouper\n        let grouper = self.grouper(&[key.to_string()]).map_err(|e| {\n            Error::new(\n                ErrorKind::InvalidOperation,\n                format!(\"Table.group_by_key: error creating grouper for key '{key}': {e}\"),\n            )\n        })?;\n\n        // Each vec contains the row indices for each group.\n        let mut groups: Vec<Vec<u64>> = Vec::new();\n        for (row_idx, group_id) in grouper.iter().enumerate() {\n            match group_id.cmp(&groups.len()) {\n                Ordering::Less => groups[group_id].push(row_idx as u64),\n                Ordering::Equal => groups.push(vec![row_idx as u64]),\n                Ordering::Greater => {\n                    // SAFETY: new group ids are always created with increments of 1, so\n                    // we either see a new group id equal to the current length of groups,\n                    // or an existing group in this loop\n                    unsafe { unreachable_unchecked() }\n                }\n            }","sourceCodeStart":840,"sourceCodeEnd":876,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-agate/src/table.rs#L840-L876","documentation":"group_by_key builds an internal grouper over the key column to produce row-index groups. If the underlying grouper construction fails (e.g. the key column does not exist or its type is unsupported for grouping), the error is wrapped in this message naming the key.","triggerScenarios":"Calling table.group_by_key with a key name that is not an existing column, or with a key column whose Arrow data type the grouper cannot handle (e.g. nested/list types).","commonSituations":"Typo in the key column name; schema changed upstream so the expected key column is missing or renamed; grouping on a struct/list column that the grouper does not support.","solutions":["Verify the key name matches an existing column in the table (check column_names / schema).","Group on a primitive-typed column; cast complex columns to a supported type first.","Inspect the inner error message (embedded after ': {e}') for the root cause, e.g. unknown column vs unsupported dtype."],"exampleFix":"// before\ntable.group_by_key(\"catergory\", None, None)? // typo\n// after\ntable.group_by_key(\"category\", None, None)?","handlingStrategy":"validation","validationCode":"if !table.column_names().contains(&key.to_string()) {\n    return Err(format!(\"key column '{key}' not found in table\"));\n}","typeGuard":null,"tryCatchPattern":"match table.group_by_key(key, key_type, None) {\n    Ok(groups) => groups,\n    Err(e) if e.to_string().contains(\"error creating grouper\") => {\n        eprintln!(\"{e}\");\n        // verify column name/type, cast, and retry\n        return Err(e);\n    }\n}","preventionTips":["Check the key name against the table schema before grouping.","Group on primitive-typed columns (Utf8, Int64, etc.); cast nested types first.","Log the inner wrapped error to distinguish missing column from unsupported dtype."],"tags":["group-by","grouper","key-column"],"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-17T15:17:12.973Z"}