-
Notifications
You must be signed in to change notification settings - Fork 6
/
create_integration.sql
55 lines (44 loc) · 1.44 KB
/
create_integration.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
{%- macro create_integration(file) -%}
{% if not file %}
{{ exceptions.raise_compiler_error(
"\nyou must pass in a file via arguments:" ~
"\n --args 'file: ./snowflake/integration/s3_to_snowflake_integration.yml'"
) }}
{% endif %}
{% set integration = gather_results(file) %}
{% set integration_name = integration.pop('integration_name') %}
{% set integration_type = integration.pop('integration_type') %}
{% set create_attributes %}
{%- for key, value in integration.items() %}
{%- if value is iterable and value is not string %}
{{ key }} = ({{ "\'" + value | join("\', \'") + "\'" }})
{%- else %}
{{ key }} = {{ value }}
{%- endif %}
{%- endfor %}
{% endset %}
{% set alter_attributes %}
{%- for key, value in integration.items() if key not in ['type', 'storage_provider'] %}
{%- if value is iterable and value is not string %}
{{ key }} = ({{ "\'" + value | join("\', \'") + "\'" }})
{%- else %}
{{ key }} = {{ value }}
{%- endif %}
{%- endfor %}
{% endset %}
{%- set sql -%}
begin name create_integration;
{# don't want to delete if already exists :) #}
create {{ integration_type }} integration if not exists {{ integration_name }}
{{- create_attributes }}
;
alter {{ integration_type }} integration {{ integration_name }} set
{{- alter_attributes }}
;
commit;
{%- endset -%}
{{ log(sql, info=True) }}
{% if not var('dry_run', False) %}
{{ run_query(sql) }}
{% endif %}
{%- endmacro -%}