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

alter-table statements during incremental run leads to potential errors on Snowflake #1687

Closed
1 task done
githoov opened this issue Aug 16, 2019 · 2 comments · Fixed by #1690
Closed
1 task done
Labels
bug Something isn't working
Milestone

Comments

@githoov
Copy link

githoov commented Aug 16, 2019

Describe the bug

For incremental models, DBT generates the following:

alter table <table> add column <col>__dbt_alter character varying(17);

update <table> set <col>__dbt_alter = <col>;

alter table <table> drop column <col> cascade;

to accommodate expanding characters in existing columns. This is necessary for Redshift, but Snowflake this is not necessary, as the string data type automatically adjusts depending on the data in the table.

In some sense, this could even be thought of as a bug, as this series of commands will fail if the dropped column is part of the cluster key in the table, leading to a failed run.

Steps To Reproduce

This is baked into an incremental run of DBT.

System information

  • snowflake

The output of dbt --version:

installed version: 0.14.0
   latest version: 0.14.0
@githoov githoov added bug Something isn't working triage labels Aug 16, 2019
@drewbanin drewbanin removed the triage label Aug 16, 2019
@drewbanin drewbanin added this to the 0.14.1 milestone Aug 16, 2019
@drewbanin
Copy link
Contributor

Thanks for the report @githoov - we'll check it out

drewbanin added a commit that referenced this issue Aug 20, 2019
…-on-snowflake

(#1687) no-op column expansion on Snowflake + BQ
@drewbanin
Copy link
Contributor

fixed in #1690

Note: column expansion is still necessary on Snowflake, but we can leverage a statement like:

alter table {{ relation }} alter {{ column_name }} set data type {{ new_column_type }};

This has the benefit of being atomic, simple, and presumably a lot faster than the existing approach:

    alter table {{ relation }} add column {{ tmp_column }} {{ new_column_type }};
    update {{ relation }} set {{ tmp_column }} = {{ column_name }};
    alter table {{ relation }} drop column {{ column_name }} cascade;
    alter table {{ relation }} rename column {{ tmp_column }} to {{ column_name }}

This should also work around the problem noted in this issue: a column in a clustering key cannot be dropped, but it can have its type changed from eg. varchar(12) to varchar(36).

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

Successfully merging a pull request may close this issue.

2 participants