forked from brooklyn-data/dbt_artifacts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload_snapshots.sql
83 lines (79 loc) · 4.36 KB
/
upload_snapshots.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
{% macro upload_snapshots(graph) -%}
{% set snapshots = [] %}
{% for node in graph.nodes.values() | selectattr("resource_type", "equalto", "snapshot") %}
{% do snapshots.append(node) %}
{% endfor %}
{{ return(adapter.dispatch('get_snapshots_dml_sql', 'dbt_artifacts')(snapshots)) }}
{%- endmacro %}
{% macro default__get_snapshots_dml_sql(snapshots) -%}
{% if snapshots != [] %}
{% set snapshot_values %}
select
{{ adapter.dispatch('column_identifier', 'dbt_artifacts')(1) }},
{{ adapter.dispatch('column_identifier', 'dbt_artifacts')(2) }},
{{ adapter.dispatch('column_identifier', 'dbt_artifacts')(3) }},
{{ adapter.dispatch('column_identifier', 'dbt_artifacts')(4) }},
{{ adapter.dispatch('column_identifier', 'dbt_artifacts')(5) }},
{{ adapter.dispatch('column_identifier', 'dbt_artifacts')(6) }},
{{ adapter.dispatch('parse_json', 'dbt_artifacts')(adapter.dispatch('column_identifier', 'dbt_artifacts')(7)) }},
{{ adapter.dispatch('column_identifier', 'dbt_artifacts')(8) }},
{{ adapter.dispatch('column_identifier', 'dbt_artifacts')(9) }},
{{ adapter.dispatch('column_identifier', 'dbt_artifacts')(10) }},
{{ adapter.dispatch('column_identifier', 'dbt_artifacts')(11) }},
{{ adapter.dispatch('parse_json', 'dbt_artifacts')(adapter.dispatch('column_identifier', 'dbt_artifacts')(12)) }},
{{ adapter.dispatch('column_identifier', 'dbt_artifacts')(13) }},
{{ adapter.dispatch('parse_json', 'dbt_artifacts')(adapter.dispatch('column_identifier', 'dbt_artifacts')(14)) }}
from values
{% for snapshot in snapshots -%}
(
'{{ invocation_id }}', {# command_invocation_id #}
'{{ snapshot.unique_id }}', {# node_id #}
'{{ run_started_at }}', {# run_started_at #}
'{{ snapshot.database }}', {# database #}
'{{ snapshot.schema }}', {# schema #}
'{{ snapshot.name }}', {# name #}
'{{ tojson(snapshot.depends_on.nodes) }}', {# depends_on_nodes #}
'{{ snapshot.package_name }}', {# package_name #}
'{{ snapshot.original_file_path | replace('\\', '\\\\') }}', {# path #}
'{{ snapshot.checksum.checksum }}', {# checksum #}
'{{ snapshot.config.strategy }}', {# strategy #}
'{{ tojson(snapshot.config.meta) | replace("\\", "\\\\") | replace("'","\\'") | replace('"', '\\"') }}', {# meta #}
'{{ snapshot.alias }}', {# alias #}
'{{ tojson(snapshot) | replace("\\", "\\\\") | replace("'","\\'") | replace('"', '\\"') }}' {# all_results #}
)
{%- if not loop.last %},{%- endif %}
{%- endfor %}
{% endset %}
{{ snapshot_values }}
{% else %}
{{ return("") }}
{% endif %}
{% endmacro -%}
{% macro bigquery__get_snapshots_dml_sql(snapshots) -%}
{% if snapshots != [] %}
{% set snapshot_values %}
{% for snapshot in snapshots -%}
(
'{{ invocation_id }}', {# command_invocation_id #}
'{{ snapshot.unique_id }}', {# node_id #}
'{{ run_started_at }}', {# run_started_at #}
'{{ snapshot.database }}', {# database #}
'{{ snapshot.schema }}', {# schema #}
'{{ snapshot.name }}', {# name #}
{{ tojson(snapshot.depends_on.nodes) }}, {# depends_on_nodes #}
'{{ snapshot.package_name }}', {# package_name #}
'{{ snapshot.original_file_path | replace('\\', '\\\\') }}', {# path #}
'{{ snapshot.checksum.checksum }}', {# checksum #}
'{{ snapshot.config.strategy }}', {# strategy #}
parse_json('''{{ tojson(snapshot.config.meta) }}'''), {# meta #}
'{{ snapshot.alias }}', {# alias #}
parse_json('{{ tojson(snapshot) | replace("\\", "\\\\") | replace("'","\\'") | replace('"', '\\"') }}', wide_number_mode=>'round') {# all_results #}
)
{%- if not loop.last %},{%- endif %}
{%- endfor %}
{% endset %}
{{ snapshot_values }}
{% else %}
{{ return("") }}
{% endif %}
{%- endmacro %}