-
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.
Recognize when loaded_at_field is explicitly set to null (#10065)
* add support for explicit nulls for loaded_at_field * add test * changelog * add parsing for tests * centralize logic a bit * account for sources being None * fix bug * remove new field from SourceDefinition * add validation for empty string, mroe tests
- Loading branch information
Showing
5 changed files
with
180 additions
and
3 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: Support overriding source level loaded_at_field with a null table level definition | ||
time: 2024-04-29T11:46:10.100373-05:00 | ||
custom: | ||
Author: emmyoop | ||
Issue: "9320" |
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
136 changes: 136 additions & 0 deletions
136
tests/functional/sources/test_source_loaded_at_field.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,136 @@ | ||
import pytest | ||
from dbt.tests.util import run_dbt, get_manifest, write_file | ||
from dbt.exceptions import YamlParseDictError | ||
|
||
|
||
loaded_at_field_null_schema_yml = """ | ||
sources: | ||
- name: test_source | ||
freshness: | ||
warn_after: | ||
count: 1 | ||
period: day | ||
error_after: | ||
count: 4 | ||
period: day | ||
loaded_at_field: updated_at | ||
tables: | ||
- name: table1 | ||
loaded_at_field: null | ||
""" | ||
|
||
loaded_at_field_blank_schema_yml = """ | ||
sources: | ||
- name: test_source | ||
freshness: | ||
warn_after: | ||
count: 1 | ||
period: day | ||
error_after: | ||
count: 4 | ||
period: day | ||
loaded_at_field: updated_at | ||
tables: | ||
- name: table1 | ||
loaded_at_field: null | ||
""" | ||
|
||
loaded_at_field_missing_schema_yml = """ | ||
sources: | ||
- name: test_source | ||
freshness: | ||
warn_after: | ||
count: 1 | ||
period: day | ||
error_after: | ||
count: 4 | ||
period: day | ||
loaded_at_field: updated_at | ||
tables: | ||
- name: table1 | ||
""" | ||
|
||
loaded_at_field_defined_schema_yml = """ | ||
sources: | ||
- name: test_source | ||
freshness: | ||
warn_after: | ||
count: 1 | ||
period: day | ||
error_after: | ||
count: 4 | ||
period: day | ||
loaded_at_field: updated_at | ||
tables: | ||
- name: table1 | ||
loaded_at_field: updated_at_another_place | ||
""" | ||
|
||
loaded_at_field_empty_string_schema_yml = """ | ||
sources: | ||
- name: test_source | ||
freshness: | ||
warn_after: | ||
count: 1 | ||
period: day | ||
error_after: | ||
count: 4 | ||
period: day | ||
loaded_at_field: updated_at | ||
tables: | ||
- name: table1 | ||
loaded_at_field: "" | ||
""" | ||
|
||
|
||
class TestParsingLoadedAtField: | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return {"schema.yml": loaded_at_field_null_schema_yml} | ||
|
||
def test_loaded_at_field(self, project): | ||
# test setting loaded_at_field to null explicitly at table level | ||
run_dbt(["parse"]) | ||
manifest = get_manifest(project.project_root) | ||
|
||
assert "source.test.test_source.table1" in manifest.sources | ||
assert manifest.sources.get("source.test.test_source.table1").loaded_at_field is None | ||
|
||
# test setting loaded_at_field at source level, do not set at table level | ||
# end up with source level loaded_at_field | ||
write_file( | ||
loaded_at_field_missing_schema_yml, project.project_root, "models", "schema.yml" | ||
) | ||
run_dbt(["parse"]) | ||
manifest = get_manifest(project.project_root) | ||
assert "source.test.test_source.table1" in manifest.sources | ||
assert ( | ||
manifest.sources.get("source.test.test_source.table1").loaded_at_field == "updated_at" | ||
) | ||
|
||
# test setting loaded_at_field to nothing, should override Source value for None | ||
write_file(loaded_at_field_blank_schema_yml, project.project_root, "models", "schema.yml") | ||
run_dbt(["parse"]) | ||
manifest = get_manifest(project.project_root) | ||
|
||
assert "source.test.test_source.table1" in manifest.sources | ||
assert manifest.sources.get("source.test.test_source.table1").loaded_at_field is None | ||
|
||
# test setting loaded_at_field at table level to a value - it should override source level | ||
write_file( | ||
loaded_at_field_defined_schema_yml, project.project_root, "models", "schema.yml" | ||
) | ||
run_dbt(["parse"]) | ||
manifest = get_manifest(project.project_root) | ||
assert "source.test.test_source.table1" in manifest.sources | ||
assert ( | ||
manifest.sources.get("source.test.test_source.table1").loaded_at_field | ||
== "updated_at_another_place" | ||
) | ||
|
||
# test setting loaded_at_field at table level to an empty string - should error | ||
write_file( | ||
loaded_at_field_empty_string_schema_yml, project.project_root, "models", "schema.yml" | ||
) | ||
with pytest.raises(YamlParseDictError): | ||
run_dbt(["parse"]) |