-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADAP-1051 - Temp Table Drop Fix (#1076)
* Fix for ADAP-1051 * adding changie files * adding changie files * Revert "adding changie files" This reverts commit f51ca0c. * Add test cases * Revert adapters.sql * Update body for changie --------- Co-authored-by: Doug Beatty <[email protected]> Co-authored-by: Mike Alfare <[email protected]> Co-authored-by: Teresa Martyny <[email protected]> Co-authored-by: Mila Page <[email protected]>
- Loading branch information
1 parent
b8bc9c0
commit b9018f7
Showing
3 changed files
with
70 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Fixes | ||
body: Drop intermediate objects created in BigQuery for incremental models | ||
time: 2024-01-20T18:08:18.817915-06:00 | ||
custom: | ||
Author: vinit2107 | ||
Issue: "1036" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import pytest | ||
from google.api_core.exceptions import NotFound | ||
from dbt.adapters.bigquery.relation import BigQueryRelation | ||
from dbt.tests.util import run_dbt, get_connection, relation_from_name | ||
|
||
|
||
_INCREMENTAL_MODEL = """ | ||
{{ | ||
config( | ||
materialized="incremental", | ||
on_schema_change="sync_all_columns" | ||
) | ||
}} | ||
select 20 as id, cast('2020-01-01 01: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 | ||
""" | ||
|
||
_INCREMENTAL_MODEL_YAML = """version: 2 | ||
models: | ||
- name: test_drop_relation | ||
columns: | ||
- name: id | ||
type: int64 | ||
- name: date_hour | ||
type: datetime | ||
""" | ||
|
||
|
||
class BaseIncrementalModelConfig: | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"test_drop_relation.sql": _INCREMENTAL_MODEL, | ||
"schema.yml": _INCREMENTAL_MODEL_YAML, | ||
} | ||
|
||
|
||
class TestIncrementalModel(BaseIncrementalModelConfig): | ||
def test_incremental_model_succeeds(self, project): | ||
""" | ||
Steps: | ||
1. Create the model | ||
2. Merge into the model using __dbt_tmp table | ||
3. Assert raises NotFound exception | ||
""" | ||
results = run_dbt(["run"]) | ||
assert len(results) == 1 | ||
results = run_dbt(["run"]) | ||
assert len(results) == 1 | ||
relation: BigQueryRelation = relation_from_name( | ||
project.adapter, "test_drop_relation__dbt_tmp" | ||
) | ||
adapter = project.adapter | ||
with pytest.raises(NotFound): | ||
with get_connection(project.adapter) as conn: | ||
conn.handle.get_table( | ||
adapter.connections.get_bq_table( | ||
relation.database, relation.schema, relation.table | ||
) | ||
) |