-
Notifications
You must be signed in to change notification settings - Fork 154
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
Implementation of metadata-based freshness #1060
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
31b3734
changelog
mikealfare 75e9898
turn on metadata-based source freshness capability
mikealfare 440b896
add boundary test to confirm get_table raises an error properly
mikealfare 1ae71ba
add metadata-based source freshness for a relation
mikealfare cf171da
remove unnecessary test setup
mikealfare 8aaf2c4
remove unnecessary fixture from test
mikealfare 79c9b5a
update from main
mikealfare 0697579
update from main
mikealfare 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Features | ||
body: Add support for checking table-last-modified by metadata | ||
time: 2023-12-18T15:54:09.69635-05:00 | ||
custom: | ||
Author: mikealfare | ||
Issue: "938" |
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
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,18 @@ | ||
import pytest | ||
|
||
from dbt.tests.util import get_connection | ||
from google.cloud.bigquery import Client, DatasetReference, TableReference | ||
from google.api_core.exceptions import NotFound | ||
|
||
|
||
@pytest.mark.parametrize("table_name", ["this_table_does_not_exist"]) | ||
def test_get_table_does_not_exist(project, table_name): | ||
""" | ||
TODO: replace dbt project methods with direct connection instantiation | ||
""" | ||
with get_connection(project.adapter) as conn: | ||
client: Client = conn.handle | ||
dataset_ref = DatasetReference(project.database, project.test_schema) | ||
table_ref = TableReference(dataset_ref, table_name) | ||
with pytest.raises(NotFound): | ||
client.get_table(table_ref) |
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,23 @@ | ||
SCHEMA_YML = """version: 2 | ||
sources: | ||
- name: test_source | ||
freshness: | ||
warn_after: {count: 10, period: hour} | ||
error_after: {count: 1, period: day} | ||
schema: "{{ env_var('DBT_GET_LAST_RELATION_TEST_SCHEMA') }}" | ||
tables: | ||
- name: test_source | ||
""" | ||
|
||
SEED_TEST_SOURCE_CSV = """ | ||
id,name | ||
1,Martin | ||
2,Jeter | ||
3,Ruth | ||
4,Gehrig | ||
5,DiMaggio | ||
6,Torre | ||
7,Mantle | ||
8,Berra | ||
9,Maris | ||
""".strip() |
30 changes: 30 additions & 0 deletions
30
tests/functional/adapter/sources_freshness_tests/test_get_relation_last_modified.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,30 @@ | ||
import os | ||
import pytest | ||
|
||
from dbt.tests.util import run_dbt | ||
|
||
from tests.functional.adapter.sources_freshness_tests import files | ||
|
||
|
||
class TestGetLastRelationModified: | ||
@pytest.fixture(scope="class") | ||
def seeds(self): | ||
return {"test_source.csv": files.SEED_TEST_SOURCE_CSV} | ||
|
||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return {"schema.yml": files.SCHEMA_YML} | ||
|
||
@pytest.fixture(scope="class", autouse=True) | ||
def setup(self, project): | ||
# we need the schema name for the sources section | ||
os.environ["DBT_GET_LAST_RELATION_TEST_SCHEMA"] = project.test_schema | ||
run_dbt(["seed"]) | ||
yield | ||
del os.environ["DBT_GET_LAST_RELATION_TEST_SCHEMA"] | ||
|
||
def test_get_last_relation_modified(self, project): | ||
results = run_dbt(["source", "freshness"]) | ||
assert len(results) == 1 | ||
result = results[0] | ||
assert result.status == "pass" |
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.
I added this test because we're seeing odd behavior with the
get_table
method (a BQ Client method). If we runget_table
during source freshness (line 726 inimpl.py
) on a table that does not exist, it hangs without returning the expectedNotFound
error, even when providingretry
. However when we do the same here, it seems to behave as expected.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 we understand this well enough to raise a bug with bigquery? https://github.com/googleapis/python-bigquery/issues
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.
There's this issue: googleapis/python-bigquery#1674