-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6129705
commit b0d8ff0
Showing
52 changed files
with
1,723 additions
and
534 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{%- macro concat_ws(string_list, separator="||") -%} | ||
|
||
{{- adapter.dispatch('concat_ws', 'dbtvault')(string_list=string_list, separator=separator) -}} | ||
|
||
{%- endmacro %} | ||
|
||
{%- macro default__concat_ws(string_list, separator="||") -%} | ||
|
||
{{ "CONCAT_WS('" ~ separator ~ "', " ~ string_list | join(", ") ~ ")" }} | ||
|
||
{%- endmacro -%} | ||
|
||
{%- macro bigquery__concat_ws(string_list, separator="||") -%} | ||
|
||
{{- 'CONCAT(' -}} | ||
{%- for str in string_list -%} | ||
{{- "{}".format(str) -}} | ||
{{- ",'{}',".format(separator) if not loop.last -}} | ||
{%- endfor -%} | ||
{{- '\n)' -}} | ||
|
||
{%- endmacro -%} |
133 changes: 133 additions & 0 deletions
133
macros/internal/metadata_processing/escape_column_names.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
{%- macro escape_column_names(columns=none) -%} | ||
|
||
{# Different platforms use different escape characters, the default below is for Snowflake which uses double quotes #} | ||
|
||
{%- if dbtvault.is_something(columns) -%} | ||
|
||
{%- set col_string = '' -%} | ||
{%- set col_list = [] -%} | ||
{%- set col_mapping = {} -%} | ||
|
||
{%- if columns is string -%} | ||
|
||
{%- set col_string = dbtvault.escape_column_name(columns) -%} | ||
|
||
{%- elif dbtvault.is_list(columns) -%} | ||
|
||
{%- for col in columns -%} | ||
|
||
{%- if col is string -%} | ||
|
||
{%- set escaped_col = dbtvault.escape_column_name(col) -%} | ||
|
||
{%- do col_list.append(escaped_col) -%} | ||
|
||
{%- else -%} | ||
|
||
{%- if execute -%} | ||
{{- exceptions.raise_compiler_error("Invalid column name(s) provided. Must be a string.") -}} | ||
{%- endif -%} | ||
|
||
{%- endif -%} | ||
|
||
{%- endfor -%} | ||
|
||
{%- elif columns is mapping -%} | ||
|
||
{%- if columns['source_column'] and columns['alias'] -%} | ||
|
||
{%- set escaped_source_col = dbtvault.escape_column_name(columns['source_column']) -%} | ||
{%- set escaped_alias_col = dbtvault.escape_column_name(columns['alias']) -%} | ||
{%- set col_mapping = {"source_column": escaped_source_col, "alias": escaped_alias_col} -%} | ||
|
||
{%- else -%} | ||
|
||
{%- if execute -%} | ||
{{- exceptions.raise_compiler_error("Invalid column name(s) provided. Must be a string, a list of strings, or a dictionary of hashdiff metadata.") -}} | ||
{%- endif %} | ||
|
||
{%- endif -%} | ||
|
||
{%- else -%} | ||
|
||
{%- if execute -%} | ||
{{- exceptions.raise_compiler_error("Invalid column name(s) provided. Must be a string, a list of strings, or a dictionary of hashdiff metadata.") -}} | ||
{%- endif %} | ||
|
||
{%- endif -%} | ||
|
||
{%- elif columns == '' -%} | ||
|
||
{%- if execute -%} | ||
{{- exceptions.raise_compiler_error("Expected a column name or a list of column names, got an empty string") -}} | ||
{%- endif -%} | ||
|
||
{%- endif -%} | ||
|
||
{%- if columns is none -%} | ||
|
||
{%- do return(none) -%} | ||
|
||
{%- elif columns == [] -%} | ||
|
||
{%- do return([]) -%} | ||
|
||
{%- elif columns == {} -%} | ||
|
||
{%- do return({}) -%} | ||
|
||
{%- elif columns is string -%} | ||
|
||
{%- do return(col_string) -%} | ||
|
||
{%- elif dbtvault.is_list(columns) -%} | ||
|
||
{%- do return(col_list) -%} | ||
|
||
{%- elif columns is mapping -%} | ||
|
||
{%- do return(col_mapping) -%} | ||
|
||
{%- endif -%} | ||
|
||
{%- endmacro -%} | ||
|
||
|
||
{%- macro escape_column_name(column) -%} | ||
|
||
{{- adapter.dispatch('escape_column_name', 'dbtvault')(column=column) -}} | ||
|
||
{%- endmacro %} | ||
|
||
{%- macro default__escape_column_name(column) -%} | ||
|
||
{%- set escape_char_left = var('escape_char_left', '"') -%} | ||
{%- set escape_char_right = var('escape_char_right', '"') -%} | ||
|
||
{%- set escaped_column_name = escape_char_left ~ column | replace(escape_char_left, '') | replace(escape_char_right, '') | trim ~ escape_char_right -%} | ||
|
||
{%- do return(escaped_column_name) -%} | ||
|
||
{%- endmacro -%} | ||
|
||
{%- macro sqlserver__escape_column_name(column) -%} | ||
|
||
{%- set escape_char_left = var('escape_char_left', '"') -%} | ||
{%- set escape_char_right = var('escape_char_right', '"') -%} | ||
|
||
{%- set escaped_column_name = escape_char_left ~ column | replace(escape_char_left, '') | replace(escape_char_right, '') | trim ~ escape_char_right -%} | ||
|
||
{%- do return(escaped_column_name) -%} | ||
|
||
{%- endmacro -%} | ||
|
||
{%- macro bigquery__escape_column_name(column) -%} | ||
|
||
{%- set escape_char_left = var('escape_char_left', '`') -%} | ||
{%- set escape_char_right = var('escape_char_right', '`') -%} | ||
|
||
{%- set escaped_column_name = escape_char_left ~ column | replace(escape_char_left, '') | replace(escape_char_right, '') | trim ~ escape_char_right -%} | ||
|
||
{%- do return(escaped_column_name) -%} | ||
|
||
{%- endmacro -%} |
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
66 changes: 35 additions & 31 deletions
66
macros/materialisations/incremental_bridge_materialization.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,57 @@ | ||
{% materialization bridge_incremental, default -%} | ||
{%- materialization bridge_incremental, default -%} | ||
|
||
{% set full_refresh_mode = flags.FULL_REFRESH %} | ||
{%- set full_refresh_mode = should_full_refresh() -%} | ||
|
||
{% set target_relation = this %} | ||
{% set existing_relation = load_relation(this) %} | ||
{% set tmp_relation = make_temp_relation(this) %} | ||
{% if target.type == "sqlserver" %} | ||
{%- set target_relation = this.incorporate(type='table') -%} | ||
{% else %} | ||
{%- set target_relation = this -%} | ||
{% endif %} | ||
{%- set existing_relation = load_relation(this) -%} | ||
{%- set tmp_relation = make_temp_relation(target_relation) -%} | ||
|
||
{{ run_hooks(pre_hooks, inside_transaction=False) }} | ||
|
||
-- `BEGIN` happens here: | ||
{{ run_hooks(pre_hooks, inside_transaction=True) }} | ||
|
||
{% set to_drop = [] %} | ||
{% if existing_relation is none %} | ||
{% set build_sql = create_table_as(False, target_relation, sql) %} | ||
{% elif existing_relation.is_view or full_refresh_mode %} | ||
{%- set to_drop = [] -%} | ||
{%- if existing_relation is none -%} | ||
{%- set build_sql = create_table_as(False, target_relation, sql) -%} | ||
{%- elif existing_relation.is_view or full_refresh_mode -%} | ||
{#-- Make sure the backup doesn't exist so we don't encounter issues with the rename below #} | ||
{% set backup_identifier = existing_relation.identifier ~ "__dbt_backup" %} | ||
{% set backup_relation = existing_relation.incorporate(path={"identifier": backup_identifier}) %} | ||
{% do adapter.drop_relation(backup_relation) %} | ||
|
||
{% do adapter.rename_relation(target_relation, backup_relation) %} | ||
{% set build_sql = create_table_as(False, target_relation, sql) %} | ||
{% do to_drop.append(backup_relation) %} | ||
{% else %} | ||
|
||
{% set tmp_relation = make_temp_relation(target_relation) %} | ||
{% do run_query(create_table_as(True, tmp_relation, sql)) %} | ||
{% do adapter.expand_target_column_types( | ||
{%- set backup_identifier = existing_relation.identifier ~ "__dbt_backup" -%} | ||
{%- set backup_relation = existing_relation.incorporate(path={"identifier": backup_identifier}) -%} | ||
{%- do adapter.drop_relation(backup_relation) -%} | ||
|
||
{%- do adapter.rename_relation(target_relation, backup_relation) -%} | ||
{%- set build_sql = create_table_as(False, target_relation, sql) -%} | ||
{%- do to_drop.append(backup_relation) -%} | ||
{%- else -%} | ||
|
||
{%- set tmp_relation = make_temp_relation(target_relation) -%} | ||
{%- do run_query(create_table_as(True, tmp_relation, sql)) -%} | ||
{%- do adapter.expand_target_column_types( | ||
from_relation=tmp_relation, | ||
to_relation=target_relation) %} | ||
{% set build_sql = dbtvault.incremental_bridge_replace(tmp_relation, target_relation) %} | ||
{% endif %} | ||
to_relation=target_relation) -%} | ||
{%- set build_sql = dbtvault.incremental_bridge_replace(tmp_relation, target_relation) -%} | ||
{%- endif -%} | ||
|
||
{% call statement("main") %} | ||
{%- call statement("main") -%} | ||
{{ build_sql }} | ||
{% endcall %} | ||
{%- endcall -%} | ||
|
||
{{ run_hooks(post_hooks, inside_transaction=True) }} | ||
|
||
-- `COMMIT` happens here | ||
{% do adapter.commit() %} | ||
{%- do adapter.commit() -%} | ||
|
||
{% for rel in to_drop %} | ||
{% do adapter.drop_relation(rel) %} | ||
{% endfor %} | ||
{%- for rel in to_drop -%} | ||
{%- do adapter.drop_relation(rel) -%} | ||
{%- endfor -%} | ||
|
||
{{ run_hooks(post_hooks, inside_transaction=False) }} | ||
|
||
{{ return({'relations': [target_relation]}) }} | ||
|
||
{%- endmaterialization %} | ||
{%- endmaterialization -%} |
Oops, something went wrong.