You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched the existing issues, and I could not find an existing issue for this bug
Current Behavior
The CTE that contains the input data seems to follow this format select safe_cast(<value> as <data type>) as <column name>,
For example,
safe_cast('''compact'''as STRING) as group
Expected Behavior
The CTE should escape the column names. For example, (in BigQuery):
safe_cast('''compact'''as STRING) as`group`
Steps To Reproduce
Running with dbt=1.8.8
Registered adapter: bigquery=1.8.3
Create a source dataset/table that uses reserved words as a column name:
create or replacetablevehicles.cars as (
select1as id, 'compact'as`group`
)
models/src_vehicles.yaml
sources:
- name: vehiclestables:
- name: carscolumns:
- name: id
- name: group
Create a model that utilizes the source:
models/cars_by_group.sql
with cars as (
select*from {{ source('vehicles', 'cars') }}
),
count_by_group as (
select
group,
count(*) as count,
from cars
)
select*from count_by_group
Run the test dbt test -s test_count_of_cars_by_group
Inspect the SQL
select * from (
with __dbt__cte__cars as (
-- Fixture for cars
select safe_cast(1 as INT64) as id, safe_cast('''compact''' as STRING) as group
union all
select safe_cast(2 as INT64) as id, safe_cast('''compact''' as STRING) as group
union all
select safe_cast(3 as INT64) as id, safe_cast('''midsize''' as STRING) as group
union all
select safe_cast(4 as INT64) as id, safe_cast('''suv''' as STRING) as group
union all
select safe_cast(5 as INT64) as id, safe_cast('''suv''' as STRING) as group
union all
select safe_cast(6 as INT64) as id, safe_cast('''suv''' as STRING) as group
), cars as (
select * from __dbt__cte__cars
),
Relevant log output
21:38:54 Runtime Error in unit_test test_count_of_cars_by_group (models/etl/splits_and_stats/splits_and_stats.yml)
An error occurred during execution of unit test'test_count_of_cars_by_group'. There may be an error in the unit test definition: check the data types.
Database Error
Syntax error: Unexpected keyword GROUP at [20:75]
Is this a new bug in dbt-core?
Current Behavior
The CTE that contains the input data seems to follow this format
select safe_cast(<value> as <data type>) as <column name>,
For example,
Expected Behavior
The CTE should escape the column names. For example, (in BigQuery):
Steps To Reproduce
models/src_vehicles.yaml
models/cars_by_group.sql
models/_properties.yml
Run the test
dbt test -s test_count_of_cars_by_group
Inspect the SQL
Relevant log output
Environment
Which database adapter are you using with dbt?
bigquery
Additional Context
Might be similar to:
The text was updated successfully, but these errors were encountered: