-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2200 from fishtown-analytics/fix/sql-header-in-in…
…crementals Fix missing sql_header for incremental models
- Loading branch information
Showing
8 changed files
with
100 additions
and
8 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
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
15 changes: 15 additions & 0 deletions
15
test/integration/022_bigquery_test/models/sql_header_model_incr.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,15 @@ | ||
|
||
{{ config(materialized="incremental") }} | ||
|
||
{# This will fail if it is not extracted correctly #} | ||
{% call set_sql_header(config) %} | ||
CREATE TEMPORARY FUNCTION a_to_b(str STRING) | ||
RETURNS STRING AS ( | ||
CASE | ||
WHEN LOWER(str) = 'a' THEN 'b' | ||
ELSE str | ||
END | ||
); | ||
{% endcall %} | ||
|
||
select a_to_b(dupe) as dupe from {{ ref('view_model') }} |
31 changes: 31 additions & 0 deletions
31
test/integration/022_bigquery_test/models/sql_header_model_incr_insert_overwrite.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,31 @@ | ||
|
||
{# | ||
Ensure that the insert overwrite incremental strategy | ||
works correctly when a UDF is used in a sql_header. The | ||
failure mode here is that dbt might inject the UDF header | ||
twice: once for the `create table` and then again for the | ||
merge statement. | ||
#} | ||
|
||
{{ config( | ||
materialized="incremental", | ||
incremental_strategy='insert_overwrite', | ||
partition_by={"field": "dt", "data_type": "date"} | ||
) }} | ||
|
||
{# This will fail if it is not extracted correctly #} | ||
{% call set_sql_header(config) %} | ||
CREATE TEMPORARY FUNCTION a_to_b(str STRING) | ||
RETURNS STRING AS ( | ||
CASE | ||
WHEN LOWER(str) = 'a' THEN 'b' | ||
ELSE str | ||
END | ||
); | ||
{% endcall %} | ||
|
||
select | ||
current_date() as dt, | ||
a_to_b(dupe) as dupe | ||
|
||
from {{ ref('view_model') }} |
32 changes: 32 additions & 0 deletions
32
test/integration/022_bigquery_test/models/sql_header_model_incr_insert_overwrite_static.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,32 @@ | ||
|
||
{# | ||
Ensure that the insert overwrite incremental strategy | ||
works correctly when a UDF is used in a sql_header. The | ||
failure mode here is that dbt might inject the UDF header | ||
twice: once for the `create table` and then again for the | ||
merge statement. | ||
#} | ||
|
||
{{ config( | ||
materialized="incremental", | ||
incremental_strategy='insert_overwrite', | ||
partition_by={"field": "dt", "data_type": "date"}, | ||
partitions=["'2020-01-1'"] | ||
) }} | ||
|
||
{# This will fail if it is not extracted correctly #} | ||
{% call set_sql_header(config) %} | ||
CREATE TEMPORARY FUNCTION a_to_b(str STRING) | ||
RETURNS STRING AS ( | ||
CASE | ||
WHEN LOWER(str) = 'a' THEN 'b' | ||
ELSE str | ||
END | ||
); | ||
{% endcall %} | ||
|
||
select | ||
cast('2020-01-01' as date) as dt, | ||
a_to_b(dupe) as dupe | ||
|
||
from {{ ref('view_model') }} |
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