From 3e4392638c1fff614428cbd25a0656b86397ead1 Mon Sep 17 00:00:00 2001 From: jnadal Date: Tue, 6 Aug 2024 17:13:24 +0200 Subject: [PATCH] added delta_table_replace materialization --- CHANGELOG.md | 3 +- .../table/delta_table_replace.sql | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 dbt/include/glue/macros/materializations/table/delta_table_replace.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index eddb3010..e7267e5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ -## New versio +## New version - Fix session provisioning timeout and delay handling +- Add delta_table_replace materialization ## v1.8.1 - Fix typo in README.md diff --git a/dbt/include/glue/macros/materializations/table/delta_table_replace.sql b/dbt/include/glue/macros/materializations/table/delta_table_replace.sql new file mode 100644 index 00000000..1b18e2ef --- /dev/null +++ b/dbt/include/glue/macros/materializations/table/delta_table_replace.sql @@ -0,0 +1,42 @@ +{% materialization delta_table_replace, adapter='glue' %} + {%- set partition_by = config.get('partition_by', none) -%} + {%- set table_properties = config.get('table_properties', default={}) -%} + {% set lf_tags_config = config.get('lf_tags_config') -%} + {%- set lf_grants = config.get('lf_grants') -%} + {%- set target_relation = this -%} + {%- set build_sql = delta_create_or_replace(target_relation, table_properties) -%} + + {{ run_hooks(pre_hooks) }} + + {%- call statement('main') -%} + {{ build_sql }} + {%- endcall -%} + + {% do persist_docs(target_relation, model) %} + + {% do persist_constraints(target_relation, model) %} + + {% if lf_tags_config is not none %} + {{ adapter.add_lf_tags(target_relation, lf_tags_config) }} + {% endif %} + + {% if lf_grants is not none %} + {{ adapter.apply_lf_grants(target_relation, lf_grants) }} + {% endif %} + + {{ run_hooks(post_hooks) }} + + {{ return({'relations': [target_relation]}) }} + +{% endmaterialization %} + +{% macro delta_create_or_replace(relation, table_properties) %} + create or replace table {{ relation }} + using delta + {{ set_table_properties(table_properties) }} + {{ partition_cols(label="partitioned by") }} + {{ glue__location_clause(relation) }} + {{ comment_clause() }} + as + {{ sql }} +{% endmacro %}