Open sudo-pradip opened 1 year ago
Thanks for opening this @sudo-pradip !
This is essentially one of the "outstanding questions" listed here:
- How can users or an organization share their custom incremental strategies or overrides? Can they share in a dbt package on the dbt Package Hub for example?
Let's suppose you add a custom macro named get_incremental_merge_null_safe_sql
to a dbt package named dbt_materializations
. Suppose further than you install that package within a project named my_project
.
Did you already try overriding global macros within dbt_project.yml
like this?
dispatch:
- macro_namespace: dbt
search_order: ['my_project', 'dbt_materializations', 'dbt']
I haven't tried this myself, so curious if you already tried it.
Hello @dbeatty10 , Thank you for your prompt response
dispatch
, feature for specifying search order is only made for adapter.dispatch
method ??adapater.dispatch
method, in doc i found example about dbt_utils.surrogate_key
and concat
method
{% macro default__concat(...) %}
, it worked finedispatch
config ? i double check and by just passing ['my_project'] only for dbt_utils macro_namespace, then it fails dbt job which prove that i used in correct way
- for calling a specific incremental strategy macro, get_incremental_strategy_macro uses model_context, which may not respect the order define under
dispatch
, feature for specifying search order is only made foradapter.dispatch
method ??
You're probably onto something here!
If that area of the code doesn't respect dispatch
, then the alternative you mentioned might be our only option currently:
{% macro get_incremental_merge_null_safe_sql(arg_dict) %}
{{ dbt_materializations.get_incremental_merge_null_safe_sql(arg_dict) }}
{% endmacro %}
Do you have any ideas / opinions about re-implementation of get_incremental_strategy_macro
in a different way?
In general, you'd need a separate dispatch
configs per package. So for dbt_utils
and dbt_expectations
you'd need two different dispatch
specifications:
dispatch:
- macro_namespace: dbt_utils
search_order: ['my_project', 'dbt_utils', 'dbt']
- macro_namespace: dbt_expectations
search_order: ['my_project', 'dbt_expectations', 'dbt']
Wanna give that dispatch config a try with dbt_utils
and see if it works for you?
Current
get_incremental_strategy_macro
method will look at top level (root project level) and if macro found then return else raise error.Expectation
dbt
at project level present under the dispatch configdbt
then behave as current flowget_incremental_strategy_macro
and adapter.dispatch
, since adapter.dispatch
also respect the search order, so must be consists behaviour across methodsMy assumptions
model_context
which used in get_incremental_strategy_macro
is same context
variable available in end users Jinja, so model and macro can use context
as i previously tried to tweak that context
variable to add my dbt package macro at top levelcontext
has keys for dbt packages, in my case dbt_materlization
where i can see all my macros, so dbt package macros are available at get_incremental_strategy_macro
adapter.dispatch
at get_incremental_strategy_macro
, sound so simple right, i didn't found any method which uses that, turn out adapter.dispatch
is only available at Jinja level, but i tried to find out dispatch method code it was atPossible solutions
adapter.dispatch
where first find out search_package (respect the dispatch config), a for loop, model_contex[package_name] is not None else attempts.append, endadapter.dispatch
at get_incremental_strategy_macro
, but even if we can we have to handle prefix(default, snowflake) which we may don't want to change, since many adapter (snowflake) already override get_incremental_strategy_macro
macroexecute_macro
Solution 1 we can think, but we have to duplicate our logic at two places (i think it's all right ?), whats your input on this ?
Thanks for doing this research @sudo-pradip 🧠
I'll either need to grab an extra set of expert eyes from an engineer on the dbt-core team do some deeper research myself. Labeling this as "Refinement" accordingly.
All of us are time-constrained this week and next due to the upcoming release of dbt-core of 1.7.0 and the Coalesce conference next week, so it could be a few weeks (or more) until we can dive deeper into this.
In the meantime, your best bet is the alternative you've already considered:
- Alternatively we can create a intermediate macro at project to call custom incremental strategy macro
{% macro get_incremental_merge_null_safe_sql(arg_dict) %} {{ dbt_materializations.get_incremental_merge_null_safe_sql(arg_dict) }} {% endmacro %}
any updates ?
@sudo-pradip we're not able to prioritize further research at this time.
So we've opened https://github.com/dbt-labs/docs.getdbt.com/pull/4716 to document the installation steps that work currently.
Is this your first time submitting a feature request?
Describe the feature
get_incremental_<name>_sql
, which will be invoke run time usingmodel_context
variable andget_incremental_strategy_macro
Describe alternatives you've considered
Who will this benefit?
Are you interested in contributing this feature?
Yes
Anything else?
context
variable, but didn't work