Skip to content

3448 user defined default selection criteria #3875

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

Merged

Conversation

TeddyCr
Copy link
Contributor

@TeddyCr TeddyCr commented Sep 13, 2021

resolves #3448

Description

This PR introduces a default field in the selectors.yml allowing users to define 1 default selector that will execute the definition on each dbt run, dbt compile, dbt list, or dbt source freshness.

This is a clean PR of #3865 fixing git status after rebased perform to fix CLA error.

Checklist

  • I have signed the CLA
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • I have updated the CHANGELOG.md and added information about my change to the "dbt next" section.

Sorry, something went wrong.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@jtcohen6
Copy link
Contributor

Closing and reopening to trigger adapter integration tests

@jtcohen6 jtcohen6 closed this Sep 13, 2021
@jtcohen6 jtcohen6 reopened this Sep 13, 2021
Copy link
Contributor

@jtcohen6 jtcohen6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TeddyCr This looks really really good! One last comment re: logging, and (if you feel up to it) DRYing up our task method code a bit.

Thanks for reopening the new PR and passing the CLA check, sorry again for the bother.

for selector_name, selector in self.selectors.items():
if selector["default"] is True:
name = selector_name
print_timestamped_line(f'Using default selector {name}')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really happy to have logging that will help avoid user confusion. Two quick thoughts:

  • [cosmetic] I think this should just be logger.info rather than print_timestamped_line. It feels more like the Found 5 models, ... line (which doesn't include a timestamp), versus the actual execution steps that print with timestamps below it.
  • [functional] We don't want to log this line every time the user has a default selector defined, only if it's being used (i.e. no CLI --select or --exclude args). So I think this logging needs to go in the get_selection_spec task method instead, in the second conditional branch.

Since that's one more line of code to add in three places, I'm thinking: All of these tasks now use the same exact definition of get_selection_spec (thanks to #3554). What do you think of just updating the GraphRunnableTask method, so that instead of implementing as an abstractmethod it actually defines the logic that compile, list, and freshness will all use? Then we can delete the duplicated code from compile, list, and freshness, since they'll just inherit from GraphRunnableTask (just as run, test, etc inherit from compile).

https://github.com/dbt-labs/dbt/blob/3effade26603a38fa71b10990a82e3318faad7b8/core/dbt/task/runnable.py#L106-L110

Copy link
Contributor Author

@TeddyCr TeddyCr Sep 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jtcohen6 Do you know why list.py has spec = parse_difference(self.selector, ... in def get_selection_spec while freshness and compile have spec = parse_difference(self.args.select ?

Copy link
Contributor

@jtcohen6 jtcohen6 Sep 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TeddyCr Ah, it's just because list accepts both models and select. So options are:

  • reimplement get_selection_spec for list alone
  • implement selector selection_arg as a property on GraphRunnableTask, and override just for ListTask

I'm leaning toward the latter

Copy link
Contributor

@jtcohen6 jtcohen6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TeddyCr Thanks for all the amazing work here! I'd really like to get this change in ahead of v0.21.0-rc1, so I'm going to merge this PR as soon as the tests pass. Then, I'll open a follow-on PR just to clean up the last bit of logging and duplicative task logic.

@jtcohen6 jtcohen6 merged commit 4845174 into dbt-labs:develop Sep 16, 2021
@jtcohen6 jtcohen6 mentioned this pull request Sep 16, 2021
4 tasks
iknox-fa pushed a commit that referenced this pull request Feb 8, 2022
* Added selector default

* Updated code from review feedback

* Fix schema.yml location

Co-authored-by: Jeremy Cohen <jeremy@fishtownanalytics.com>

automatic commit by git-black, original commits:
  4845174
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

User-defined default selection criteria
2 participants