[BigQuery] Ingestion-time partitioned tables generate invalid CREATE TABLE DDL for STRUCT columns
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, callsget_columns_with_types_in_query_sql(macros/materializations/incremental_strategy/time_ingestion_tables.sql), which callsadapter.get_columns_in_select_sql(sql), and rendersquote(col.name) ~ " " ~ col.data_typeinto 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` STRINGinstead 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
- Create a BigQuery incremental model configured with ingestion-time partitioning and a top-level
STRUCTcolumn:
{{ 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- Run
dbt build(first run, table creation path). - The
bigquery__create_table_asmacro builds itsCREATE TABLEcolumn list viaget_columns_with_types_in_query_sql→adapter.get_columns_in_select_sql(sql). - Because the BigQuery arm of
get_columns_in_select_sqldelegates toget_column_schema_from_query, theSTRUCTcolumnsis flattened into dotted leaf columns (s.a,s.b) instead of being kept as a single nestedSTRUCTcolumn, producing an invalid column list for theCREATE TABLEstatement.
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_sqlreturns unflattened top-level columns; see link above)
Additional Context
- Fix PR: #16548
Source: dbt-labs/dbt-core