-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Unit tests fail when input contain reserved-word-named columns #10112
Comments
Thanks for reporting this @mpatek ! When I ran your example, I got the same error as you. When I looked at the compiled SQL (in with __dbt__cte__stg as (
-- Fixture for stg
select safe_cast('''a''' as STRING) as id, safe_cast('''2024-01-01''' as DATETIME) as loaded_at, safe_cast(null as INT64) as from
union all
select safe_cast('''a''' as STRING) as id, safe_cast('''2024-01-02''' as DATETIME) as loaded_at, safe_cast(null as INT64) as from
union all
select safe_cast('''a''' as STRING) as id, safe_cast('''2024-01-02''' as DATETIME) as loaded_at, safe_cast(null as INT64) as from
) -- some_model
SELECT id, loaded_at FROM __dbt__cte__stg
qualify row_number() over (partition by id order by loaded_at desc) = 1 And when I copy that compiled output to an analyses file, I get the same error: cp target/compiled/my_project/models/_unit.yml/models/test__some_model.sql analyses
dbt show -s analyses/test__some_model.sql But if I modify that analysis file to have backticks around all the column names, then it can run successfully: with __dbt__cte__stg as (
-- Fixture for stg
select safe_cast('''a''' as STRING) as `id`, safe_cast('''2024-01-01''' as DATETIME) as `loaded_at`, safe_cast(null as INT64) as `from`
union all
select safe_cast('''a''' as STRING) as `id`, safe_cast('''2024-01-02''' as DATETIME) as `loaded_at`, safe_cast(null as INT64) as `from`
union all
select safe_cast('''a''' as STRING) as `id`, safe_cast('''2024-01-02''' as DATETIME) as `loaded_at`, safe_cast(null as INT64) as `from`
) -- some_model
SELECT id, loaded_at FROM __dbt__cte__stg
qualify row_number() over (partition by id order by loaded_at desc) = 1 Output
So I'm wondering if we just need to apply |
@dbeatty10 I think you're right, and I think the right spots might be here and here:
|
|
Closing, since this should proabably be a |
Is this a new bug in dbt-core?
Current Behavior
In BigQuery:
Supposing an input table with a reserved-word-named column like:
And a downstream table like:
And a unit test like:
If I try
dbt test --select test_type:unit
I get:
Syntax error: Unexpected keyword FROM
Expected Behavior
Expect tests to pass without errors.
Steps To Reproduce
from
)Relevant log output
No response
Environment
Which database adapter are you using with dbt?
bigquery
Additional Context
No response
The text was updated successfully, but these errors were encountered: