File tree Expand file tree Collapse file tree 2 files changed +39
-18
lines changed Expand file tree Collapse file tree 2 files changed +39
-18
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ {% macro create_unload_external_stage() %}
2+ {% if env_var(' DBT_ENVIRONMENT' , ' dev' ) == ' prod' %}
3+ {% set sql %}
4+ CREATE OR REPLACE STAGE dbt_ext_unload_stage
5+ url= ' s3://your-company-artifacts/snowflake-unload/dbt/'
6+ credentials= (aws_key_id= ' {{ env_var(' DBT_SECRET_AWS_ACCESS_KEY_ID' ) }}' , aws_secret_key= ' {{ env_var(' DBT_SECRET_AWS_SECRET_ACCESS_KEY' ) }}' )
7+ file_format = (type = csv, field_optionally_enclosed_by = ' "' , compression = gzip);
8+ {% endset %}
9+ {% set _ = run_query(sql) %}
10+ {% endif %}
11+ {% endmacro %}
12+
13+ {% macro unload_to_s3() %}
14+ -- Another example here: https://gist.github.com/jeremyyeo/f07dbe9a7687ffc4976e1488a8e35547
15+
16+ {% if env_var(' DBT_ENVIRONMENT' , ' dev' ) == ' prod' %}
17+
18+ {% set sql %}
19+
20+ -- Unload (possibly multiple) data files into timestamped directory.
21+ COPY INTO @dbt_ext_unload_stage/ {{ this .name }}/ {{ run_started_at .date ().isoformat() }}/ {{ run_started_at .isoformat () }}/ data
22+ FROM {{ this }}
23+ header = true;
24+
25+ -- Add an indicator that the unload has completed.
26+ COPY INTO @dbt_ext_unload_stage/ {{ this .name }}/ {{ run_started_at .date ().isoformat() }}/ {{ run_started_at .isoformat () }}/ done .csv
27+ FROM (SELECT 1 AS done)
28+ single = true;
29+
30+ {% endset %}
31+
32+ {% if execute %}
33+
34+ {% do run_query(sql) %}
35+
36+ {% endif %}
37+
38+ {% endif %}
39+ {% endmacro %}
You can’t perform that action at this time.
0 commit comments