-
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
Persist predicates to get_merge_sql and wrap in parentheses #5679
Conversation
core/dbt/include/global_project/macros/materializations/models/incremental/merge.sql
Outdated
Show resolved
Hide resolved
{#-- Wrap predicates in parentheses to ensure correct evaluation when later anded --#} | ||
{% do predicates.append('(' ~ predicate ~ ')') %} |
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.
Oh! I see what you mean, since predicates could have their own nested conditional logic (and/or):
(predicate_a) and (predicate_b) and (predicate_c)
Would it make more sense to do that wrapping here, or within the templating logic in get_merge_sql
?
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.
I concluded here was best, as it avoids the need to replicate this logic into every get_x_sql
which might use the predicates. I'll defer to you though!
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.
Thanks @NiallRees! I'd be very excited to (finally) have this functionality. I've got a bit of bookkeeping to do, to clean up the issues tracking this work.
The right place for tests is probably in the "incremental" subsection of the "adapter zone" functional tests: https://github.com/dbt-labs/dbt-core/tree/main/tests/adapter/dbt/tests/adapter/incremental. We'd want the ability to pull these tests in and run them on adapter plugins, too.
One thought: We could take this one step further, and make it available to the other incremental strategies as well, by pulling in predicates
to each of those macros, too. @dave-connors-3 had done work in that vein back in #4546. If you want to keep this limited in scope, to just default__get_merge_sql
and the adapters which use it, that's fine too — we should open a follow-on ticket to track complete availability across adapters + strategies.
I think I'll keep this limited in scope if that's cool, just to increase my chances of getting it across the finish line relatively quickly! |
Closing this PR, in favor of #5702 (merged for inclusion in v1.4!) |
Resolves #5680 and dbt-labs/dbt-snowflake#231
This enables the already available
incremental_predicates
to be persisted toget_merge_sql()
. It also wraps all predicates in parentheses to force the correct evaluation order when they're anded.I can now add this config to an incremental model:
Resulting in:
improving pruning performance.
I've changed the default value of predicates to be an empty list from none, that may have been done for a reason I'm unaware of though! Also not sure if/where to add tests so appreciate any pointers.
Description
Checklist
changie new
to create a changelog entry