-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[BQ] Fix insert_overwrite with int + ts partitions #3098
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you think
table.partitioning_type
could ever beNone
here? I'd thinktable.time_partitioning is not None
also meanstable.partitioning_type
has a value, just being nit-pickyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine, you can ignore! I dug around docs a little and I think
holds true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah good catch though! if one of our intrepid
dbt-bigquery
beta testers manages to get an error likeNoneType has no attribute lower
, then we'll know who to blame (me) and where to fix it (here)