{"record":{"id":"0efba4b099b654af","repo":"dbt-labs/dbt-core","slug":"table-distinct-error-creating-grouper-e","errorCode":null,"errorMessage":"Table.distinct: error creating grouper: {e}","messagePattern":"Table\\.distinct: error creating grouper: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-agate/src/table.rs","lineNumber":948,"sourceCode":"    fn distinct(&self, key: Option<Vec<String>>) -> Result<AgateTable, Error> {\n        let column_names = match key {\n            Some(keys) => self\n                .column_names()\n                .iter()\n                .filter_map(|key| {\n                    if keys.contains(key) {\n                        Some(key.clone())\n                    } else {\n                        None\n                    }\n                })\n                .collect(),\n            None => self.column_names(),\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(&column_names).map_err(|e| {\n            Error::new(\n                ErrorKind::InvalidOperation,\n                format!(\"Table.distinct: error creating grouper: {e}\"),\n            )\n        })?;\n\n        // Builds a selection vector with the first `row_idx` of every group.\n        // A \"group\" is the set of rows that are identical, so whenever the\n        // grouper emits a `group_id` we've already seen, we know we shouldn't\n        // emit that `row_idx` because it's not the index of a distinct row.\n        let mut seen_groups = HashSet::new();\n        let indices: Vec<u64> = grouper\n            .iter()\n            .enumerate()\n            .filter_map(|(row_idx, group_id)| {\n                if seen_groups.insert(group_id) {\n                    Some(row_idx as u64)\n                } else {\n                    None","sourceCodeStart":930,"sourceCodeEnd":966,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-agate/src/table.rs#L930-L966","documentation":"distinct builds a grouper over the specified (or all) columns to identify unique rows. If grouper construction fails — unknown column name or unsupported column type — the error is wrapped as 'Table.distinct: error creating grouper'.","triggerScenarios":"Calling table.distinct with a subset argument naming a column that does not exist, or distinct over columns with types the grouper cannot hash (e.g. nested types).","commonSituations":"Typo in the subset column list; upstream schema drift renamed a column; deduplicating on struct/list columns unsupported by the grouper.","solutions":["Verify every name in the subset list exists in the table's column_names.","Call distinct with no subset to dedupe on all columns, or restrict the subset to primitive-typed columns.","Read the wrapped inner error for the precise cause (missing column vs unsupported dtype) and fix the input accordingly."],"exampleFix":"// before\ntable.distinct(Some(vec![\"user_id\", \"evnt_date\"]), None)? // typo\n// after\ntable.distinct(Some(vec![\"user_id\", \"event_date\"]), None)?","handlingStrategy":"validation","validationCode":"let names = table.column_names();\nif let Some(sub) = &subset {\n    for c in sub {\n        if !names.contains(c) { return Err(format!(\"column '{c}' not found\")); }\n    }\n}","typeGuard":null,"tryCatchPattern":"match table.distinct(subset, key_type) {\n    Ok(t) => t,\n    Err(e) if e.to_string().contains(\"error creating grouper\") => {\n        eprintln!(\"{e}\");\n        // fix subset names/types and retry, or dedupe on all columns\n        table.distinct(None, None)\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Validate subset names against table.column_names() before calling distinct.","Restrict distinct subsets to primitive-typed columns.","Reread schema after upstream transformations that may rename columns."],"tags":["distinct","grouper","deduplication"],"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"}