-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The incremental strategy supported is to insert new records into target table, without updating or overwriting. Resolves: #1
- Loading branch information
1 parent
4386120
commit 6fda13a
Showing
6 changed files
with
87 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,42 @@ | ||
{% macro dbt_trino_get_append_sql(tmp_relation, target_relation) %} | ||
|
||
{%- set dest_columns = adapter.get_columns_in_relation(target_relation) -%} | ||
{%- set dest_cols_csv = dest_columns | map(attribute='quoted') | join(', ') -%} | ||
insert into {{ target_relation }} | ||
select {{dest_cols_csv}} from {{ tmp_relation.include(database=false, schema=false) }}; | ||
|
||
drop table if exists {{ tmp_relation }}; | ||
|
||
{% endmacro %} | ||
|
||
{% materialization incremental, adapter='trino' -%} | ||
{{ exceptions.raise_not_implemented( | ||
'incremental materialization not implemented for '+adapter.type()) | ||
}} | ||
{% endmaterialization %} | ||
|
||
{%- set full_refresh_mode = (flags.FULL_REFRESH == True) -%} | ||
|
||
{% set target_relation = this %} | ||
{% set existing_relation = load_relation(this) %} | ||
{% set tmp_relation = make_temp_relation(this) %} | ||
|
||
{{ run_hooks(pre_hooks) }} | ||
|
||
{% if existing_relation is none %} | ||
{% set build_sql = create_table_as(False, target_relation, sql) %} | ||
{% elif existing_relation.is_view or full_refresh_mode %} | ||
{% do adapter.drop_relation(existing_relation) %} | ||
{% set build_sql = create_table_as(False, target_relation, sql) %} | ||
{% else %} | ||
{% set drop_tmp_relation_sql = "drop table if exists " ~ tmp_relation %} | ||
{% do run_query(drop_tmp_relation_sql) %} | ||
{% do run_query(create_table_as(True, tmp_relation, sql)) %} | ||
{% set build_sql = dbt_trino_get_append_sql(tmp_relation, target_relation) %} | ||
{% endif %} | ||
|
||
{%- call statement('main') -%} | ||
{{ build_sql }} | ||
{%- endcall -%} | ||
|
||
{{ run_hooks(post_hooks) }} | ||
|
||
{{ return({'relations': [target_relation]}) }} | ||
|
||
{%- endmaterialization %} |
17 changes: 17 additions & 0 deletions
17
docker/dbt/jaffle_shop/models/marts/core/dim_order_dates.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{{ | ||
config(materialized = 'incremental') | ||
}} | ||
|
||
with orders as ( | ||
|
||
select * from {{ ref('stg_orders') }} | ||
|
||
) | ||
|
||
select distinct order_date | ||
from orders | ||
|
||
{% if is_incremental() %} | ||
-- this filter will only be applied on an incremental run | ||
where order_date > (select max(order_date) from {{ this }}) | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters