-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix insert_overwrite with int64, ts partitions. Add tests
- Loading branch information
Showing
14 changed files
with
197 additions
and
14 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
File renamed without changes.
5 changes: 5 additions & 0 deletions
5
test/integration/022_bigquery_test/data/incremental_overwrite_day_expected.csv
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,5 @@ | ||
id,date_time | ||
10,2020-01-01 00:00:00 | ||
20,2020-01-01 00:00:00 | ||
30,2020-01-02 00:00:00 | ||
40,2020-01-02 00:00:00 |
5 changes: 5 additions & 0 deletions
5
test/integration/022_bigquery_test/data/incremental_overwrite_range_expected.csv
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,5 @@ | ||
id,date_int | ||
10,20200101 | ||
20,20200101 | ||
30,20200102 | ||
40,20200102 |
5 changes: 5 additions & 0 deletions
5
test/integration/022_bigquery_test/data/incremental_overwrite_time_expected.csv
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,5 @@ | ||
id,date_day | ||
10,2020-01-01 01:00:00 | ||
20,2020-01-01 01:00:00 | ||
30,2020-01-01 02:00:00 | ||
40,2020-01-01 02:00:00 |
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
36 changes: 36 additions & 0 deletions
36
test/integration/022_bigquery_test/scripting-models/incremental_overwrite_day.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,36 @@ | ||
|
||
{{ | ||
config( | ||
materialized="incremental", | ||
incremental_strategy='insert_overwrite', | ||
cluster_by="id", | ||
partition_by={ | ||
"field": "date_time", | ||
"data_type": "timestamp" | ||
} | ||
) | ||
}} | ||
|
||
|
||
with data as ( | ||
select 1 as id, cast('2020-01-01' as timestamp) as date_time union all | ||
select 2 as id, cast('2020-01-01' as timestamp) as date_time union all | ||
select 3 as id, cast('2020-01-01' as timestamp) as date_time union all | ||
select 4 as id, cast('2020-01-01' as timestamp) as date_time | ||
|
||
{% if is_incremental() %} | ||
union all | ||
-- 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 timestamp) as date_time union all | ||
select 20 as id, cast('2020-01-01' as timestamp) as date_time union all | ||
select 30 as id, cast('2020-01-02' as timestamp) as date_time union all | ||
select 40 as id, cast('2020-01-02' as timestamp) as date_time | ||
{% endif %} | ||
) | ||
|
||
select * from data | ||
|
||
{% if is_incremental() %} | ||
where ts >= _dbt_max_partition | ||
{% endif %} |
37 changes: 37 additions & 0 deletions
37
test/integration/022_bigquery_test/scripting-models/incremental_overwrite_partitions.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,37 @@ | ||
|
||
{{ | ||
config( | ||
materialized="incremental", | ||
incremental_strategy='insert_overwrite', | ||
cluster_by="id", | ||
partitions=["'2020-01-01'","'2020-01-02'"], | ||
partition_by={ | ||
"field": "date_day", | ||
"data_type": "date" | ||
} | ||
) | ||
}} | ||
|
||
|
||
with data as ( | ||
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 | ||
|
||
{% if is_incremental() %} | ||
union all | ||
-- 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 ts in ({{ config.get("partitions") | join(",") }}) | ||
{% endif %} |
41 changes: 41 additions & 0 deletions
41
test/integration/022_bigquery_test/scripting-models/incremental_overwrite_range.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,41 @@ | ||
|
||
{{ | ||
config( | ||
materialized="incremental", | ||
incremental_strategy='insert_overwrite', | ||
cluster_by="id", | ||
partition_by={ | ||
"field": "date_int", | ||
"data_type": "int64", | ||
"range": { | ||
"start": 20200101, | ||
"end": 20200110, | ||
"interval": 1 | ||
} | ||
} | ||
) | ||
}} | ||
|
||
|
||
with data as ( | ||
select 1 as id, 20200101 as date_int union all | ||
select 2 as id, 20200101 as date_int union all | ||
select 3 as id, 20200101 as date_int union all | ||
select 4 as id, 20200101 as date_int | ||
|
||
{% if is_incremental() %} | ||
union all | ||
-- we want to overwrite the 4 records in the 20200101 partition | ||
-- with the 2 records below, but add two more in the 20200102 partition | ||
select 10 as id, 20200101 as date_int union all | ||
select 20 as id, 20200101 as date_int union all | ||
select 30 as id, 20200102 as date_int union all | ||
select 40 as id, 20200102 as date_int as date_day | ||
{% endif %} | ||
) | ||
|
||
select * from data | ||
|
||
{% if is_incremental() %} | ||
where ts >= _dbt_max_partition | ||
{% endif %} |
37 changes: 37 additions & 0 deletions
37
test/integration/022_bigquery_test/scripting-models/incremental_overwrite_time.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,37 @@ | ||
|
||
{{ | ||
config( | ||
materialized="incremental", | ||
incremental_strategy='insert_overwrite', | ||
cluster_by="id", | ||
partition_by={ | ||
"field": "date_hour", | ||
"data_type": "timestamp", | ||
"granularity": "hour" | ||
} | ||
) | ||
}} | ||
|
||
|
||
with data as ( | ||
select 1 as id, cast('2020-01-01 01:00:00' as timestamp) as date_hour union all | ||
select 2 as id, cast('2020-01-01 01:00:00' as timestamp) as date_hour union all | ||
select 3 as id, cast('2020-01-01 01:00:00' as timestamp) as date_hour union all | ||
select 4 as id, cast('2020-01-01 01:00:00' as timestamp) as date_hour | ||
|
||
{% if is_incremental() %} | ||
union all | ||
-- we want to overwrite the 4 records in the 2020-01-01 01:00:00 partition | ||
-- with the 2 records below, but add two more in the 2020-01-00 02:00:00 partition | ||
select 10 as id, cast('2020-01-01 01:00:00' as timestamp) as date_hour union all | ||
select 20 as id, cast('2020-01-01 01:00:00' as timestamp) as date_hour union all | ||
select 30 as id, cast('2020-01-01 02:00:00' as timestamp) as date_hour union all | ||
select 40 as id, cast('2020-01-01 02:00:00' as timestamp) as date_hour | ||
{% endif %} | ||
) | ||
|
||
select * from data | ||
|
||
{% if is_incremental() %} | ||
where ts >= _dbt_max_partition | ||
{% 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