Skip to content
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

[CT-2562] [Feature] support "depend on macro" selector in --select #7596

Closed
3 tasks done
tema-popov opened this issue May 11, 2023 · 5 comments
Closed
3 tasks done

[CT-2562] [Feature] support "depend on macro" selector in --select #7596

tema-popov opened this issue May 11, 2023 · 5 comments
Labels
enhancement New feature or request wontfix Not a bug or out of scope for dbt-core

Comments

@tema-popov
Copy link

Is this your first time submitting a feature request?

  • I have read the expectations for open source contributors
  • I have searched the existing issues, and I could not find an existing issue for this feature
  • I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion

Describe the feature

In case of updating the macro code, I want to select and run all models, that could depend on the macro. That includes

  • models that use the specified macro directly
  • models that reference models that use the specified macro directly
  • models that use macros that depend on the specified macro through the graph of macros calls

something like
dbt ls|run --select macro:macro_name could work well for me.

Describe alternatives you've considered

Discussion about workaround https://discourse.getdbt.com/t/is-there-a-way-to-select-models-that-depend-on-specific-macro/8217/2

Who will this benefit?

Anybody, who supports a lot of models in a project where it is dangerous or expensive to run all models in case of code change and it is hard to find all dependent models from the specified macro where the code and logic were changed.

Are you interested in contributing this feature?

no

Anything else?

No response

@tema-popov tema-popov added enhancement New feature or request triage labels May 11, 2023
@github-actions github-actions bot changed the title [Feature] support "depend on macro" selector in --select [CT-2562] [Feature] support "depend on macro" selector in --select May 11, 2023
@dbeatty10
Copy link
Contributor

Thanks for opening @tema-popov -- clearly this a popular feature request across the developer team at FingerprintJS 😎

Could you share more detail about the potential use case and how it would benefit your team and others? Do you have a workaround that you are using today?

@tema-popov
Copy link
Author

tema-popov commented May 11, 2023

Could you share more detail about the potential use case

Sure! If I change a model and want to re-run all models that depend on it I have a selector for that (I believe it is dbt run --select @some_changed_model)
Macros are one of the most used features by our team as it allows us to avoid SQL code duplication.
If I change a macro that could be used in other macros and models, I don't have any clear way to select all models that depend on the macro code so I could re-run only models, that will change after the code change. As the dependencies could be quite unexpected in a large dbt project, I could forget to update models that depend on the changed code.

and how it would benefit your team and others?

  • Less manual work and potential for making mistakes during dbt project code updates and its deployment. No
  • Another case is to use it in a changelog generation for all affected models by code diff so we could find pull requests that could change some model behavior in an unexpected way.

Do you have a workaround that you are using today?`

Suppose, I changed the macro that was used in 2 other macros and several models. And all these macros and models also have models that depend on them. Right now I will just look through the code to see what models depend on changed macros, which requires manual work.

Other options I have:

  • run all models that are safe to run (some of the models require dynamic parameters from variables or iterative, so I can't really run them every time. Perhaps it is expected to run all models on every code update as a general pattern, but I try to run only potentially affected models.
    It could work if I tag all "unsafe" to run on every code update model with a special tag and exclude them and if I'm okay with time spent or re-running all models.

@dbeatty10 dbeatty10 self-assigned this May 11, 2023
@dbeatty10
Copy link
Contributor

Thanks for that background @tema-popov !

Did you try state-based selection, by any chance? See relevant caveats for state-based selection here.

If you have tried it before, will be curious how it did or didn't meet your needs.

If not, I'll provide a short example below.

Example using the "state" selector method

  1. Create these two files in your dbt project:

models/my_model.sql

select {{ guid() }} as id

macros/guid.sql

{% macro guid() %}
    {{ return("'1'") }}
{% endmacro %}
  1. Run all the models:
dbt run
  1. Save a copy of the manifest for later:
cp target/manifest.json .
  1. Only run any models that are categorized as being modified versus the last saved state (which should be none):
dbt run -s state:modified --state .
  1. Modify the macro:
    macros/guid.sql
{% macro guid() %}
    {{ return("'A'") }}
{% endmacro %}
  1. Re-run any models that are categorized as being modified versus the last saved state (which should be one):
dbt run -s state:modified --state .

@dbeatty10 dbeatty10 removed their assignment May 11, 2023
@tema-popov
Copy link
Author

Oh, great, I will definitely try the state selector, it seems to do, what I want from macro selectors. It is a bummer it was hard for me to new about it as https://docs.getdbt.com/reference/node-selection/syntax don't have any clear reference to new selectors added in 1.5

@dbeatty10
Copy link
Contributor

We'll be interested to hear how the state selector works for you!

With the belief that it will do what you want, I'm going to close this issue as "not planned". But feel free to reach out if you think we should reconsider.

Docs for state-based selection

Thank you for mentioning that this feature was hard to know about. We definitely want you to know about all the tools at your disposal! 🔧

The state-based selector was added in 0.18.0, but many people either don't know about it or haven't used it before.

If you have any suggestions to improve our documentation, we would welcome the feedback. There's two ways to do so:

  1. Propose an edit
  2. Open a docs issue

Propose an edit

image

If you come across a page that lacks clear references or information about relevant features, you can help by submitting proposed edits. To do this, simply click on the "edit this page" link located near the bottom of every documentation page. This will allow you to suggest changes or additions to the content.

Thank you for bringing this up, and please let me know if there's anything else I can assist you with!

@dbeatty10 dbeatty10 closed this as not planned Won't fix, can't repro, duplicate, stale May 12, 2023
@dbeatty10 dbeatty10 added wontfix Not a bug or out of scope for dbt-core and removed triage labels May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix Not a bug or out of scope for dbt-core
Projects
None yet
Development

No branches or pull requests

2 participants