-
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.
3448 user defined default selection criteria (#3875)
* Added selector default * Updated code from review feedback * Fix schema.yml location Co-authored-by: Jeremy Cohen <jeremy@fishtownanalytics.com>
- Loading branch information
Showing
15 changed files
with
203 additions
and
17 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
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
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
2 changes: 2 additions & 0 deletions
2
test/integration/073_default_selectors_tests/data/model_c.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,2 @@ | ||
fun,_loaded_at | ||
1,2021-04-19 01:00:00 |
1 change: 1 addition & 0 deletions
1
test/integration/073_default_selectors_tests/models/model_a.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 @@ | ||
SELECT 1 AS fun |
1 change: 1 addition & 0 deletions
1
test/integration/073_default_selectors_tests/models/model_b.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 @@ | ||
SELECT 1 AS fun |
35 changes: 35 additions & 0 deletions
35
test/integration/073_default_selectors_tests/models/schema.yml
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,35 @@ | ||
version: 2 | ||
|
||
sources: | ||
- name: src | ||
schema: "{{ target.schema }}" | ||
freshness: | ||
warn_after: {count: 24, period: hour} | ||
loaded_at_field: _loaded_at | ||
tables: | ||
- name: source_a | ||
identifier: model_c | ||
columns: | ||
- name: fun | ||
- name: _loaded_at | ||
- name: src | ||
schema: "{{ target.schema }}" | ||
freshness: | ||
warn_after: {count: 24, period: hour} | ||
loaded_at_field: _loaded_at | ||
tables: | ||
- name: source_b | ||
identifier: model_c | ||
columns: | ||
- name: fun | ||
- name: _loaded_at | ||
|
||
models: | ||
- name: model_a | ||
columns: | ||
- name: fun | ||
tags: [marketing] | ||
- name: model_b | ||
columns: | ||
- name: fun | ||
tags: [finance] |
77 changes: 77 additions & 0 deletions
77
test/integration/073_default_selectors_tests/test_default_selectors.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,77 @@ | ||
import yaml | ||
from test.integration.base import DBTIntegrationTest, use_profile | ||
|
||
|
||
class TestDefaultSelectors(DBTIntegrationTest): | ||
'''Test the selectors default argument''' | ||
@property | ||
def schema(self): | ||
return 'test_default_selectors_101' | ||
|
||
@property | ||
def models(self): | ||
return 'models' | ||
|
||
@property | ||
def project_config(self): | ||
return { | ||
'config-version': 2, | ||
'source-paths': ['models'], | ||
'data-paths': ['data'], | ||
'seeds': { | ||
'quote_columns': False, | ||
}, | ||
} | ||
|
||
@property | ||
def selectors_config(self): | ||
return yaml.safe_load(''' | ||
selectors: | ||
- name: default_selector | ||
description: test default selector | ||
definition: | ||
union: | ||
- method: source | ||
value: "test.src.source_a" | ||
- method: fqn | ||
value: "model_a" | ||
default: true | ||
''') | ||
|
||
def list_and_assert(self, expected): | ||
'''list resources in the project with the selectors default''' | ||
listed = self.run_dbt(['ls', '--resource-type', 'model']) | ||
|
||
assert len(listed) == len(expected) | ||
|
||
def compile_and_assert(self, expected): | ||
'''Compile project with the selectors default''' | ||
compiled = self.run_dbt(['compile']) | ||
|
||
assert len(compiled.results) == len(expected) | ||
assert compiled.results[0].node.name == expected[0] | ||
|
||
def run_and_assert(self, expected): | ||
run = self.run_dbt(['run']) | ||
|
||
assert len(run.results) == len(expected) | ||
assert run.results[0].node.name == expected[0] | ||
|
||
def freshness_and_assert(self, expected): | ||
self.run_dbt(['seed', '-s', 'test.model_c']) | ||
freshness = self.run_dbt(['source', 'freshness']) | ||
|
||
assert len(freshness.results) == len(expected) | ||
assert freshness.results[0].node.name == expected[0] | ||
|
||
@use_profile('postgres') | ||
def test__postgres__model_a_only(self): | ||
expected_model = ['model_a'] | ||
|
||
self.list_and_assert(expected_model) | ||
self.compile_and_assert(expected_model) | ||
|
||
def test__postgres__source_a_only(self): | ||
expected_source = ['source_a'] | ||
|
||
self.freshness_and_assert(expected_source) |
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