implementation of selector selector method#12582
Conversation
|
Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #12582 +/- ##
==========================================
- Coverage 91.39% 91.39% -0.01%
==========================================
Files 203 203
Lines 25685 25715 +30
==========================================
+ Hits 23475 23501 +26
- Misses 2210 2214 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
|
||
| def test_selector_definition(self): | ||
| dct = get_selector_dict( | ||
| """\ | ||
| selectors: | ||
| - name: default | ||
| definition: | ||
| union: | ||
| - intersection: | ||
| - tag: foo | ||
| - tag: bar | ||
| - name: inherited | ||
| definition: | ||
| method: selector | ||
| value: default | ||
| """ | ||
| ) | ||
|
|
||
| sel_dict = SelectorDict.parse_from_selectors_list(dct["selectors"]) | ||
| assert sel_dict | ||
| definition = sel_dict["default"]["definition"] | ||
| expected = sel_dict["inherited"]["definition"] | ||
| self.assertEqual(expected, definition) | ||
|
|
||
| def test_selector_definition_with_exclusion(self): | ||
| dct = get_selector_dict( | ||
| """\ | ||
| selectors: | ||
| - name: default | ||
| definition: | ||
| union: | ||
| - intersection: | ||
| - tag: foo | ||
| - tag: bar | ||
| - name: inherited | ||
| definition: | ||
| union: | ||
| - method: selector | ||
| value: default | ||
| - exclude: | ||
| - tag: bar | ||
| - name: comparison | ||
| definition: | ||
| union: | ||
| - union: | ||
| - intersection: | ||
| - tag: foo | ||
| - tag: bar | ||
| - exclude: | ||
| - tag: bar | ||
| """ | ||
| ) | ||
|
|
||
| sel_dict = SelectorDict.parse_from_selectors_list((dct["selectors"])) | ||
| assert sel_dict | ||
| definition = sel_dict["inherited"]["definition"] | ||
| expected = sel_dict["comparison"]["definition"] | ||
| self.assertEqual(expected, definition) | ||
|
|
||
| def test_missing_selector(self): | ||
| dct = get_selector_dict( | ||
| """\ | ||
| selectors: | ||
| - name: inherited | ||
| definition: | ||
| method: selector | ||
| value: default | ||
| """ | ||
| ) | ||
| with self.assertRaises(DbtSelectorsError) as err: | ||
| SelectorDict.parse_from_selectors_list((dct["selectors"])) | ||
|
|
||
| self.assertEqual( | ||
| "Existing selector definition for default not found.", str(err.exception.msg) | ||
| ) |
There was a problem hiding this comment.
These tests depend on earlier inheritance behavior which should be removed as part of this feature, as that behavior will not let explicitly declared method: selector be resolved to SelectorSelectorMethod and only - selector:abcd would work.
The missing selector would be raised on runtime because now we can even declare selectors with wildcards.
|
Want to raise one risk here (if it hasn't already been raised) - one of the referenced issues describes: Where dbt behaves "implicitly" by ignoring the |
Just to be clear while the issue suggests respecting --exclude and --select with --selector flag, the feature isn't implemented that way. Please have a look at this to see the final scope of the feature that's implemented here. |
…eat/add-selector-selector-method
…eat/add-selector-selector-method
Resolves #5009
Resolves #10992
Problem
At present selectors can only be used by either setting default selector or passing them via
--selectorargument. This significantly limits the utility of selectors. We should be able to utilise selectors as just another selector method. This will allow us to cover these functionalities.Solution
Add a selector selector method class. This will require access to selector definitions and also for recursive calls to
get_selectedmethod from node selector. We pass these as extra arguments toSelectorMethodwhich will be ignored by existing methods but will be used bySelectorSelectorMethod. The selectors is passed from allResourceTypeSelectorso that this can be utilised upstream.Checklist