Skip to content

Commit

Permalink
add an example for incremental delta
Browse files Browse the repository at this point in the history
  • Loading branch information
milicevica23 committed Mar 3, 2024
1 parent 8aba866 commit 0b304c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
3 changes: 1 addition & 2 deletions dbt/include/duckdb/macros/utils/upstream.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@


{%- macro register_self_reference_external_models() -%}
{% if execute %}
{% if execute and var("first_run") != 'true' %}
{% for node in selected_resources if
graph['nodes'][node].resource_type in ('model', 'seed')
and graph['nodes'][node].config.materialized=='external'
and 'this' in graph['nodes'][node]['raw_code']
%}
{% set current_node = graph['nodes'][node] %}
{%- set node_rel = api.Relation.create(
Expand Down
28 changes: 16 additions & 12 deletions tests/functional/plugins/delta/test_delta_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
SELECT 2 as a, 'test2' as b
UNION ALL
SELECT 3 as a, 'test3' as b
UNION ALL
SELECT 4 as a, 'test4' as b
UNION ALL
SELECT 5 as a, 'test5' as b
UNION ALL
SELECT 6 as a, 'test6' as b
"""

delta1 = """
Expand All @@ -29,7 +23,7 @@
select * from {{{{ref('ref1')}}}}
{{{{var('first_run')}}}}
{{% if var('first_run') == 'true' %}}
WHERE a < 2
{{% else %}}
Expand Down Expand Up @@ -72,9 +66,10 @@ def models(self, project_root):
}

def test_plugins(self, project):
# This doesnt work because we need some kind of incremental notin
# This doesnt work because we need some kind of incremental thinking
# i made it register on the begining but if the table doesnt exists by the first run it can't register
# We have to see how to do it
# I tried to simulate the incremental model with the variables which works

results = run_dbt(
[
Expand All @@ -89,8 +84,17 @@ def test_plugins(self, project):

res = project.run_sql("SELECT * FROM 'delta1'", fetch="all")

# results = run_dbt(["run", "--select", "ref1 delta1"])

# res = project.run_sql("SELECT * FROM 'delta1'", fetch="all")
results = run_dbt(
[
"run",
"--select",
"ref1 delta1",
"--vars",
"{'first_run': 'false'}",
"-d",
]
)

print("hello")
res = project.run_sql("SELECT * FROM 'delta1'", fetch="all")
assert res == [(1, "test"), (3, "test3"), (2, "test2"), (1, "test")]
print("break point")

0 comments on commit 0b304c0

Please sign in to comment.