Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inline comments (--) on the last line of an incremental model (partition replacement) #991

Merged
merged 8 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20231105-125740.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Fix inline comments (--) on the last line of an incremental model
time: 2023-11-05T12:57:40.289399+09:00
custom:
Author: tnk-ysk
Issue: "896"
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
{{ wrap_with_time_ingestion_partitioning_sql(partition_by, sql, True) }}
{%- else -%}
{{sql}}
{%- endif -%}
{%- endif %}

)
{%- endset -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,50 @@
{% endif %}
""".lstrip()

overwrite_date_with_comment_at_end_sql = """
{{
config(
materialized="incremental",
incremental_strategy='insert_overwrite',
cluster_by="id",
partition_by={
"field": "date_day",
"data_type": "date"
}
)
}}


with data as (

{% if not is_incremental() %}

select 1 as id, cast('2020-01-01' as date) as date_day union all
select 2 as id, cast('2020-01-01' as date) as date_day union all
select 3 as id, cast('2020-01-01' as date) as date_day union all
select 4 as id, cast('2020-01-01' as date) as date_day

{% else %}

-- we want to overwrite the 4 records in the 2020-01-01 partition
-- with the 2 records below, but add two more in the 2020-01-02 partition
select 10 as id, cast('2020-01-01' as date) as date_day union all
select 20 as id, cast('2020-01-01' as date) as date_day union all
select 30 as id, cast('2020-01-02' as date) as date_day union all
select 40 as id, cast('2020-01-02' as date) as date_day

{% endif %}

)

select * from data

{% if is_incremental() %}
where date_day >= _dbt_max_partition
{% endif %}
-- Test comment to prevent recurrence of https://github.com/dbt-labs/dbt-bigquery/issues/896
""".lstrip()

overwrite_day_sql = """
{{
config(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
merge_range_sql,
merge_time_sql,
overwrite_date_sql,
overwrite_date_with_comment_at_end_sql,
overwrite_day_sql,
overwrite_day_with_copy_partitions_sql,
overwrite_partitions_sql,
Expand All @@ -40,6 +41,7 @@ def models(self):
"incremental_merge_range.sql": merge_range_sql,
"incremental_merge_time.sql": merge_time_sql,
"incremental_overwrite_date.sql": overwrite_date_sql,
"incremental_overwrite_date_with_comment_at_end.sql": overwrite_date_with_comment_at_end_sql,
"incremental_overwrite_day.sql": overwrite_day_sql,
"incremental_overwrite_day_with_copy_partitions.sql": overwrite_day_with_copy_partitions_sql,
"incremental_overwrite_partitions.sql": overwrite_partitions_sql,
Expand All @@ -65,15 +67,16 @@ def seeds(self):
def test__bigquery_assert_incremental_configurations_apply_the_right_strategy(self, project):
run_dbt(["seed"])
results = run_dbt()
assert len(results) == 11
assert len(results) == 12

results = run_dbt()
assert len(results) == 11
assert len(results) == 12
incremental_strategies = [
("incremental_merge_range", "merge_expected"),
("incremental_merge_time", "merge_expected"),
("incremental_overwrite_time", "incremental_overwrite_time_expected"),
("incremental_overwrite_date", "incremental_overwrite_date_expected"),
("incremental_overwrite_date_with_comment_at_end", "incremental_overwrite_date_expected"),
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
("incremental_overwrite_partitions", "incremental_overwrite_date_expected"),
("incremental_overwrite_day", "incremental_overwrite_day_expected"),
("incremental_overwrite_range", "incremental_overwrite_range_expected"),
Expand Down
Loading