Skip to content
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

Gets columns to update from config for BQ and Snowflake #3100

Merged
merged 30 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9086634
get columns to update from config for BQ and Snowflake
prratek Feb 13, 2021
4f8c10c
default to get_columns_in_relation if not specified in config
prratek Feb 16, 2021
81155ca
use get_columns_in_relation as default for snowflake
prratek Feb 20, 2021
2b9aa38
rename config field to incremental_update_columns
prratek Feb 20, 2021
6bd263d
add incremental_update_columns to Snowflake & BQ config schemas
prratek Feb 20, 2021
3528480
test incremental model w/ subset of cols to update
prratek Feb 20, 2021
808b980
move "update cols" incremental test to snowflake models
prratek Feb 20, 2021
bf64db4
fix typo
prratek Mar 3, 2021
4da6564
use merge_update_columns when getting merge sql
prratek Mar 3, 2021
fb449ca
rename new config var to merge_update_columns
prratek Mar 3, 2021
a07532d
revert changes to incremental materializations
prratek Mar 3, 2021
af3a818
loop over column_name instead of column.name
prratek Mar 3, 2021
25b143c
WIP test case and empty seeds
prratek Mar 6, 2021
a5bc19d
paste in some data for seeds
prratek Mar 6, 2021
1345d95
modify some records and the expected result
prratek Mar 6, 2021
de4d7d6
Revert "modify some records and the expected result"
prratek Mar 6, 2021
540a042
modify seeds to contain load date and some modified records
prratek Mar 7, 2021
4d4d176
refactor seeds directory structure and names
prratek Mar 7, 2021
8255c91
change test logic for new seed directories
prratek Mar 7, 2021
4e6adc0
switch to correct data dir for second run
prratek Mar 13, 2021
2853f07
use correct config var name
prratek Mar 13, 2021
2feeb5b
Merge remote-tracking branch 'origin/specify-cols-to-update' into spe…
prratek Mar 13, 2021
4d18e39
correct the load date for updated entries in "update seed"
prratek Mar 13, 2021
909068d
leave quoting for merge_update_columns to the user
prratek Mar 16, 2021
96bfb3b
Update core/dbt/include/global_project/macros/materializations/common…
prratek Mar 16, 2021
b0e50de
update changelog
prratek Mar 16, 2021
bae9767
add my name to contributors
prratek Mar 16, 2021
6bdd01d
Merge branch 'develop' into specify-cols-to-update
prratek Mar 16, 2021
8ebbc10
Merge branch 'develop' into specify-cols-to-update
prratek Mar 18, 2021
48e367c
Merge branch 'develop' into specify-cols-to-update
jtcohen6 Mar 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/bigquery/dbt/adapters/bigquery/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class BigqueryConfig(AdapterConfig):
hours_to_expiration: Optional[int] = None
require_partition_filter: Optional[bool] = None
partition_expiration_days: Optional[int] = None
incrmental_update_columns: Optional[str] = None
prratek marked this conversation as resolved.
Show resolved Hide resolved


class BigQueryAdapter(BaseAdapter):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@
{% endif %}
{% set build_sql = create_table_as(False, target_relation, sql) %}
{% else %}
{% set dest_columns = adapter.get_columns_in_relation(existing_relation) %}
{% set dest_columns = config.get('incremental_update_columns', none) %}
{% if dest_columns is none %}
{% set dest_columns = adapter.get_columns_in_relation(existing_relation) %}
{% endif %}

{#-- if partitioned, use BQ scripting to get the range of partition values to be updated --#}
{% if strategy == 'insert_overwrite' %}
Expand Down
1 change: 1 addition & 0 deletions plugins/snowflake/dbt/adapters/snowflake/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class SnowflakeConfig(AdapterConfig):
copy_grants: Optional[bool] = None
snowflake_warehouse: Optional[str] = None
query_tag: Optional[str] = None
incremental_update_columns: Optional[str] = None


class SnowflakeAdapter(SQLAdapter):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@
{% do adapter.expand_target_column_types(
from_relation=tmp_relation,
to_relation=target_relation) %}
{% set dest_columns = adapter.get_columns_in_relation(target_relation) %}
{% set dest_columns = config.get('update_columns', none) %}
{% if dest_columns is none %}
{% set dest_columns = adapter.get_columns_in_relation(existing_relation) %}
{% endif %}
{% set build_sql = dbt_snowflake_get_incremental_sql(strategy, tmp_relation, target_relation, unique_key, dest_columns) %}
{% endif %}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{
config(
materialized = "incremental",
unique_key = "id",
incremental_update_columns = ["email", "ip_address"]
)
}}


select *
from {{ ref('seed') }}

{% if is_incremental() %}

where id > (select max(id) from {{this}})

{% endif %}