-
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.
- Loading branch information
Showing
10 changed files
with
247 additions
and
21 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
11 changes: 11 additions & 0 deletions
11
test/integration/022_bigquery_test/partition-models/my_model.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,11 @@ | ||
|
||
|
||
{{ | ||
config( | ||
materialized="table", | ||
partition_by=var('partition_by'), | ||
cluster_by=var('cluster_by') | ||
) | ||
}} | ||
|
||
select 1 as id, 'dr. bigquery' as name, current_timestamp() as cur_time, current_date() as cur_date |
39 changes: 39 additions & 0 deletions
39
test/integration/022_bigquery_test/scripting-models/incremental_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,39 @@ | ||
|
||
{{ | ||
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 ( | ||
select 1 as id, current_date() as ts union all | ||
select 2 as id, current_date() as ts union all | ||
select 3 as id, current_date() as ts union all | ||
select 4 as id, current_date() as ts | ||
|
||
{% if is_incremental() %} | ||
union all | ||
select 5 as id, current_date() as ts union all | ||
select 6 as id, current_date() as ts union all | ||
select 7 as id, current_date() as ts union all | ||
select 8 as id, current_date() as ts | ||
{% endif %} | ||
) | ||
|
||
select * from data | ||
|
||
{% if is_incremental() %} | ||
where id > _dbt_max_partition | ||
{% endif %} |
34 changes: 34 additions & 0 deletions
34
test/integration/022_bigquery_test/scripting-models/incremental_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,34 @@ | ||
|
||
{{ | ||
config( | ||
materialized="incremental", | ||
unique_key="id", | ||
cluster_by="id", | ||
partition_by={ | ||
"field": "ts", | ||
"data_type": "timestamp" | ||
} | ||
) | ||
}} | ||
|
||
|
||
with data as ( | ||
select 1 as id, current_timestamp() as ts union all | ||
select 2 as id, current_timestamp() as ts union all | ||
select 3 as id, current_timestamp() as ts union all | ||
select 4 as id, current_timestamp() as ts | ||
|
||
{% if is_incremental() %} | ||
union all | ||
select 5 as id, current_timestamp() as ts union all | ||
select 6 as id, current_timestamp() as ts union all | ||
select 7 as id, current_timestamp() as ts union all | ||
select 8 as id, current_timestamp() as ts | ||
{% endif %} | ||
) | ||
|
||
select * from data | ||
|
||
{% if is_incremental() %} | ||
where ts > _dbt_max_partition | ||
{% endif %} |
49 changes: 49 additions & 0 deletions
49
test/integration/022_bigquery_test/test_bigquery_changing_partitions.py
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,49 @@ | ||
from test.integration.base import DBTIntegrationTest, FakeArgs, use_profile | ||
import json | ||
|
||
class TestChangingPartitions(DBTIntegrationTest): | ||
|
||
@property | ||
def schema(self): | ||
return "bigquery_test_022" | ||
|
||
@property | ||
def models(self): | ||
return "partition-models" | ||
|
||
def test_change(self, before, after): | ||
results = self.run_dbt(['run', '--vars', json.dumps(before)]) | ||
self.assertEqual(len(results), 1) | ||
|
||
results = self.run_dbt(['run', '--vars', json.dumps(after)]) | ||
self.assertEqual(len(results), 1) | ||
|
||
def test_add_partition(self): | ||
before = {"partition_by": None, "cluster_by": None} | ||
after = {"partition_by": "date(cur_time)", "cluster_by": None} | ||
self.test_change(before, after) | ||
|
||
def test_remove_partition(self): | ||
before = {"partition_by": "date(cur_time)", "cluster_by": None} | ||
after = {"partition_by": None, "cluster_by": None} | ||
self.test_change(before, after) | ||
|
||
def test_change_partitions(self): | ||
before = {"partition_by": "date(cur_time)", "cluster_by": None} | ||
after = {"partition_by": "cur_date", "cluster_by": None} | ||
self.test_change(before, after) | ||
|
||
def test_add_clustering(self): | ||
before = {"partition_by": "date(cur_time)", "cluster_by": None} | ||
after = {"partition_by": "cur_date", "cluster_by": "id"} | ||
self.test_change(before, after) | ||
|
||
def test_remove_clustering(self): | ||
before = {"partition_by": "date(cur_time)", "cluster_by": "id"} | ||
after = {"partition_by": "cur_date", "cluster_by": None} | ||
self.test_change(before, after) | ||
|
||
def test_change_clustering(self): | ||
before = {"partition_by": "date(cur_time)", "cluster_by": "id"} | ||
after = {"partition_by": "cur_date", "cluster_by": "name"} | ||
self.test_change(before, after) |
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,22 @@ | ||
from test.integration.base import DBTIntegrationTest, FakeArgs, use_profile | ||
|
||
class TestBigQueryScripting(DBTIntegrationTest): | ||
|
||
@property | ||
def schema(self): | ||
return "bigquery_test_022" | ||
|
||
@property | ||
def models(self): | ||
return "scripting-models" | ||
|
||
@property | ||
def profile_config(self): | ||
return self.bigquery_profile() | ||
|
||
def assert_incrementals(self): | ||
results = self.run_dbt() | ||
self.assertEqual(len(results), 2) | ||
|
||
self.run_dbt() | ||
self.assertEqual(len(results), 2) |
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