Skip to content
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] Use qualified names in snowflake__get_rename_x_sql macros #1031

Closed
2 tasks done
jtcohen6 opened this issue May 10, 2024 · 0 comments · Fixed by #1060
Closed
2 tasks done

[Bug] Use qualified names in snowflake__get_rename_x_sql macros #1031

jtcohen6 opened this issue May 10, 2024 · 0 comments · Fixed by #1060
Assignees
Labels
bug Something isn't working dynamic_tables

Comments

@jtcohen6
Copy link
Contributor

jtcohen6 commented May 10, 2024

Is this a new bug in dbt-snowflake?

  • I believe this is a new bug in dbt-snowflake
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

The snowflake__get_rename_x_sql macros are using unqualified names for the rename target. This ultimately led to an error in #1016 — although I'm glad it did, because if it hadn't, it might have masked the real underlying issue, which is that dbt can no longer recognizes dynamic tables based on the output of show terse objects and is full-refreshing them on every run.

Still, I would expect that these macros return:

alter table "ANALYTICS"."DBT_JCOHEN_DEV"."MY_DYNAMIC_TABLE" rename to "ANALYTICS"."DBT_JCOHEN_DEV".MY_DYNAMIC_TABLE__dbt_backup;

Instead:

alter table "ANALYTICS"."DBT_JCOHEN_DEV"."MY_DYNAMIC_TABLE" rename to MY_DYNAMIC_TABLE__dbt_backup;

Expected Behavior

{%- macro snowflake__get_rename_table_sql(relation, new_name) -%}
    alter table {{ relation }} rename to {{ relation.incorporate(path={"identifier": new_name}) }}
{%- endmacro -%}

{%- macro snowflake__get_rename_view_sql(relation, new_name) -%}
    alter view {{ relation }} rename to {{ relation.incorporate(path={"identifier": new_name}) }}
{%- endmacro -%}

Steps To Reproduce

Reproduction case in #1016 — the specific error actually surfaces because the temp relation being dropped (qualified name) does not match the temp relation being created (unqualified name)

Relevant log output

08:31:27  On model.my_dbt_project.foo_2024_03_enabled: /* {"app": "dbt", "dbt_version": "1.7.14", "profile_name": "all", "target_name": "sf", "node_id": "model.my_dbt_project.foo_2024_03_enabled"} */
-- get the standard backup name
    

    -- drop any pre-existing backup
    

    
        drop table if exists "DEVELOPMENT_JYEO"."DBT_JYEO"."FOO_2024_03_ENABLED__dbt_backup" cascade

    

;
08:31:27  Opening a new connection, currently in state closed
08:31:29  SQL status: SUCCESS 1 in 2.0 seconds
08:31:29  Using snowflake connection "model.my_dbt_project.foo_2024_03_enabled"
08:31:29  On model.my_dbt_project.foo_2024_03_enabled: /* {"app": "dbt", "dbt_version": "1.7.14", "profile_name": "all", "target_name": "sf", "node_id": "model.my_dbt_project.foo_2024_03_enabled"} */
alter table "DEVELOPMENT_JYEO"."DBT_JYEO"."FOO_2024_03_ENABLED" rename to FOO_2024_03_ENABLED__dbt_backup;
08:31:29  Snowflake adapter: Snowflake query id: 01b413bf-0804-98fe-000d-3783323f397a
08:31:29  Snowflake adapter: Snowflake error: 002002 (42710): SQL compilation error:
Object 'FOO_2024_03_ENABLED__DBT_BACKUP' already exists.

Environment

- OS: 14.4.1
- Python: 3.10.11
- dbt-core: 1.8.0
- dbt-snowflake: 1.8.0

Additional Context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dynamic_tables
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants