-
Notifications
You must be signed in to change notification settings - Fork 349
feat(athena): add build_strategy config for incremental and table materializations #1830
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
base: main
Are you sure you want to change the base?
Changes from 6 commits
5bd01f8
5e0f4ec
c31f06c
f95a3ae
c2217e9
7e23811
bd9f34f
221b1cd
eba662d
244fa2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| kind: Features | ||
| body: build_with_subquery config option to skip tmp table staging for incremental merge and append strategies | ||
| time: 2026-04-06T22:54:58.739286+09:00 | ||
| custom: | ||
| Author: dtaniwaki | ||
| Issue: "1829" |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |||||||||||||||||||||||||||||
| {% set lf_grants = config.get('lf_grants') %} | ||||||||||||||||||||||||||||||
| {% set partitioned_by = config.get('partitioned_by') %} | ||||||||||||||||||||||||||||||
| {% set force_batch = config.get('force_batch', False) | as_bool -%} | ||||||||||||||||||||||||||||||
| {% set build_with_subquery = config.get('build_with_subquery', False) | as_bool -%} | ||||||||||||||||||||||||||||||
| {% set unique_tmp_table_suffix = config.get('unique_tmp_table_suffix', False) | as_bool -%} | ||||||||||||||||||||||||||||||
| {% set temp_schema = config.get('temp_schema') %} | ||||||||||||||||||||||||||||||
| {% set target_relation = this.incorporate(type='table') %} | ||||||||||||||||||||||||||||||
|
|
@@ -46,6 +47,18 @@ | |||||||||||||||||||||||||||||
| {% endif %} | ||||||||||||||||||||||||||||||
| {% endif %} | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| {% if build_with_subquery %} | ||||||||||||||||||||||||||||||
| {% if model_language == 'python' %} | ||||||||||||||||||||||||||||||
| {% do exceptions.raise_compiler_error('build_with_subquery is not supported with Python models.') %} | ||||||||||||||||||||||||||||||
| {% endif %} | ||||||||||||||||||||||||||||||
| {% if force_batch %} | ||||||||||||||||||||||||||||||
| {% do exceptions.raise_compiler_error('build_with_subquery is incompatible with force_batch. Batching requires data in the tmp table.') %} | ||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: I would say "Batching requires a temp table" |
||||||||||||||||||||||||||||||
| {% endif %} | ||||||||||||||||||||||||||||||
| {% if strategy == 'insert_overwrite' %} | ||||||||||||||||||||||||||||||
| {% do exceptions.raise_compiler_error('build_with_subquery is not supported with insert_overwrite strategy.') %} | ||||||||||||||||||||||||||||||
| {% endif %} | ||||||||||||||||||||||||||||||
|
Comment on lines
+57
to
+59
|
||||||||||||||||||||||||||||||
| {% if force_batch %} | |
| {% do exceptions.raise_compiler_error('build_with_subquery is incompatible with force_batch. Batching requires data in the tmp table.') %} | |
| {% endif %} | |
| {% if strategy == 'insert_overwrite' %} | |
| {% do exceptions.raise_compiler_error('build_with_subquery is not supported with insert_overwrite strategy.') %} | |
| {% endif %} | |
| {% if existing_relation is not none and not should_full_refresh() %} | |
| {% if force_batch %} | |
| {% do exceptions.raise_compiler_error('build_with_subquery is incompatible with force_batch. Batching requires data in the tmp table.') %} | |
| {% endif %} | |
| {% if strategy == 'insert_overwrite' %} | |
| {% do exceptions.raise_compiler_error('build_with_subquery is not supported with insert_overwrite strategy.') %} | |
| {% endif %} | |
| {% endif %} |
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 think there're pros and cons in ignoring the error in the full-refresh phase. The error will be eventually raised in the incremental phase, so we should catch it earlier.
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.
If you aren't familiar with dbt-athena since before this change, you may be confused by the naming of this property. The name is a response to the current default, but the current default is actually not the default behavior that you would expect.
It's natural to add a feature with a config that enables it, but I'm thinking that in this case we are adding something that probably should have been the default mode, and it's only for historical reasons it ended up being added later. At least to me, using a temp table is the alternative way of doing this.
One way to convey this is to use a config that is not true or false, but enables one of two (or more) modes, like
incremental_strategywith values "subquery" or "tmp_table" (default).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.
That sounds reasonable.
incremental_strategyis the same as dbt-core's config likeincremental_strategy: insert_overwrite. How aboutbuild_strategy?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.
What do you think about applying this mode to table materialization? This behavior benefits all the materialization types rather than the incremental materialization.
I made another PR over this PR in dtaniwaki#12.
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.
build_strategysounds good to me, that works for table materialization too.