Skip to content

Commit 8379d10

Browse files
committed
Release v0.9.0
1 parent a86d2b9 commit 8379d10

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1947
-1791
lines changed

dbt_project.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: dbtvault
2-
version: 0.8.3
2+
version: 0.9.0
33
require-dbt-version: [">=1.0.0", "<2.0.0"]
44
config-version: 2
55

@@ -17,4 +17,5 @@ clean-targets:
1717

1818
vars:
1919
hash: MD5
20-
max_datetime: '{{ dbtvault.max_datetime() }}'
20+
null_key_required: '-1' # Default -1, allows user to configure
21+
null_key_optional: '-2' # Default -2, allows user to configure

macros/internal/helpers/is_checks.sql

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
{%- macro is_nothing(obj) -%}
1818

19-
{%- if obj is none or obj is undefined or not obj -%}
19+
{%- if obj is none or obj is undefined or not obj or dbtvault.is_list(obj, empty_is_false=true) -%}
2020
{%- do return(true) -%}
2121
{%- else -%}
2222
{%- do return(false) -%}
@@ -29,7 +29,12 @@
2929
{%- macro is_something(obj) -%}
3030

3131
{%- if obj is not none and obj is defined and obj -%}
32-
{%- do return(true) -%}
32+
{#- if an empty list, do not consider the object something -#}
33+
{% if dbtvault.is_list(empty_is_false=true) %}
34+
{%- do return(true) -%}
35+
{%- else -%}
36+
{%- do return(false) -%}
37+
{%- endif -%}
3338
{%- else -%}
3439
{%- do return(false) -%}
3540
{%- endif -%}
@@ -50,4 +55,4 @@
5055
{%- do return(false) -%}
5156
{%- endif -%}
5257

53-
{%- endmacro -%}
58+
{%- endmacro -%}

macros/internal/helpers/logging.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{% macro log_relation_sources(relation, source_count) %}
2+
{{ return(adapter.dispatch('log_relation_sources', 'dbtvault')(relation=relation, source_count=source_count)) }}
3+
{%- endmacro -%}
4+
5+
{% macro default__log_relation_sources(relation, source_count) %}
6+
7+
{%- if execute -%}
8+
9+
{%- do dbt_utils.log_info('Loading {} from {} source(s)'.format("{}.{}.{}".format(relation.database, relation.schema, relation.identifier),
10+
source_count)) -%}
11+
{%- endif -%}
12+
{% endmacro %}
13+
14+
{% macro databricks__log_relation_sources(relation, source_count) %}
15+
16+
{%- if execute -%}
17+
18+
{%- do dbt_utils.log_info('Loading {} from {} source(s)'.format("{}.{}".format(relation.schema, relation.identifier),
19+
source_count)) -%}
20+
{%- endif -%}
21+
{% endmacro %}

macros/internal/helpers/stage_processing_macros.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,30 @@
9090
{%- endfor -%}
9191

9292
{%- endmacro -%}
93+
94+
95+
{%- macro extract_null_column_names(columns_dict=none) -%}
96+
97+
{%- set extracted_column_names = [] -%}
98+
99+
{%- if columns_dict is mapping -%}
100+
{%- for key, value in columns_dict.items() -%}
101+
{%- if dbtvault.is_something(value) -%}
102+
{% if dbtvault.is_list(value) %}
103+
{% for col_name in value %}
104+
{%- do extracted_column_names.append(col_name) -%}
105+
{%- do extracted_column_names.append(col_name ~ "_ORIGINAL") -%}
106+
{% endfor %}
107+
{% else %}
108+
{%- do extracted_column_names.append(value) -%}
109+
{%- do extracted_column_names.append(value ~ "_ORIGINAL") -%}
110+
{% endif %}
111+
{%- endif -%}
112+
{%- endfor -%}
113+
114+
{%- do return(extracted_column_names) -%}
115+
{%- else -%}
116+
{%- do return([]) -%}
117+
{%- endif -%}
118+
119+
{%- endmacro -%}

macros/internal/metadata_processing/as_constant.sql

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,7 @@
1414

1515
{%- else -%}
1616

17-
{%- if dbtvault.is_expression(column_str) -%}
18-
19-
{{- return(column_str) -}}
20-
21-
{%- else -%}
22-
23-
{{- return(dbtvault.escape_column_names(column_str)) -}}
24-
25-
{%- endif -%}
17+
{{- return(column_str) -}}
2618

2719
{%- endif -%}
2820
{%- else -%}

macros/internal/metadata_processing/concat_ws.sql

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
{%- macro default__concat_ws(string_list, separator="||") -%}
88

9-
{{ "CONCAT_WS('" ~ separator ~ "', " ~ string_list | join(", ") ~ ")" }}
9+
CONCAT_WS('{{ separator }}', {{ string_list | join(", ") }})
1010

1111
{%- endmacro -%}
1212

@@ -19,4 +19,10 @@
1919
{%- endfor -%}
2020
{{- '\n)' -}}
2121

22-
{%- endmacro -%}
22+
{%- endmacro -%}
23+
24+
{%- macro sqlserver__concat_ws(string_list, separator="||") -%}
25+
26+
{{ dbtvault.default__concat_ws(string_list=string_list, separator=separator) }}
27+
28+
{%- endmacro -%}

macros/internal/metadata_processing/escape_column_names.sql

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{%- macro escape_column_names(columns=none) -%}
22

3-
{# Different platforms use different escape characters, the default below is for Snowflake which uses double quotes #}
3+
{%- if dbtvault.is_list(columns) -%}
4+
{%- set columns = dbtvault.expand_column_list(columns) -%}
5+
{%- endif -%}
46

57
{%- if dbtvault.is_something(columns) -%}
68

@@ -64,31 +66,31 @@
6466

6567
{%- endif -%}
6668

67-
{%- if columns is none -%}
69+
{%- if columns is none -%}
6870

69-
{%- do return(none) -%}
71+
{%- do return(none) -%}
7072

71-
{%- elif columns == [] -%}
73+
{%- elif columns == [] -%}
7274

73-
{%- do return([]) -%}
75+
{%- do return([]) -%}
7476

75-
{%- elif columns == {} -%}
77+
{%- elif columns == {} -%}
7678

77-
{%- do return({}) -%}
79+
{%- do return({}) -%}
7880

79-
{%- elif columns is string -%}
81+
{%- elif columns is string -%}
8082

81-
{%- do return(col_string) -%}
83+
{%- do return(col_string) -%}
8284

83-
{%- elif dbtvault.is_list(columns) -%}
85+
{%- elif dbtvault.is_list(columns) -%}
8486

85-
{%- do return(col_list) -%}
87+
{%- do return(col_list) -%}
8688

87-
{%- elif columns is mapping -%}
89+
{%- elif columns is mapping -%}
8890

89-
{%- do return(col_mapping) -%}
91+
{%- do return(col_mapping) -%}
9092

91-
{%- endif -%}
93+
{%- endif -%}
9294

9395
{%- endmacro -%}
9496

@@ -101,33 +103,44 @@
101103

102104
{%- macro default__escape_column_name(column) -%}
103105

104-
{%- set escape_char_left = var('escape_char_left', '"') -%}
105-
{%- set escape_char_right = var('escape_char_right', '"') -%}
106+
{# Do not escape a constant (single quoted) value #}
107+
{%- if column | first == "'" and column | last == "'" -%}
108+
{%- set escaped_column_name = column -%}
109+
{%- else -%}
110+
{%- set escape_char_default_left, escape_char_default_right = dbtvault.get_escape_characters() -%}
111+
{%- set escape_char_left = var('escape_char_left', escape_char_default_left) -%}
112+
{%- set escape_char_right = var('escape_char_right', escape_char_default_right) -%}
106113

107-
{%- set escaped_column_name = escape_char_left ~ column | replace(escape_char_left, '') | replace(escape_char_right, '') | trim ~ escape_char_right -%}
114+
{%- set escaped_column_name = escape_char_left ~ column | replace(escape_char_left, '') | replace(escape_char_right, '') | trim ~ escape_char_right -%}
115+
{%- endif -%}
108116

109117
{%- do return(escaped_column_name) -%}
110118

111119
{%- endmacro -%}
112120

113-
{%- macro sqlserver__escape_column_name(column) -%}
114-
115-
{%- set escape_char_left = var('escape_char_left', '"') -%}
116-
{%- set escape_char_right = var('escape_char_right', '"') -%}
121+
{% macro get_escape_characters() -%}
117122

118-
{%- set escaped_column_name = escape_char_left ~ column | replace(escape_char_left, '') | replace(escape_char_right, '') | trim ~ escape_char_right -%}
123+
{% do return(adapter.dispatch('get_escape_characters', 'dbtvault')()) -%}
119124

120-
{%- do return(escaped_column_name) -%}
121-
122-
{%- endmacro -%}
125+
{%- endmacro %}
123126

124-
{%- macro bigquery__escape_column_name(column) -%}
127+
{%- macro snowflake__get_escape_characters() %}
128+
{%- do return (('"', '"')) -%}
129+
{%- endmacro %}
125130

126-
{%- set escape_char_left = var('escape_char_left', '`') -%}
127-
{%- set escape_char_right = var('escape_char_right', '`') -%}
131+
{%- macro bigquery__get_escape_characters() %}
132+
{%- do return (('`', '`')) -%}
133+
{%- endmacro %}
128134

129-
{%- set escaped_column_name = escape_char_left ~ column | replace(escape_char_left, '') | replace(escape_char_right, '') | trim ~ escape_char_right -%}
135+
{%- macro sqlserver__get_escape_characters() %}
136+
{%- do return (('"', '"')) -%}
137+
{%- endmacro %}
130138

131-
{%- do return(escaped_column_name) -%}
139+
{%- macro databricks__get_escape_characters() %}
140+
{%- do return (('`', '`')) -%}
141+
{%- endmacro %}
132142

133-
{%- endmacro -%}
143+
{%- macro postgres__get_escape_characters() %}
144+
{#- DO NOT QUOTE FOR NOW. Postgres has a "feature" which froces explicit casing and breaks the SQL-92 standard -#}
145+
{%- do return (('', '')) -%}
146+
{%- endmacro %}

macros/internal/metadata_processing/expand_column_list.sql

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{%- macro expand_column_list(columns=none) -%}
22

33
{%- if not columns -%}
4-
{%- if execute -%}
5-
{{- exceptions.raise_compiler_error("Expected a list of columns, got: " ~ columns) -}}
6-
{%- endif -%}
4+
{%- do return([]) -%}
75
{%- endif -%}
86

97
{%- set col_list = [] -%}
@@ -49,4 +47,4 @@
4947

5048
{%- do return(col_list) -%}
5149

52-
{%- endmacro -%}
50+
{%- endmacro -%}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{%- macro process_payload_column_excludes(src_pk, src_hashdiff, src_payload, src_extra_columns,
2+
src_eff, src_ldts, src_source, source_model) -%}
3+
4+
{%- if src_payload is not mapping -%}
5+
{%- do return(src_payload) -%}
6+
{%- endif -%}
7+
8+
{%- set source_model_cols = adapter.get_columns_in_relation(ref(source_model)) -%}
9+
{%- set columns_in_metadata = dbtvault.expand_column_list(columns=[src_pk, src_hashdiff,
10+
src_payload, src_extra_columns,
11+
src_eff, src_ldts, src_source]) | map('lower') | list -%}
12+
13+
{%- set payload_cols = [] -%}
14+
{%- for col in source_model_cols -%}
15+
{%- if col.column | lower not in columns_in_metadata -%}
16+
{%- do payload_cols.append(col.column) -%}
17+
{%- endif -%}
18+
{%- endfor -%}
19+
20+
{%- if 'exclude_columns' in src_payload.keys() -%}
21+
{%- set table_excludes_columns = src_payload.exclude_columns -%}
22+
23+
{%- if table_excludes_columns -%}
24+
25+
{%- set excluded_payload = [] -%}
26+
{%- set exclude_columns_list = src_payload.columns | map('lower') | list -%}
27+
28+
{%- for col in payload_cols -%}
29+
{%- if col | lower not in exclude_columns_list -%}
30+
{%- do excluded_payload.append(col) -%}
31+
{%- endif -%}
32+
{%- endfor -%}
33+
{%- endif -%}
34+
{%- endif -%}
35+
36+
{%- do return(excluded_payload) -%}
37+
38+
{%- endmacro -%}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{% macro drop_temporary_special(tmp_relation) %}
2+
{# In databricks and sqlserver a temporary view/table can only be dropped by #}
3+
{# the connection or session that created it so drop it now before the commit below closes this session #}
4+
5+
{%- set drop_query_name = 'DROP_QUERY-' ~ i -%}
6+
{% call statement(drop_query_name, fetch_result=True) -%}
7+
{% if target.type == 'databricks' %}
8+
DROP VIEW {{ tmp_relation }};
9+
{% elif target.type == 'sqlserver' %}
10+
DROP TABLE {{ tmp_relation }};
11+
{% endif %}
12+
{%- endcall %}
13+
14+
{% endmacro %}

macros/materialisations/mat_is_checks.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
{{ return(relation is not none
1818
and relation.type == 'table'
1919
and model.config.materialized == 'vault_insert_by_period'
20-
and not flags.FULL_REFRESH) }}
20+
and not should_full_refresh()) }}
2121
{% endif %}
2222
{% endmacro %}
2323

@@ -33,7 +33,7 @@
3333
{{ return(relation is not none
3434
and relation.type == 'table'
3535
and model.config.materialized == 'vault_insert_by_rank'
36-
and not flags.FULL_REFRESH) }}
36+
and not should_full_refresh()) }}
3737
{% endif %}
3838
{% endmacro %}
3939

@@ -49,7 +49,7 @@
4949
{{ return(relation is not none
5050
and relation.type == 'table'
5151
and model.config.materialized == 'bridge_incremental'
52-
and not flags.FULL_REFRESH) }}
52+
and not should_full_refresh()) }}
5353
{% endif %}
5454
{% endmacro %}
5555

@@ -65,6 +65,6 @@
6565
{{ return(relation is not none
6666
and relation.type == 'table'
6767
and model.config.materialized == 'pit_incremental'
68-
and not flags.FULL_REFRESH) }}
68+
and not should_full_refresh()) }}
6969
{% endif %}
7070
{% endmacro %}

0 commit comments

Comments
 (0)