Skip to content

Commit 7ce6cd3

Browse files
author
Alex Higgs
committed
Release 0.7.1
1 parent a90f480 commit 7ce6cd3

25 files changed

+271
-126
lines changed

CONTRIBUTING.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
## Contributing new features
2+
3+
Please refer to our contribution guidelines over on our [development repository](https://github.com/Datavault-UK/dbtvault-dev/blob/master/CONTRIBUTING.md)
4+
15
## We'd love to hear from you
26

37
dbtvault is very much a work in progress – we’re constantly adding quality of life improvements and will be adding
48
new table types regularly.
59

6-
We know that it deserves new features, that the code base can be tidied up and the SQL better tuned.
7-
8-
Rest assured we’re working on it for future releases – [our roadmap contains information on what’s coming](roadmap.md).
10+
Rest assured we’re working on future releases – [our roadmap contains information on what’s coming](https://dbtvault.readthedocs.io/en/latest/roadmap/).
911

1012
If you spot anything you’d like to bring to our attention, have a request for new features, have spotted an improvement we could make,
11-
or want to tell us about a typo or bug, then please don’t hesitate to let us know via [Github](https://github.com/Datavault-UK/dbtvault/issues).
13+
or want to tell us about a typo or bug, then please don’t hesitate to let us know via [github](https://github.com/Datavault-UK/dbtvault/issues).
1214

1315
We’d rather know you are making active use of this package than hearing nothing from all of you out there!
1416

@@ -30,8 +32,4 @@ We'd love to add new features to make this package even more useful for the comm
3032
please feel free to submit ideas and thoughts!
3133

3234
### If it's an idea, feedback or a general inquiry
33-
Create a post with as much detail as possible; We'll be happy to reply and work with you.
34-
35-
## Pull requests
36-
If you've developed something which we can add via a pull request, we're more than happy to consider it, but we'd
37-
like to discuss the changes first.
35+
Create a post with as much detail as possible; We'll be happy to reply and work with you.

macros/internal/alias.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{%- macro alias(alias_config=none, prefix=none) -%}
22

3-
{{- adapter.dispatch('alias', packages = ['dbtvault'])(alias_config=alias_config, prefix=prefix) -}}
3+
{{- adapter.dispatch('alias', packages = var('adapter_packages', ['dbtvault']))(alias_config=alias_config, prefix=prefix) -}}
44

55
{%- endmacro %}
66

macros/internal/alias_all.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{%- macro alias_all(columns=none, prefix=none) -%}
22

3-
{{- adapter.dispatch('alias_all', packages = ['dbtvault'])(columns=columns, prefix=prefix) -}}
3+
{{- adapter.dispatch('alias_all', packages = var('adapter_packages', ['dbtvault']))(columns=columns, prefix=prefix) -}}
44

55
{%- endmacro %}
66

macros/internal/as_constant.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{%- macro as_constant(column_str=none) -%}
22

3-
{{- adapter.dispatch('as_constant', packages = ['dbtvault'])(column_str=column_str) -}}
3+
{{- adapter.dispatch('as_constant', packages = var('adapter_packages', ['dbtvault']))(column_str=column_str) -}}
44

55
{%- endmacro %}
66

macros/internal/expand_column_list.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@
1414

1515
{%- if col is string -%}
1616

17-
{%- set _ = col_list.append(col) -%}
17+
{%- do col_list.append(col) -%}
1818

1919
{#- If list of lists -#}
2020
{%- elif col is iterable and col is not string -%}
2121

2222
{%- if col is mapping -%}
2323

24-
{%- set _ = col_list.append(col) -%}
24+
{%- do col_list.append(col) -%}
2525

2626
{%- else -%}
2727

2828
{%- for cols in col -%}
2929

30-
{%- set _ = col_list.append(cols) -%}
30+
{%- do col_list.append(cols) -%}
3131

3232
{%- endfor -%}
3333

macros/internal/multikey.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{%- macro multikey(columns, prefix=none, condition=none, operator='AND') -%}
22

3-
{{- adapter.dispatch('multikey', packages = ['dbtvault'])(columns=columns, prefix=prefix, condition=condition, operator=operator) -}}
3+
{{- adapter.dispatch('multikey', packages = var('adapter_packages', ['dbtvault']))(columns=columns, prefix=prefix, condition=condition, operator=operator) -}}
44

55
{%- endmacro %}
66

macros/internal/process_macros.sql

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{%- macro process_excludes(source_relation=none, derived_columns=none, columns=none) -%}
2+
3+
{%- set exclude_columns_list = [] -%}
4+
{%- set include_columns = [] -%}
5+
{%- if exclude_columns is none -%}
6+
{%- set exclude_columns = false -%}
7+
{% endif %}
8+
9+
{#- getting all the source columns -#}
10+
11+
{%- set source_columns = dbtvault.source_columns(source_relation=source_relation) -%}
12+
13+
{%- if columns is mapping -%}
14+
15+
{%- for col in columns -%}
16+
17+
{# Checks if the exclude flag is present and then creates a exclude list to pass to NEED BETTER NAME FOR MACRO #}
18+
{%- if columns[col] is mapping and columns[col].exclude_columns -%}
19+
20+
{%- for flagged_cols in columns[col]['columns'] -%}
21+
22+
{%- do exclude_columns_list.append(flagged_cols) -%}
23+
24+
{%- endfor -%}
25+
26+
{%- set include_columns = dbtvault.process_include_columns(primary_set_list=derived_columns, secondary_set_list=source_columns, exclude_columns_list=exclude_columns_list) -%}
27+
28+
{#- Updates the the apropriate hashdiff to contain the columns we do want to hash -#}
29+
{%- do columns[col].update({'columns': include_columns}) -%}
30+
{%- do columns[col].pop('exclude_columns') -%}
31+
{%- set include_columns = [] -%}
32+
{%- set exclude_columns = [] -%}
33+
34+
{%- endif -%}
35+
{%- endfor -%}
36+
{%- endif -%}
37+
38+
{%- do return(columns) -%}
39+
40+
41+
{%- endmacro -%}
42+
43+
44+
{%- macro process_include_columns(primary_set_list=none, secondary_set_list=none, exclude_columns_list=none) -%}
45+
46+
{%- set include_columns = [] -%}
47+
48+
{%- if exclude_columns is none -%}
49+
{%- set exclude_columns_list = [] -%}
50+
{%- endif -%}
51+
52+
{# Appending primary list items not in exclude columns #}
53+
{%- if primary_set_list is not none -%}
54+
55+
{%- for primary_col in primary_set_list -%}
56+
57+
{%- if primary_col not in exclude_columns_list -%}
58+
59+
{%- if primary_set_list is mapping -%}
60+
{%- set primary_str = dbtvault.as_constant(primary_col) -%}
61+
{%- do include_columns.append(primary_str) -%}
62+
{%- do exclude_columns_list.append(primary_str) -%}
63+
{%- else -%}
64+
{%- do include_columns.append(primary_col) -%}
65+
{%- do exclude_columns_list.append(primary_col) -%}
66+
{%- endif -%}
67+
68+
{%- endif -%}
69+
70+
{%- endfor -%}
71+
72+
{%- endif -%}
73+
74+
{# Apending the secondary list items not in the priamry list or the exclude list #}
75+
{%- if secondary_set_list is not none -%}
76+
77+
{%- for secondary_col in secondary_set_list -%}
78+
79+
{%- if secondary_col not in exclude_columns_list -%}
80+
81+
{%- if secondary_set_list is mapping -%}
82+
{%- set secondary_str = dbtvault.as_constant(secondary_col) -%}
83+
{%- do include_columns.append(secondary_str) -%}
84+
{%- else -%}
85+
{%- do include_columns.append(secondary_col) -%}
86+
{%- endif -%}
87+
88+
{%- endif -%}
89+
90+
{% endfor -%}
91+
92+
{%- endif -%}
93+
94+
{%- do return(include_columns) -%}
95+
96+
{%- endmacro -%}

macros/materialisations/helpers.sql

+13-13
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
{%- macro replace_placeholder_with_filter(core_sql, timestamp_field, start_timestamp, stop_timestamp, offset, period) -%}
88

99
{% set macro = adapter.dispatch('replace_placeholder_with_filter',
10-
packages = ['dbtvault'])(core_sql=core_sql,
11-
timestamp_field=timestamp_field,
12-
start_timestamp=start_timestamp,
13-
stop_timestamp=stop_timestamp,
14-
offset=offset,
15-
period=period) %}
10+
packages = var('adapter_packages', ['dbtvault']))(core_sql=core_sql,
11+
timestamp_field=timestamp_field,
12+
start_timestamp=start_timestamp,
13+
stop_timestamp=stop_timestamp,
14+
offset=offset,
15+
period=period) %}
1616
{% do return(macro) %}
1717
{%- endmacro %}
1818

19-
{% macro snowflake__replace_placeholder_with_filter(core_sql, timestamp_field, start_timestamp, stop_timestamp, offset, period) %}
19+
{% macro default__replace_placeholder_with_filter(core_sql, timestamp_field, start_timestamp, stop_timestamp, offset, period) %}
2020

2121
{%- set period_filter -%}
2222
(TO_DATE({{ timestamp_field }}) >= DATE_TRUNC('{{ period }}', TO_DATE('{{ start_timestamp }}') + INTERVAL '{{ offset }} {{ period }}') AND
@@ -35,7 +35,7 @@
3535
{%- macro get_period_filter_sql(target_cols_csv, base_sql, timestamp_field, period, start_timestamp, stop_timestamp, offset) -%}
3636

3737
{% set macro = adapter.dispatch('get_period_filter_sql',
38-
packages = ['dbtvault'])(target_cols_csv=target_cols_csv,
38+
packages = var('adapter_packages', ['dbtvault']))(target_cols_csv=target_cols_csv,
3939
base_sql=base_sql,
4040
timestamp_field=timestamp_field,
4141
period=period,
@@ -45,7 +45,7 @@
4545
{% do return(macro) %}
4646
{%- endmacro %}
4747

48-
{% macro snowflake__get_period_filter_sql(target_cols_csv, base_sql, timestamp_field, period, start_timestamp, stop_timestamp, offset) -%}
48+
{% macro default__get_period_filter_sql(target_cols_csv, base_sql, timestamp_field, period, start_timestamp, stop_timestamp, offset) -%}
4949

5050
{%- set filtered_sql = {'sql': base_sql} -%}
5151

@@ -63,7 +63,7 @@
6363
{%- macro get_period_boundaries(target_schema, target_table, timestamp_field, start_date, stop_date, period) -%}
6464

6565
{% set macro = adapter.dispatch('get_period_boundaries',
66-
packages = ['dbtvault'])(target_schema=target_schema,
66+
packages = var('adapter_packages', ['dbtvault']))(target_schema=target_schema,
6767
target_table=target_table,
6868
timestamp_field=timestamp_field,
6969
start_date=start_date,
@@ -73,7 +73,7 @@
7373
{% do return(macro) %}
7474
{%- endmacro %}
7575

76-
{% macro snowflake__get_period_boundaries(target_schema, target_table, timestamp_field, start_date, stop_date, period) -%}
76+
{% macro default__get_period_boundaries(target_schema, target_table, timestamp_field, start_date, stop_date, period) -%}
7777

7878
{% set period_boundary_sql -%}
7979
with data as (
@@ -107,14 +107,14 @@
107107
{%- macro get_period_of_load(period, offset, start_timestamp) -%}
108108

109109
{% set macro = adapter.dispatch('get_period_of_load',
110-
packages = ['dbtvault'])(period=period,
110+
packages = var('adapter_packages', ['dbtvault']))(period=period,
111111
offset=offset,
112112
start_timestamp=start_timestamp) %}
113113

114114
{% do return(macro) %}
115115
{%- endmacro %}
116116

117-
{%- macro snowflake__get_period_of_load(period, offset, start_timestamp) -%}
117+
{%- macro default__get_period_of_load(period, offset, start_timestamp) -%}
118118

119119
{% set period_of_load_sql -%}
120120
SELECT DATE_TRUNC('{{ period }}', DATEADD({{ period }}, {{ offset }}, TO_DATE('{{start_timestamp}}'))) AS period_of_load

macros/materialisations/helpers_snowflake_schema.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: 2
22

33
macros:
4-
- name: snowflake__replace_placeholder_with_filter
4+
- name: default__replace_placeholder_with_filter
55
description: |
66
{{ doc("macro__replace_placeholder_with_filter") }}
77
@@ -26,7 +26,7 @@ macros:
2626
type: string
2727
description: '{{ doc("arg__period_materialisation__period") }}'
2828

29-
- name: snowflake__get_period_filter_sql
29+
- name: default__get_period_filter_sql
3030
description: |
3131
{{ doc("macro__get_period_filter_sql") }}
3232
@@ -54,7 +54,7 @@ macros:
5454
type: string
5555
description: '{{ doc("arg__period_materialisation__offset") }}'
5656

57-
- name: snowflake__get_period_boundaries
57+
- name: default__get_period_boundaries
5858
description: |
5959
{{ doc("macro__get_period_boundaries") }}
6060
@@ -79,7 +79,7 @@ macros:
7979
type: string
8080
description: '{{ doc("arg__period_materialisation__period") }}'
8181

82-
- name: snowflake__get_period_of_load
82+
- name: default__get_period_of_load
8383
description: |
8484
{{ doc("macro__get_period_of_load") }}
8585

macros/materialisations/vault_insert_by_period_materialization.sql

+8-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
0, period) %}
3030
{% set build_sql = create_table_as(False, target_relation, filtered_sql) %}
3131

32+
{% do to_drop.append(tmp_relation) %}
33+
3234
{% elif existing_relation.is_view or full_refresh_mode %}
3335
{#-- Make sure the backup doesn't exist so we don't encounter issues with the rename below #}
3436
{% set backup_identifier = existing_relation.identifier ~ "__dbt_backup" %}
@@ -43,6 +45,7 @@
4345
0, period) %}
4446
{% set build_sql = create_table_as(False, target_relation, filtered_sql) %}
4547

48+
{% do to_drop.append(tmp_relation) %}
4649
{% do to_drop.append(backup_relation) %}
4750
{% else %}
4851

@@ -88,13 +91,14 @@
8891
{%- set rows_inserted = (load_result(insert_query_name)['status'].split(" "))[1] | int -%}
8992

9093
{%- set sum_rows_inserted = loop_vars['sum_rows_inserted'] + rows_inserted -%}
91-
{%- set _ = loop_vars.update({'sum_rows_inserted': sum_rows_inserted}) %}
94+
{%- do loop_vars.update({'sum_rows_inserted': sum_rows_inserted}) %}
9295

9396
{{ dbt_utils.log_info("Ran for {} {} of {} ({}); {} records inserted [{}]".format(period, iteration_number,
9497
period_boundaries.num_periods,
9598
period_of_load, rows_inserted,
9699
model.unique_id)) }}
97100

101+
{% do to_drop.append(tmp_relation) %}
98102
{% do adapter.commit() %}
99103

100104
{% endfor %}
@@ -123,7 +127,9 @@
123127
{{ run_hooks(post_hooks, inside_transaction=True) }}
124128

125129
{% for rel in to_drop %}
126-
{{ drop_relation_if_exists(backup_relation) }}
130+
{% if rel.type is not none %}
131+
{% do adapter.drop_relation(rel) %}
132+
{% endif %}
127133
{% endfor %}
128134

129135
{{ run_hooks(post_hooks, inside_transaction=False) }}

0 commit comments

Comments
 (0)