{"record":{"id":"cd17abcab391c0c1","repo":"dbt-labs/dbt-core","slug":"columnsastuple-count-occurrences-of","errorCode":null,"errorMessage":"ColumnsAsTuple::count_occurrences_of","messagePattern":"ColumnsAsTuple::count_occurrences_of","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-agate/src/columns.rs","lineNumber":212,"sourceCode":"    }\n\n    pub fn into_tuple(self) -> Tuple {\n        Tuple(Box::new(self))\n    }\n}\n\nimpl TupleRepr for ColumnsAsTuple {\n    fn get_item_by_index(&self, idx: isize) -> Option<Value> {\n        let column = self.of_table.get_column(idx)?;\n        Some(Value::from_object(column))\n    }\n\n    fn len(&self) -> usize {\n        self.of_table.num_columns()\n    }\n\n    fn count_occurrences_of(&self, _needle: &Value) -> usize {\n        todo!(\"ColumnsAsTuple::count_occurrences_of\")\n    }\n\n    fn index_of(&self, _needle: &Value) -> Option<usize> {\n        todo!(\"ColumnsAsTuple::index_of\")\n    }\n\n    fn clone_repr(&self) -> Box<dyn TupleRepr> {\n        Box::new(ColumnsAsTuple {\n            of_table: Arc::clone(&self.of_table),\n        })\n    }\n}\n\n/// Represents an instance of a `MappedSequence` populated by a list of columns.\n///\n/// https://github.com/wireservice/agate/blob/7023e35b51e8abfe9784fe292a23dd4d7d983c63/agate/table/__init__.py#L181\n#[derive(Debug)]\npub struct Columns {","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-agate/src/columns.rs#L194-L230","documentation":"`ColumnsAsTuple::count_occurrences_of` in dbt-agate is a `todo!()` placeholder in the `TupleRepr` trait implementation, so calling it panics with the message \"ColumnsAsTuple::count_occurrences_of\". The columns-as-tuple view of a Table does not yet support counting occurrences of a value across its columns. Any code that treats a table's columns like an agate Python tuple and asks how many entries equal a given value will hit this panic.","triggerScenarios":"Calling `count_occurrences_of(&value)` on a `ColumnsAsTuple` (e.g., a table's `.columns` view used as a tuple) for any needle value.","commonSituations":"Porting agate Python table operations (e.g., `values.count(...)`) to the Rust dbt-agate port; code doing membership/multiplicity checks on a table's column collection.","solutions":["Avoid calling `count_occurrences_of` on the columns tuple view; iterate the table's rows/values and count manually instead.","Use the row-oriented tuple representation instead of `ColumnsAsTuple` if the operation is available there.","Implement the method upstream: delegate to comparing each column against the needle (per the Python agate semantics) and return the match count."],"exampleFix":"// before (crates/dbt-agate/src/columns.rs)\nfn count_occurrences_of(&self, _needle: &Value) -> usize {\n    todo!(\"ColumnsAsTuple::count_occurrences_of\")\n}\n// after\nfn count_occurrences_of(&self, needle: &Value) -> usize {\n    (0..self.len()).filter(|i| self.get(i).map_or(false, |v| v == needle)).count()\n}","handlingStrategy":"validation","validationCode":"// avoid the call entirely; count manually:\nlet count = table.rows()\n    .filter(|row| row.values().iter().any(|v| v == &needle))\n    .count();","typeGuard":"fn supports_tuple_repr_op(repr: &dyn TupleRepr) -> bool {\n    // ColumnsAsTuple does not implement count_occurrences_of/index_of\n    (repr as &dyn std::any::Any).downcast_ref::<ColumnsAsTuple>().is_none()\n}","tryCatchPattern":"// isolate the placeholder if a trait object must be used:\nlet n = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| repr.count_occurrences_of(&needle)))\n    .unwrap_or(0);","preventionTips":["Do not use the columns tuple view for value multiplicity checks; use row/column iteration.","Prefer row-oriented tuple representations when you need full TupleRepr behavior.","Check the dbt-agate TODO markers before porting agate Python tuple methods."],"tags":["unimplemented","agate","rust-panic","table-operations"],"backgroundTag":"method-not-implemented","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}