#16549·dbt-core

[BigQuery] Ingestion-time partitioned tables generate invalid CREATE TABLE DDL for STRUCT columns

Author: dandres2929Created Oct 1, 2026Updated Oct 1, 2026
Labelstriage

Current Behavior

For BigQuery models configured with ingestion-time partitioning (partition_by: {..., time_ingestion_partitioning: true}), the generated CREATE TABLE DDL for STRUCT columns is invalid.

The code path is:

  • bigquery__create_table_as (crates/dbt-loader/src/dbt_macro_assets/dbt-bigquery/macros/adapters.sql), inside the {% if partition_config.time_ingestion_partitioning %} branch, calls
  • get_columns_with_types_in_query_sql (macros/materializations/incremental_strategy/time_ingestion_tables.sql), which calls
  • adapter.get_columns_in_select_sql(sql), and renders quote(col.name) ~ " " ~ col.data_type into the CREATE TABLE column list.

In crates/dbt-adapter/src/adapter/adapter_impl.rs, the BigQuery arm of get_columns_in_select_sql delegates to get_column_schema_from_query, which flattens STRUCT columns into dotted leaf columns (e.g. a struct s with fields a, b becomes s.a, s.b).

This produces invalid DDL column entries such as:

`s.a` INT64, `s.b` STRING

instead of a single, correctly nested column definition for s.

Note: this was identified by code inspection of the Fusion engine source (not yet confirmed end-to-end against a live BigQuery run), so the exact DDL error text above is illustrative of what the code generates, not a captured runtime error message.

Expected Behavior

For a top-level STRUCT column, get_columns_in_select_sql should return a single, unflattened column entry per top-level field, matching the behavior of the dbt-bigquery v1 Python adapter's get_columns_in_select_sql, e.g.:

`s` STRUCT<`a` INT64, `b` STRING>

Regular (non-partitioned) tables, column-partitioned tables, and other incremental strategies are unaffected — this only impacts the ingestion-time partitioning CREATE TABLE path.

Steps To Reproduce

  1. Create a BigQuery incremental model configured with ingestion-time partitioning and a top-level STRUCT column:
sql
{{ config(
    materialized='incremental',
    incremental_strategy='insert_overwrite',
    partition_by={'field': '_partitiontime', 'data_type': 'timestamp', 'granularity': 'day', 'time_ingestion_partitioning': true}
) }}

select
  struct(1 as a, 'x' as b) as s,
  timestamp_trunc(current_timestamp(), day) as _partitiontime
  1. Run dbt build (first run, table creation path).
  2. The bigquery__create_table_as macro builds its CREATE TABLE column list via get_columns_with_types_in_query_sql → adapter.get_columns_in_select_sql(sql).
  3. Because the BigQuery arm of get_columns_in_select_sql delegates to get_column_schema_from_query, the STRUCT column s is flattened into dotted leaf columns (s.a, s.b) instead of being kept as a single nested STRUCT column, producing an invalid column list for the CREATE TABLE statement.

Environment

  • dbt distribution and version: dbt Fusion (v2)
  • Adapter: bigquery

Is this a discrepancy vs. dbt 1.x?

  • Yes — this works in dbt 1.x but not in dbt v2.x (the dbt-bigquery v1 Python adapter's get_columns_in_select_sql returns unflattened top-level columns; see link above)

Additional Context

  • Fix PR: #16548