forked from brooklyn-data/dbt_artifacts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload_sources.sql
76 lines (73 loc) · 3.72 KB
/
upload_sources.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
{% macro upload_sources(graph) -%}
{% set sources = [] %}
{% for node in graph.sources.values() %}
{% do sources.append(node) %}
{% endfor %}
{{ return(adapter.dispatch('get_sources_dml_sql', 'dbt_artifacts')(sources)) }}
{%- endmacro %}
{% macro default__get_sources_dml_sql(sources) -%}
{% if sources != [] %}
{% set source_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('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('parse_json', 'dbt_artifacts')(adapter.dispatch('column_identifier', 'dbt_artifacts')(11)) }},
{{ adapter.dispatch('parse_json', 'dbt_artifacts')(adapter.dispatch('column_identifier', 'dbt_artifacts')(12)) }}
from values
{% for source in sources -%}
(
'{{ invocation_id }}', {# command_invocation_id #}
'{{ source.unique_id }}', {# node_id #}
'{{ run_started_at }}', {# run_started_at #}
'{{ source.database }}', {# database #}
'{{ source.schema }}', {# schema #}
'{{ source.source_name }}', {# source_name #}
'{{ source.loader }}', {# loader #}
'{{ source.name }}', {# name #}
'{{ source.identifier }}', {# identifier #}
'{{ source.loaded_at_field | replace("'","\\'") }}', {# loaded_at_field #}
'{{ tojson(source.freshness) | replace("'","\\'") }}', {# freshness #}
'{{ tojson(source) | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}' {# all_results #}
)
{%- if not loop.last %},{%- endif %}
{%- endfor %}
{% endset %}
{{ source_values }}
{% else %}
{{ return("") }}
{% endif %}
{% endmacro -%}
{% macro bigquery__get_sources_dml_sql(sources) -%}
{% if sources != [] %}
{% set source_values %}
{% for source in sources -%}
(
'{{ invocation_id }}', {# command_invocation_id #}
'{{ source.unique_id }}', {# node_id #}
'{{ run_started_at }}', {# run_started_at #}
'{{ source.database }}', {# database #}
'{{ source.schema }}', {# schema #}
'{{ source.source_name }}', {# source_name #}
'{{ source.loader }}', {# loader #}
'{{ source.name }}', {# name #}
'{{ source.identifier }}', {# identifier #}
'{{ source.loaded_at_field | replace("'","\\'") }}', {# loaded_at_field #}
parse_json('{{ tojson(source.freshness) | replace("'","\\'") }}'), {# freshness #}
parse_json('{{ tojson(source) | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}', wide_number_mode=>'round') {# all_results #}
)
{%- if not loop.last %},{%- endif %}
{%- endfor %}
{% endset %}
{{ source_values }}
{% else %}
{{ return("") }}
{% endif %}
{%- endmacro %}