-
Notifications
You must be signed in to change notification settings - Fork 234
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
Make internal macros use macro dispatch to be overridable in child adapters #320
Conversation
@jtcohen6 Do you think this will be backported to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One requested change, then this is good to go. Thanks for the quick work!
@jtcohen6 Do you think this will be backported to 1.0.latest? If not, we might need to apply the original approach to the 1.0.latest branch in dbt-databricks. Thanks.
@leahwicz What do you think? I'd be willing to backport this to 1.0.latest
, given that:
- it's a total non-change for
dbt-spark
end users (overridinglocation_clause()
by name will still work just as before) - it will enable
dbt-databricks
to patch this behavior for folks migrating fromdbt-spark
v1.0.latest todbt-databricks
v1.0.latest
@@ -1,19 +1,33 @@ | |||
{% macro file_format_clause() %} | |||
{{ return(adapter.dispatch('file_format_clause')()) }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this and the other macros below, could you provide the second argument to dispatch
(macro_namespace
) as 'dbt'
?
{{ return(adapter.dispatch('file_format_clause')()) }} | |
{{ return(adapter.dispatch('file_format_clause', 'dbt')()) }} |
This enables users to install packages with overrides for "global" (core/plugin) macros, and choose to prefer the package's version over the global version by specifying a project config like:
# dbt_project.yml
dispatch:
- macro_namespace: dbt
search_order: ['my_project', 'package_with_custom_overrides', 'dbt']
Docs: https://docs.getdbt.com/reference/dbt-jinja-functions/dispatch#overriding-global-macros
(Meta comment: The syntax here has developed organically over time, so it can be a bit clunky. Some thoughts about how we could make it more ergonomic in the future: dbt-labs/dbt-core#4646)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, thanks for letting me know! Updated.
tests/unit/test_macros.py
Outdated
def dispatch(macro_name): | ||
return getattr(template.module, f'spark__{macro_name}') | ||
self.default_context['adapter'].dispatch = dispatch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@leahwicz Thanks for taking care of this issue.
As I've addressed @jtcohen6's comment, this must be good to go unless there are any other comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @ueshin!
One integration test failed for a reason that appears unrelated to the changes here. Rerunning now. If it fails again I'll try taking a deeper look.
The same test failed again, only when running against a Databricks cluster, only via ODBC connection: Trying to dig in to figure out why. |
I haven't been able to reproduce locally, or by running the exact same SQL against a cluster in our Databricks workspace. Looks like this one has failed flakily for us before. Here's a run from 10 days ago, against It also sounds like other users have also seen the same error message crop up intermittently: #293
We could enable query retries ( I'm trying one last rerun, but just about willing to say this is a flaky failure, and unrelated to any substantive changes in this PR. |
…apters (#320) * Make internal macros use macro dispatch to be overridable in child adapters. * changelog * Address a comment. * Fix. * Fix.
@jtcohen6 Thanks for merging and backporting this! |
resolves #319
Description
Makes internal macros use macro dispatch to be overridable in child adapters.
The target macros are:
file_format_clause
location_clause
options_clause
comment_clause
partition_cols
clustered_cols
create_temporary_view
Checklist
CHANGELOG.md
and added information about my change to the "dbt-spark next" section.