dbt-labs / dbt-labs/dbt

[CT-2790] Support dispatch for materialization macros

Open
#8,031 2 comments 2 reactions 1 assignee Claimed by @aranke View on GitHub
engine:v1 type:tech-debt
Dominant language
Rust
Stars
13.8k
Forks
2.6k
Avg merge
21h 31m
Merged PRs (30d)
56

Description

Definition of done:
- It's possible to call `adapter.dispatch` for materialization macros, and return the appropriate macro for this adapter, which can then be called/executed from within another macro/materialization

---

In conversation with Kshitij just now, it seems that the main changes need to be in core/dbt/context/macros.py, in MacroNamespace.get_from_package where we can add special processing of "materialization" macros. The "get_from_package" method is called from adapter.dispatch, which comes from the adapter "contextproperty" of the ProviderContext in core/dbt/context/providers.py. The actual "dispatch" method is in the BaseDatabaseWrapper.

The materialization macro can be found in the "execute" method of the clone task (and probably the same method in runnable.py) by doing context.adapter.dispatch from the constructed context. This should already be a MacroGenerator callable, so we wouldn't need to construct a MacroGenerator as we do further down in "execute".

_Originally posted by @gshank in https://github.com/dbt-labs/dbt-core/issues/7799#issuecomment-1614996026_

---

### Motivation

This would enable us to refactor the implementation in the `clone` materialization here:

https://github.com/dbt-labs/dbt-core/blob/a58b5ee8fb9fafd8bbf9da52d3b9e8603725592c/core/dbt/include/global_project/macros/materializations/models/clone/clone.sql#L49-L58

It might also unblock an approach for this desirable UX improvement to model versions:
- #7442

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.