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

Fix manifest search (#2032) #2035

Merged
merged 1 commit into from
Jan 31, 2020
Merged

Conversation

beckjake
Copy link
Contributor

@beckjake beckjake commented Jan 8, 2020

Fixes #2032

I went a bit further and also included the node search since it was very easy and I had a nice test suite for it...

Unify the lookup for the various macros, all of them are done in the manifest now:

  • dbt's built-in package + all plugins are part of 'core'
  • finding macros has the concept of an optional package name
  • materializations are a special case of finding macros
  • the generate_*_name macros are another special case (non-core dependency packages are ignored)
  • generating the macro execution context now uses the concept of an optional search_package_name
  • macro execution now binds these two together

Unify the lookup for models/docs/sources:

  • added a search_name property to those three types
  • create a 'Searchable' protocol, have the node search code accept that
  • simplify matching logic/push it into the correct types accordingly

Renamed get_materialization_macro to find_materialization_macro_by_name (consistency)

context namespacing behavior:

  • dbt run-operation now passes the named package along to macro execution if a package name is specified
  • so dbt run-operation dependency.ad runs with the dependency namespace as local, overriding globals
  • but dbt run-operation my_macro runs in the current package namespace as local, even if it ultimately runs the dependency's my_macro()
  • the current package namespace is always treated as "global", overriding core macros

Added type annotations for all the manifest stuff

Tons of tests

@beckjake
Copy link
Contributor Author

rebased + fixed merge conflicts

Unify the lookup for the various macros, all of them are done in the manifest now:
 - dbt's built-in package + all plugins are part of 'core'
 - finding macros has the concept of an optional package name
 - materializations are a special case of finding macros
 - the `generate_*_name` macros are another special case (non-core dependency packages are ignored)
 - generating the macro execution context now uses the concept of an optional search_package_name
 - macro execution now binds these two together

Unify the lookup for models/docs/sources
 - added a search_name property to those three types
 - create a 'Searchable' protocol, have the node search code accept that
 - simplify matching logic/push it into the correct types accordingly

Rename get_materialization_macro to find_materialization_macro_by_name (consistency)

context namespacing behavior:
 - dbt run-operation now passes the named package along to macro execution if a package name is specified
 - so `dbt run-operation dependency.ad` runs with the dependency namespace as local, overriding globals
 - but `dbt run-operation my_macro` runs in the current package namespace as local, even if it ultimately runs the dependency's my_macro()
 - the current package namespace is always treated as "global", overriding core macros

Tons of tests
Copy link
Contributor

@drewbanin drewbanin left a comment

Choose a reason for hiding this comment

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

This looks excellent! Thanks for the thorough writeup of changes in the description - that was really helpful.

Let's ship it 🚢

- if neither of those exist (unit tests?), return None
"""
def filter(candidate: MacroCandidate) -> bool:
return candidate.locality != Locality.Imported
Copy link
Contributor

Choose a reason for hiding this comment

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

this is super elegant

@beckjake beckjake merged commit b01226f into dev/barbara-gittings Jan 31, 2020
@beckjake beckjake deleted the fix/manifest-search branch January 31, 2020 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants