dbt-labs/dbt-core · error

'flatten' is only implemented for Bigquery

Error message

'flatten' is only implemented for Bigquery

What it means

flatten() expands a nested (RECORD/STRUCT) BigQuery column into a flat list of leaf columns, mirroring dbt-bigquery's BigQueryColumn.flatten(). Because nested-column flattening only exists for BigQuery's type system, the method panics with unimplemented!() for every other adapter type before delegating to _bq_flatten_inner.

Solutions

  1. Guard the call on adapter type: {% if adapter.type() == 'bigquery' %} before flattening.
  2. For other warehouses, iterate the column list directly or handle nested types with platform-native mechanisms (e.g. Snowflake VARIANT / Redshift SUPER accessors).
  3. If BigQuery flattening is intended, ensure columns were constructed with the BigQuery adapter type set (AdapterType::Bigquery).

Example fix

// before
let flat = column.flatten();

// after
let flat = if matches!(column.adapter_type(), AdapterType::Bigquery) {
    column.flatten()
} else {
    vec![column.clone()]
};
Defensive patterns

Strategy: validation

Validate before calling

if adapter_type != AdapterType::Bigquery { /* do not flatten; handle nested types per platform */ }

Type guard

fn is_bigquery(t: &AdapterType) -> bool { *t == AdapterType::Bigquery }

Prevention

When it happens

Trigger: Calling DbtColumn::flatten() on a column whose _adapter_type is not AdapterType::Bigquery — typically from a Jinja macro doing flatten_column or nested field traversal on another warehouse.

Common situations: Copying dbt-bigquery macros that flatten STRUCT columns into a Snowflake/Redshift/Databricks project; processing columns loaded from a non-BigQuery relation with a BigQuery-specific code path; unit tests using default (non-BigQuery) adapter type.

Related errors


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

Appendix: source

Thrown at crates/dbt-adapter/src/column/types.rs:1148

                new_prefix,
                original_sql_str,
                &[],
                self.mode(),
            )])
        } else {
            let mut new_fields = Vec::new();
            for f in &self._fields {
                let mut flatten_f = f._bq_flatten_inner(&new_prefix);
                new_fields.append(&mut flatten_f);
            }
            new_fields
        }
    }

    /// https://github.com/dbt-labs/dbt-adapters/blob/c16cc7047e8678f8bb88ae294f43da2c68e9f5cc/dbt-bigquery/src/dbt/adapters/bigquery/column.py#L69
    pub fn flatten(&self) -> Vec<Self> {
        if !matches!(self._adapter_type, AdapterType::Bigquery) {
            unimplemented!("'flatten' is only implemented for Bigquery")
        }

        self._bq_flatten_inner("")
    }

    pub fn fields(&self) -> &[Self] {
        &self._fields
    }
}

impl Object for Column {
    fn call_method(
        self: &Arc<Self>,
        _state: &minijinja::State,
        name: &str,
        args: &[Value],
        _listeners: &[std::rc::Rc<dyn minijinja::listener::RenderingEventListener>],
    ) -> Result<Value, minijinja::Error> {

View on GitHub (pinned to 0267ce9170)