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

[Wilt Chamberlain] fix for dupe check_cols values in snapshot strategy #1590

Merged
Merged
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion core/dbt/contracts/graph/parsed.py
Original file line number Diff line number Diff line change
@@ -500,7 +500,7 @@ def config(self, value):
]
},
'required': [
'target_database', 'target_schema', 'unique_key', 'strategy',
'target_schema', 'unique_key', 'strategy',
],
}

Original file line number Diff line number Diff line change
@@ -106,7 +106,8 @@
)
{%- endset %}

{% set scd_id_expr = snapshot_hash_arguments(check_cols) %}
{% set scd_id_cols = [primary_key] + (check_cols | list) %}
{% set scd_id_expr = snapshot_hash_arguments(scd_id_cols) %}

{% do return({
"unique_key": primary_key,
9 changes: 9 additions & 0 deletions core/dbt/parser/snapshots.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,15 @@


def set_snapshot_attributes(node):
# Default the target database to the database specified in the target
# This line allows target_database to be optional in the snapshot config
if 'target_database' not in node.config:
node.config['target_database'] = node.database

# Set the standard node configs (database+schema) to be the specified
# values from target_database and target_schema. This ensures that the
# database and schema names are interopolated correctly when snapshots
# are ref'd from other models
config_keys = {
'target_database': 'database',
'target_schema': 'schema'
6 changes: 4 additions & 2 deletions test/integration/004_simple_snapshot_test/seed_pg.sql
Original file line number Diff line number Diff line change
@@ -26,9 +26,11 @@ create table {database}.{schema}.snapshot_expected (


-- seed inserts
-- use the same email for two users to verify that duplicated check_cols values
-- are handled appropriately
insert into {database}.{schema}.seed (id, first_name, last_name, email, gender, ip_address, updated_at) values
(1, 'Judith', 'Kennedy', 'jkennedy0@phpbb.com', 'Female', '54.60.24.128', '2015-12-24 12:19:28'),
(2, 'Arthur', 'Kelly', 'akelly1@eepurl.com', 'Male', '62.56.24.215', '2015-10-28 16:22:15'),
(1, 'Judith', 'Kennedy', '(not provided)', 'Female', '54.60.24.128', '2015-12-24 12:19:28'),
(2, 'Arthur', 'Kelly', '(not provided)', 'Male', '62.56.24.215', '2015-10-28 16:22:15'),
(3, 'Rachel', 'Moreno', 'rmoreno2@msu.edu', 'Female', '31.222.249.23', '2016-04-05 02:05:30'),
(4, 'Ralph', 'Turner', 'rturner3@hp.com', 'Male', '157.83.76.114', '2016-08-08 00:06:51'),
(5, 'Laura', 'Gonzales', 'lgonzales4@howstuffworks.com', 'Female', '30.54.105.168', '2016-09-01 08:25:38'),
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{% snapshot no_target_database %}
{{
config(
target_schema=schema,
unique_key='id || ' ~ "'-'" ~ ' || first_name',
strategy='timestamp',
updated_at='updated_at',
Original file line number Diff line number Diff line change
@@ -353,7 +353,7 @@ def test__postgres__invalid(self):
with self.assertRaises(dbt.exceptions.CompilationException) as exc:
self.run_dbt(['compile'], expect_pass=False)

self.assertIn('target_database', str(exc.exception))
self.assertIn('target_schema', str(exc.exception))


class TestCheckCols(TestSimpleSnapshotFiles):