dbt-labs/dbt-core · error

column_distinct

Error message

column_distinct

What it means

`Table::column_distinct` in dbt-agate is an unimplemented public API: it computes the single-column subtable via `single_column_table` and then panics with `todo!("column_distinct")`. The method is supposed to return a single-column table containing the distinct values of the given column (mirroring agate's `Table.distinct` on one column), but the deduplication logic is not yet written.

Source

Thrown at crates/dbt-agate/src/table.rs:225

        let flat = self.flat.select(indices);
        // row names remain the same when selecting columns
        let row_names = self.row_names.as_ref().map(Arc::clone);
        let repr = TableRepr::new(flat, None, row_names);
        Arc::new(repr)
    }

    pub fn single_column_table(&self, idx: isize) -> Option<Arc<TableRepr>> {
        let idx = self.adjusted_column_index(idx)?;
        let flat_with_single_column = self.flat.with_single_column(idx);
        let row_names = self.row_names.as_ref().map(Arc::clone);
        let repr = TableRepr::new(flat_with_single_column, None, row_names);
        Some(Arc::new(repr))
    }

    /// Return a single-column table with the distinct values in this column.
    pub fn column_distinct(&self, col_idx: isize) -> Arc<Self> {
        let _col = self.single_column_table(col_idx).unwrap();
        todo!("column_distinct")
    }

    pub fn column_without_nulls(&self, col_idx: isize) -> Arc<Self> {
        let _col = self.single_column_table(col_idx).unwrap();
        todo!("column_without_nulls")
    }

    pub fn column_sorted(&self, col_idx: isize) -> Arc<Self> {
        let _col = self.single_column_table(col_idx).unwrap();
        todo!("column_sorted")
    }

    pub fn column_without_nulls_sorted(&self, col_idx: isize) -> Arc<Self> {
        let _col = self.single_column_table(col_idx).unwrap();
        todo!("column_without_nulls_sorted")
    }

    pub fn count_occurrences_of_value_in_column(&self, _needle: &Value, col_idx: isize) -> usize {

View on GitHub (pinned to 0267ce9170)

Solutions

  1. Compute distinct values manually: extract the column, iterate its values, deduplicate (e.g., with a HashSet or ordered set), and build a new single-column table yourself.
  2. Use any existing alternative such as `column_without_nulls` equivalents or grouping APIs if implemented.
  3. Implement the method upstream: take the single-column table, dedupe rows by value preserving first-seen order, and return the resulting table.

Example fix

// before (crates/dbt-agate/src/table.rs)
pub fn column_distinct(&self, col_idx: isize) -> Arc<Self> {
    let _col = self.single_column_table(col_idx).unwrap();
    todo!("column_distinct")
}
// after
pub fn column_distinct(&self, col_idx: isize) -> Arc<Self> {
    let col = self.single_column_table(col_idx).unwrap();
    let mut seen = IndexSet::new();
    for v in col.column_values(0) { seen.insert(v.clone()); }
    self.from_columns_rows(/* distinct rows built from `seen` */)
}
Defensive patterns

Strategy: validation

Validate before calling

// check the API surface is implemented before relying on it (or just compute distinct yourself):
let distinct: Vec<Value> = {
    let col = table.single_column_table(col_idx).unwrap();
    let mut seen = std::collections::HashSet::new();
    let mut out = Vec::new();
    for v in col.column_values(0) {
        if seen.insert(v.clone()) { out.push(v.clone()); }
    }
    out
};

Try / catch

// isolate the panicking call if you must probe:
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| table.column_distinct(idx)));
// treat Err as "not implemented" and fall back to manual dedup

Prevention

When it happens

Trigger: Calling `table.column_distinct(col_idx)` with any column index on any table; the panic occurs after `single_column_table` succeeds, including for valid indices.

Common situations: Porting agate Python workflows that compute distinct column values (e.g., deduplicated domain lists for macros/tests); building summaries like unique dimension members in dbt-adjacent tooling.

Related errors


AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07). Data as JSON: /api/errors/294e301357a7ab8d. Report an issue: GitHub.