File tree Expand file tree Collapse file tree
dbt/include/sqlserver/macros/materializations/snapshots
tests/functional/adapter/dbt Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5252
5353 {% else %}
5454
55- {% set columns = config .get (" snapshot_meta_column_names" ) or get_snapshot_table_column_names() %}
55+ {% set columns = get_snapshot_table_column_names() %}
56+ {% set meta = config .get (" snapshot_meta_column_names" ) %}
57+ {% if meta %}
58+ {% if meta .dbt_valid_from %}{% do columns .update ({" dbt_valid_from" : meta .dbt_valid_from }) %}{% endif %}
59+ {% if meta .dbt_valid_to %}{% do columns .update ({" dbt_valid_to" : meta .dbt_valid_to }) %}{% endif %}
60+ {% if meta .dbt_scd_id %}{% do columns .update ({" dbt_scd_id" : meta .dbt_scd_id }) %}{% endif %}
61+ {% if meta .dbt_updated_at %}{% do columns .update ({" dbt_updated_at" : meta .dbt_updated_at }) %}{% endif %}
62+ {% if meta .dbt_is_deleted %}{% do columns .update ({" dbt_is_deleted" : meta .dbt_is_deleted }) %}{% endif %}
63+ {% endif %}
5664 {{ adapter .valid_snapshot_target (target_relation, columns) }}
5765 {% set build_or_select_sql = snapshot_staging_table(strategy, temp_snapshot_relation, target_relation) %}
5866 {% set staging_table = build_snapshot_staging_table(strategy, temp_snapshot_relation, target_relation) %}
Original file line number Diff line number Diff line change @@ -779,3 +779,41 @@ def test_multi_column_unique_key(self, project):
779779
780780class TestBaseSnapshotMultiUniqueKey (BaseSnapshotMultiUniqueKey ):
781781 pass
782+
783+
784+ snapshot_partial_column_names_yml = """
785+ snapshots:
786+ - name: snapshot_actual
787+ config:
788+ strategy: timestamp
789+ updated_at: updated_at
790+ snapshot_meta_column_names:
791+ dbt_valid_to: EffectiveEndDate
792+ dbt_valid_from: EffectiveStartDate
793+ """
794+
795+
796+ class TestSnapshotPartialColumnNames :
797+ """Regression test for #639: partial snapshot_meta_column_names fails on second run."""
798+
799+ @pytest .fixture (scope = "class" )
800+ def snapshots (self ):
801+ return {"snapshot.sql" : snapshot_actual_sql }
802+
803+ @pytest .fixture (scope = "class" )
804+ def models (self ):
805+ return {
806+ "snapshots.yml" : snapshot_partial_column_names_yml ,
807+ "ref_snapshot.sql" : ref_snapshot_sql ,
808+ }
809+
810+ def test_partial_column_names_second_run (self , project ):
811+ project .run_sql (create_seed_sql )
812+ project .run_sql (seed_insert_sql )
813+
814+ results = run_dbt (["snapshot" ])
815+ assert len (results ) == 1
816+
817+ # Second run should succeed — this is where #639 failed
818+ results = run_dbt (["snapshot" ])
819+ assert len (results ) == 1
You can’t perform that action at this time.
0 commit comments