-
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.
Merge pull request #3098 from fishtown-analytics/fix/bq-insert-overwr…
…ite-int-ts-partitions [BQ] Fix insert_overwrite with int + ts partitions
- Loading branch information
Showing
19 changed files
with
336 additions
and
117 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_hour | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
id,date_time | ||
1,2020-01-01 00:00:00 | ||
2,2020-01-01 00:00:00 | ||
3,2020-01-01 00:00:00 | ||
4,2020-01-02 00:00:00 | ||
5,2020-01-02 00:00:00 | ||
6,2020-01-02 00:00:00 |
46 changes: 46 additions & 0 deletions
46
test/integration/022_bigquery_test/incremental-strategy-models/incremental_merge_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,46 @@ | ||
|
||
{{ | ||
config( | ||
materialized="incremental", | ||
unique_key="id", | ||
cluster_by="id", | ||
partition_by={ | ||
"field": "id", | ||
"data_type": "int64", | ||
"range": { | ||
"start": 1, | ||
"end": 10, | ||
"interval": 1 | ||
} | ||
} | ||
) | ||
}} | ||
|
||
|
||
with data as ( | ||
|
||
{% if not is_incremental() %} | ||
|
||
select 1 as id, cast('2020-01-01' as datetime) as date_time union all | ||
select 2 as id, cast('2020-01-01' as datetime) as date_time union all | ||
select 3 as id, cast('2020-01-01' as datetime) as date_time union all | ||
select 4 as id, cast('2020-01-01' as datetime) as date_time | ||
|
||
{% else %} | ||
|
||
select 1 as id, cast('2020-01-01' as datetime) as date_time union all | ||
select 2 as id, cast('2020-01-01' as datetime) as date_time union all | ||
select 3 as id, cast('2020-01-01' as datetime) as date_time union all | ||
select 4 as id, cast('2020-01-02' as datetime) as date_time union all | ||
select 5 as id, cast('2020-01-02' as datetime) as date_time union all | ||
select 6 as id, cast('2020-01-02' as datetime) as date_time | ||
|
||
{% endif %} | ||
|
||
) | ||
|
||
select * from data | ||
|
||
{% if is_incremental() %} | ||
where id >= (select max(id) from {{ this }}) | ||
{% endif %} |
42 changes: 42 additions & 0 deletions
42
test/integration/022_bigquery_test/incremental-strategy-models/incremental_merge_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,42 @@ | ||
|
||
{{ | ||
config( | ||
materialized="incremental", | ||
unique_key="id", | ||
cluster_by="id", | ||
partition_by={ | ||
"field": "date_time", | ||
"data_type": "datetime" | ||
} | ||
) | ||
}} | ||
|
||
|
||
|
||
with data as ( | ||
|
||
{% if not is_incremental() %} | ||
|
||
select 1 as id, cast('2020-01-01' as datetime) as date_time union all | ||
select 2 as id, cast('2020-01-01' as datetime) as date_time union all | ||
select 3 as id, cast('2020-01-01' as datetime) as date_time union all | ||
select 4 as id, cast('2020-01-01' as datetime) as date_time | ||
|
||
{% else %} | ||
|
||
select 1 as id, cast('2020-01-01' as datetime) as date_time union all | ||
select 2 as id, cast('2020-01-01' as datetime) as date_time union all | ||
select 3 as id, cast('2020-01-01' as datetime) as date_time union all | ||
select 4 as id, cast('2020-01-02' as datetime) as date_time union all | ||
select 5 as id, cast('2020-01-02' as datetime) as date_time union all | ||
select 6 as id, cast('2020-01-02' as datetime) as date_time | ||
|
||
{% endif %} | ||
|
||
) | ||
|
||
select * from data | ||
|
||
{% if is_incremental() %} | ||
where date_time > (select max(date_time) 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
41 changes: 41 additions & 0 deletions
41
test/integration/022_bigquery_test/incremental-strategy-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,41 @@ | ||
|
||
{{ | ||
config( | ||
materialized="incremental", | ||
incremental_strategy='insert_overwrite', | ||
cluster_by="id", | ||
partition_by={ | ||
"field": "date_time", | ||
"data_type": "datetime" | ||
} | ||
) | ||
}} | ||
|
||
|
||
with data as ( | ||
|
||
{% if not is_incremental() %} | ||
|
||
select 1 as id, cast('2020-01-01' as datetime) as date_time union all | ||
select 2 as id, cast('2020-01-01' as datetime) as date_time union all | ||
select 3 as id, cast('2020-01-01' as datetime) as date_time union all | ||
select 4 as id, cast('2020-01-01' as datetime) as date_time | ||
|
||
{% 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 datetime) as date_time union all | ||
select 20 as id, cast('2020-01-01' as datetime) as date_time union all | ||
select 30 as id, cast('2020-01-02' as datetime) as date_time union all | ||
select 40 as id, cast('2020-01-02' as datetime) as date_time | ||
|
||
{% endif %} | ||
|
||
) | ||
|
||
select * from data | ||
|
||
{% if is_incremental() %} | ||
where date_time >= _dbt_max_partition | ||
{% endif %} |
42 changes: 42 additions & 0 deletions
42
...ration/022_bigquery_test/incremental-strategy-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,42 @@ | ||
|
||
{{ | ||
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 ( | ||
|
||
{% 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 in ({{ config.get("partitions") | join(",") }}) | ||
{% endif %} |
46 changes: 46 additions & 0 deletions
46
...integration/022_bigquery_test/incremental-strategy-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,46 @@ | ||
|
||
{{ | ||
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 ( | ||
|
||
{% if not is_incremental() %} | ||
|
||
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 | ||
|
||
{% else %} | ||
|
||
-- 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 | ||
|
||
{% endif %} | ||
|
||
) | ||
|
||
select * from data | ||
|
||
{% if is_incremental() %} | ||
where date_int >= _dbt_max_partition | ||
{% endif %} |
42 changes: 42 additions & 0 deletions
42
.../integration/022_bigquery_test/incremental-strategy-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,42 @@ | ||
|
||
{{ | ||
config( | ||
materialized="incremental", | ||
incremental_strategy='insert_overwrite', | ||
cluster_by="id", | ||
partition_by={ | ||
"field": "date_hour", | ||
"data_type": "datetime", | ||
"granularity": "hour" | ||
} | ||
) | ||
}} | ||
|
||
|
||
with data as ( | ||
|
||
{% if not is_incremental() %} | ||
|
||
select 1 as id, cast('2020-01-01 01:00:00' as datetime) as date_hour union all | ||
select 2 as id, cast('2020-01-01 01:00:00' as datetime) as date_hour union all | ||
select 3 as id, cast('2020-01-01 01:00:00' as datetime) as date_hour union all | ||
select 4 as id, cast('2020-01-01 01:00:00' as datetime) as date_hour | ||
|
||
{% else %} | ||
|
||
-- 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 datetime) as date_hour union all | ||
select 20 as id, cast('2020-01-01 01:00:00' as datetime) as date_hour union all | ||
select 30 as id, cast('2020-01-01 02:00:00' as datetime) as date_hour union all | ||
select 40 as id, cast('2020-01-01 02:00:00' as datetime) as date_hour | ||
|
||
{% endif %} | ||
|
||
) | ||
|
||
select * from data | ||
|
||
{% if is_incremental() %} | ||
where date_hour >= _dbt_max_partition | ||
{% endif %} |
Oops, something went wrong.