-
Notifications
You must be signed in to change notification settings - Fork 146
Description
Is this a new bug?
- I believe this is a new bug
- I have searched the existing issues, and I could not find an existing issue for this bug
Which packages are affected?
- dbt-adapters
- dbt-tests-adapter
- dbt-athena
- dbt-athena-community
- dbt-bigquery
- dbt-postgres
- dbt-redshift
- dbt-snowflake
- dbt-spark
Current Behavior
dbt codegen's generate_source
macro fails as one of my table is named "GROUP". When the adapter.get_columns_in_relation(table_relation)
function is called (here), the snowflake__get_columns_in_relation
macro generates the sql to describe a table as :
{%- set sql -%}
describe table {{ relation.render() }}
{%- endset -%}
which causes an error on snowflake side because one my table makes it generate this statement :
describe table MY_DATABASE.RAW_SOURCE.GROUP
Expected Behavior
The snowflake__get_columns_in_relation
macro would account for this problem in some way to avoid the error.
Steps To Reproduce
- Have a Snowflake database and schema with normal name (that does not interfere with snowflake) and a table named "GROUP"
- Try to execute "describe table <database_name>.<schema_name>.GROUP" in Snowflake, it should fail
- Have a dbt project using
dbt-labs/codegen version 0.13.1
- Try to run
dbt run-operation generate_source --args '{"schema_name": "<SCHEMA_NAME>", "database_name": "<DATABASE_NAME>", "generate_columns": true, "include_descriptions": true, "include_schema": true, "name": "<source_name>"}'
, it should fail
Relevant log output
Environment
- OS: Ubuntu 24.04.3 LTS (Under WSL2)
- Python: 3.12.3
- dbt : 1.10.11
- dbt-adapters: 1.10.1
- dbt-snowflake: 1.10.1
Additional Context
I found a fix that works for me, maybe it can be useful for you and it's not that bad of a solution idk 😅
It seems that simply using the identifier
function of Snowflake (docs) fixes the problem.
I copied the generate_source.sql
macro out of codegen in my macros.
Copy-pasted the snowflake__get_columns_in_relation
macro in the generate_source.sql
Inside the snowflake__get_columns_in_relation
, I changed
{%- set sql -%}
describe table {{ relation.render() }}
{%- endset -%}
to
{%- set sql -%}
describe table identifier('{{ relation.render() }}')
{%- endset -%}