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/Dynamic-table-comment-on-syntax #1

Merged
merged 5 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230914-110800.yaml
Original file line number Diff line number Diff line change
@@ -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'
33 changes: 25 additions & 8 deletions dbt/include/snowflake/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,23 @@
{% endmacro %}

{% macro snowflake__alter_relation_comment(relation, relation_comment) -%}
comment on {{ relation.type }} {{ relation }} IS $${{ relation_comment | replace('$', '[$]') }}$$;
{%- if relation.is_dynamic_table -%}
{%- set relation_type = 'table' -%}
{%- else -%}
{%- set relation_type = relation.type -%}
{%- endif -%}
comment on {{ relation_type }} {{ relation }} IS $${{ relation_comment | replace('$', '[$]') }}$$;
{% endmacro %}


{% 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 = "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 %}
Expand Down Expand Up @@ -227,35 +237,42 @@

{% 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 %}
{%- endset -%}

{% 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 %}
{%- endset -%}

{% 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
Expand Down