-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add a mechanism for "wrapping" SQL across materializations #1096
Comments
closing due to lack of interest |
Bummed to see this one closed! A use case I found for it is having a collection of models to run, which you sometimes want to apply a filter to, but it would be tedious to modify all of them (i.e. |
@kconvey I believe versions of this functionality are possible today through other more generic dbt constructs. The approach that comes to my mind leverages custom For instance, if in one of your models you have: with source_data as (
select * from {{ source('fivetran_stripe', 'payments') }}
) Normally this would compile to something like: with source_data as (
select * from fivetran_stripe.payments
) But you could override the {% macro source(source_name, source_table) %}
{% set src_rel = builtins.source(source_name, source_table) %}
{% set filtered_src %}
(
select * from {{ src_rel }} where _fivetran_deleted is not null
) {{ src_rel.identifier }}
{% endset %}
{% set final_src = filtered_src if var('filter_out_deleted', False) %}
{% do return(final_src) %}
{% endmacro %} Given those conditions:
The compiled SQL changes: with source_data as (
select * from (
select * from fivetran_stripe.payments where _fivetran_deleted is not null
) payments
) |
Feature
Feature description
dbt should make it possible/easy to wrap the model sql that gets executed in a materialization.
Use cases:
where _fivetran_deleted is not null
to all base modelslimit 0
for only CI runsSome questions:
Implementation
In order for this to be really useful, users should be able to apply a wrapper macro to whole groups of models all at once. As such, I think a reasonable implementation is to specify a
wrap_sql
config indbt_project.yml
. Thiswrap_sql
parameter can either be a string, or a list of strings, indicating the name of the macro(s) to call. Eg:Example macros:
Option 1: Supply the model as an argument
Option 2: Just supply
sql
as an argumentI'm not certain where the best place to call these macros is, nor do I have super strong opinions on the exact interface for these macros. Whatever we choose, we should be really explicit about what the context is :)
The text was updated successfully, but these errors were encountered: