{"record":{"id":"3a3f863ad12ffe75","repo":"dbt-labs/dbt-core","slug":"table-group-by-key-error-selecting-table-rows-e","errorCode":null,"errorMessage":"Table.group_by_key: error selecting table rows: {e}","messagePattern":"Table\\.group_by_key: error selecting table rows: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-agate/src/table.rs","lineNumber":918,"sourceCode":"                let indices = UInt64Array::new(indices.into(), None);\n                let table = self\n                    .repr\n                    .select_rows(\n                        &indices,\n                        Some(TakeOptions {\n                            check_bounds: false, // groups only contain valid indices\n                            ..Default::default()\n                        }),\n                    )\n                    .map(|repr| {\n                        let table = AgateTable::from_repr(Arc::new(repr));\n                        Arc::new(table)\n                    })?;\n                Ok(table) as Result<Arc<AgateTable>, ArrowError>\n            })\n            .collect::<Result<Vec<Arc<AgateTable>>, ArrowError>>()\n            .map_err(|e| {\n                Error::new(\n                    ErrorKind::InvalidOperation,\n                    format!(\"Table.group_by_key: error selecting table rows: {e}\"),\n                )\n            })?;\n\n        let key_name = Some(key_name.to_string());\n        let is_fork = true; // skip validations\n        let repr = TableSetRepr::try_new(tables, keys, key_name, key_type, is_fork)?;\n        Ok(TableSet::from_repr(repr))\n    }\n\n    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) {","sourceCodeStart":900,"sourceCodeEnd":936,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-agate/src/table.rs#L900-L936","documentation":"After grouping, group_by_key selects the rows belonging to each group to build the sub-tables. If the row-selection take operation fails at the Arrow level, the error is wrapped as 'error selecting table rows'.","triggerScenarios":"Internal failure while taking rows per group: out-of-bounds indices produced by the grouper, or an Arrow compute error (e.g. type/kernel mismatch) during the take, surfaced via the collect of per-group tables.","commonSituations":"Custom or unusual column types whose take kernel fails; edge-case grouping inputs (all-null keys, very large indices); running with an Arrow version whose take behavior differs.","solutions":["Check the inner Arrow error message for the concrete take failure (e.g. out-of-bounds index).","Sanitize the key column before grouping (replace nulls, cast to a simple type like Utf8 or Int64).","Reproduce with a small table to isolate which column or key values break selection."],"exampleFix":"// before\nlet groups = table.group_by_key(\"id\", None, None)?; // id is List<Utf8>\n// after\nlet groups = table\n    .with_column(\"id_str\", cast(col(\"id\"), Utf8))?\n    .group_by_key(\"id_str\", None, None)?;","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match table.group_by_key(key, None, None) {\n    Ok(groups) => groups,\n    Err(e) if e.to_string().contains(\"error selecting table rows\") => {\n        eprintln!(\"arrow take failed while building groups: {e}\");\n        // sanitize/cast key column and retry\n        return Err(e);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Replace nulls and cast complex key columns to simple types before grouping.","Test group_by_key on a small sample table first.","Keep Arrow versions aligned between your crate and dbt-agate to avoid kernel mismatches."],"tags":["group-by","arrow","take"],"backgroundTag":"database-query-failed","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"}