From 7dfbb71bd0bc55026cebafc7937663d98b1c696a Mon Sep 17 00:00:00 2001 From: kaarthik108 Date: Thu, 14 Sep 2023 10:52:46 +1200 Subject: [PATCH 1/8] bug/Dynamic-table-comment-on-syntax --- dbt/include/snowflake/macros/adapters.sql | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dbt/include/snowflake/macros/adapters.sql b/dbt/include/snowflake/macros/adapters.sql index c4afd525b..f7d30dcc0 100644 --- a/dbt/include/snowflake/macros/adapters.sql +++ b/dbt/include/snowflake/macros/adapters.sql @@ -171,7 +171,11 @@ {% endmacro %} {% macro snowflake__alter_relation_comment(relation, relation_comment) -%} - comment on {{ relation.type }} {{ relation }} IS $${{ relation_comment | replace('$', '[$]') }}$$; + {%- set relation_type = relation.type -%} + {%- if relation_type == 'dynamic_table' -%} + {%- set relation_type = 'dynamic table' -%} + {%- endif -%} + comment on {{ relation_type }} {{ relation }} IS $${{ relation_comment | replace('$', '[$]') }}$$; {% endmacro %} From 48d9bf38597fa7009768c7b26b5cbb8bfdb37dde Mon Sep 17 00:00:00 2001 From: kaarthik108 Date: Thu, 14 Sep 2023 11:08:16 +1200 Subject: [PATCH 2/8] Add changelog --- .changes/unreleased/Fixes-20230914-110800.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20230914-110800.yaml diff --git a/.changes/unreleased/Fixes-20230914-110800.yaml b/.changes/unreleased/Fixes-20230914-110800.yaml new file mode 100644 index 000000000..3aa206a73 --- /dev/null +++ b/.changes/unreleased/Fixes-20230914-110800.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Fixing comment on syntax for dynamic tables +time: 2023-09-14T11:08:00.250684+12:00 +custom: + Author: kaarthik108 + Issue: '769' From 9d27f028f40e041b598db6464dfb61381beb1191 Mon Sep 17 00:00:00 2001 From: kaarthik108 Date: Thu, 14 Sep 2023 12:10:47 +1200 Subject: [PATCH 3/8] Fix relation type --- dbt/include/snowflake/macros/adapters.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dbt/include/snowflake/macros/adapters.sql b/dbt/include/snowflake/macros/adapters.sql index f7d30dcc0..db34dd966 100644 --- a/dbt/include/snowflake/macros/adapters.sql +++ b/dbt/include/snowflake/macros/adapters.sql @@ -171,9 +171,10 @@ {% endmacro %} {% macro snowflake__alter_relation_comment(relation, relation_comment) -%} - {%- set relation_type = relation.type -%} - {%- if relation_type == 'dynamic_table' -%} + {%- if relation.is_dynamic_table -%} {%- set relation_type = 'dynamic table' -%} + {%- else -%} + {%- set relation_type = relation.type -%} {%- endif -%} comment on {{ relation_type }} {{ relation }} IS $${{ relation_comment | replace('$', '[$]') }}$$; {% endmacro %} From 248f60953ee97590c8cc3b96568d7c4620bf70fa Mon Sep 17 00:00:00 2001 From: kaarthik108 Date: Thu, 14 Sep 2023 14:15:17 +1200 Subject: [PATCH 4/8] Fix alter --- dbt/include/snowflake/macros/adapters.sql | 26 +++++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/dbt/include/snowflake/macros/adapters.sql b/dbt/include/snowflake/macros/adapters.sql index db34dd966..024c05274 100644 --- a/dbt/include/snowflake/macros/adapters.sql +++ b/dbt/include/snowflake/macros/adapters.sql @@ -182,7 +182,12 @@ {% macro snowflake__alter_column_comment(relation, column_dict) -%} {% set existing_columns = adapter.get_columns_in_relation(relation) | map(attribute="name") | list %} - alter {{ relation.type }} {{ relation }} alter + {% if relation.is_dynamic_table -%} + {% set relation_type = "dynamic table" %} + {% else -%} + {% set relation_type = relation.type %} + {% endif %} + alter {{ relation_type }} {{ relation }} alter {% for column_name in existing_columns if (column_name in existing_columns) or (column_name|lower in existing_columns) %} {{ get_column_comment_sql(column_name, column_dict) }} {{- ',' if not loop.last else ';' }} {% endfor %} @@ -232,10 +237,16 @@ {% macro snowflake__alter_relation_add_remove_columns(relation, add_columns, remove_columns) %} - {% if add_columns %} + {% if relation.is_dynamic_table -%} + {% set relation_type = "dynamic table" %} + {% else -%} + {% set relation_type = relation.type %} + {% endif %} + + {% if add_columns %} {% set sql -%} - alter {{ relation.type }} {{ relation }} add column + alter {{ relation_type }} {{ relation }} add column {% for column in add_columns %} {{ column.name }} {{ column.data_type }}{{ ',' if not loop.last }} {% endfor %} @@ -243,12 +254,12 @@ {% do run_query(sql) %} - {% endif %} + {% endif %} - {% if remove_columns %} + {% if remove_columns %} {% set sql -%} - alter {{ relation.type }} {{ relation }} drop column + alter {{ relation_type }} {{ relation }} drop column {% for column in remove_columns %} {{ column.name }}{{ ',' if not loop.last }} {% endfor %} @@ -256,11 +267,12 @@ {% do run_query(sql) %} - {% endif %} + {% endif %} {% endmacro %} + {% macro snowflake_dml_explicit_transaction(dml) %} {# Use this macro to wrap all INSERT, MERGE, UPDATE, DELETE, and TRUNCATE From edbf91000a9de268410f873c8f7f5617106f4aba Mon Sep 17 00:00:00 2001 From: Pat Kearns Date: Wed, 27 Sep 2023 14:37:05 +0800 Subject: [PATCH 5/8] Update dynamic table comment alter statement --- dbt/include/snowflake/macros/adapters.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dbt/include/snowflake/macros/adapters.sql b/dbt/include/snowflake/macros/adapters.sql index 024c05274..f3de6dc2b 100644 --- a/dbt/include/snowflake/macros/adapters.sql +++ b/dbt/include/snowflake/macros/adapters.sql @@ -172,7 +172,7 @@ {% macro snowflake__alter_relation_comment(relation, relation_comment) -%} {%- if relation.is_dynamic_table -%} - {%- set relation_type = 'dynamic table' -%} + {%- set relation_type = 'table' -%} {%- else -%} {%- set relation_type = relation.type -%} {%- endif -%} @@ -183,7 +183,7 @@ {% macro snowflake__alter_column_comment(relation, column_dict) -%} {% set existing_columns = adapter.get_columns_in_relation(relation) | map(attribute="name") | list %} {% if relation.is_dynamic_table -%} - {% set relation_type = "dynamic table" %} + {% set relation_type = "table" %} {% else -%} {% set relation_type = relation.type %} {% endif %} From 6a3d86e92447e71995a0f15a5dc779ed01b55efa Mon Sep 17 00:00:00 2001 From: kaarthik108 Date: Thu, 28 Sep 2023 11:20:29 +1300 Subject: [PATCH 6/8] update comment on syntax --- dbt/include/snowflake/macros/adapters.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt/include/snowflake/macros/adapters.sql b/dbt/include/snowflake/macros/adapters.sql index f3de6dc2b..b2b496356 100644 --- a/dbt/include/snowflake/macros/adapters.sql +++ b/dbt/include/snowflake/macros/adapters.sql @@ -172,7 +172,7 @@ {% macro snowflake__alter_relation_comment(relation, relation_comment) -%} {%- if relation.is_dynamic_table -%} - {%- set relation_type = 'table' -%} + {%- set relation_type = 'dynamic table' -%} {%- else -%} {%- set relation_type = relation.type -%} {%- endif -%} From 70c97e2d35fb9ea358eb04c1059fc453242a695b Mon Sep 17 00:00:00 2001 From: kaarthik108 Date: Mon, 2 Oct 2023 14:47:11 +1300 Subject: [PATCH 7/8] Update changie --- .changes/unreleased/Fixes-20231002-144648.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20231002-144648.yaml diff --git a/.changes/unreleased/Fixes-20231002-144648.yaml b/.changes/unreleased/Fixes-20231002-144648.yaml new file mode 100644 index 000000000..6acb28c8a --- /dev/null +++ b/.changes/unreleased/Fixes-20231002-144648.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Fix the alter syntax on column for dynamic table +time: 2023-10-02T14:46:48.980242+13:00 +custom: + Author: kaarthik108 + Issue: "769" From 7184cd5642775214ebd197ec0a920c3a054aca75 Mon Sep 17 00:00:00 2001 From: kaarthik108 Date: Wed, 11 Oct 2023 13:43:56 +1300 Subject: [PATCH 8/8] Removed old changelog --- .changes/unreleased/Fixes-20230914-110800.yaml | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .changes/unreleased/Fixes-20230914-110800.yaml diff --git a/.changes/unreleased/Fixes-20230914-110800.yaml b/.changes/unreleased/Fixes-20230914-110800.yaml deleted file mode 100644 index 3aa206a73..000000000 --- a/.changes/unreleased/Fixes-20230914-110800.yaml +++ /dev/null @@ -1,6 +0,0 @@ -kind: Fixes -body: Fixing comment on syntax for dynamic tables -time: 2023-09-14T11:08:00.250684+12:00 -custom: - Author: kaarthik108 - Issue: '769'