dbt-adapters 1.6.1__py3-none-any.whl → 1.7.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of dbt-adapters might be problematic. Click here for more details.

dbt/adapters/__about__.py CHANGED
@@ -1 +1 @@
1
- version = "1.6.1"
1
+ version = "1.7.0"
dbt/adapters/base/impl.py CHANGED
@@ -83,7 +83,6 @@ from dbt.adapters.exceptions import (
83
83
  QuoteConfigTypeError,
84
84
  RelationReturnedMultipleResultsError,
85
85
  RenameToNoneAttemptedError,
86
- SnapshotTargetIncompleteError,
87
86
  SnapshotTargetNotSnapshotTableError,
88
87
  UnexpectedNonTimestampError,
89
88
  )
@@ -764,7 +763,9 @@ class BaseAdapter(metaclass=AdapterMeta):
764
763
  return [col for (col_name, col) in from_columns.items() if col_name in missing_columns]
765
764
 
766
765
  @available.parse_none
767
- def valid_snapshot_target(self, relation: BaseRelation) -> None:
766
+ def valid_snapshot_target(
767
+ self, relation: BaseRelation, column_names: Optional[Dict[str, str]] = None
768
+ ) -> None:
768
769
  """Ensure that the target relation is valid, by making sure it has the
769
770
  expected columns.
770
771
 
@@ -782,21 +783,16 @@ class BaseAdapter(metaclass=AdapterMeta):
782
783
 
783
784
  columns = self.get_columns_in_relation(relation)
784
785
  names = set(c.name.lower() for c in columns)
785
- expanded_keys = ("scd_id", "valid_from", "valid_to")
786
- extra = []
787
786
  missing = []
788
- for legacy in expanded_keys:
789
- desired = "dbt_" + legacy
787
+ # Note: we're not checking dbt_updated_at here because it's not
788
+ # always present.
789
+ for column in ("dbt_scd_id", "dbt_valid_from", "dbt_valid_to"):
790
+ desired = column_names[column] if column_names else column
790
791
  if desired not in names:
791
792
  missing.append(desired)
792
- if legacy in names:
793
- extra.append(legacy)
794
793
 
795
794
  if missing:
796
- if extra:
797
- raise SnapshotTargetIncompleteError(extra, missing)
798
- else:
799
- raise SnapshotTargetNotSnapshotTableError(missing)
795
+ raise SnapshotTargetNotSnapshotTableError(missing)
800
796
 
801
797
  @available.parse_none
802
798
  def expand_target_column_types(
@@ -150,8 +150,10 @@ class SnapshotTargetNotSnapshotTableError(CompilationError):
150
150
  super().__init__(msg=self.get_message())
151
151
 
152
152
  def get_message(self) -> str:
153
- msg = 'Snapshot target is not a snapshot table (missing "{}")'.format(
154
- '", "'.join(self.missing)
153
+ missing = '", "'.join(self.missing)
154
+ msg = (
155
+ f'Snapshot target is missing configured columns (missing "{missing}"). '
156
+ "See https://docs.getdbt.com/docs/build/snapshots#snapshot-meta-fields for more information."
155
157
  )
156
158
  return msg
157
159
 
@@ -34,7 +34,12 @@
34
34
  {{ adapter.dispatch('snapshot_staging_table', 'dbt')(strategy, source_sql, target_relation) }}
35
35
  {% endmacro %}
36
36
 
37
+ {% macro get_snapshot_table_column_names() %}
38
+ {{ return({'dbt_valid_to': 'dbt_valid_to', 'dbt_valid_from': 'dbt_valid_from', 'dbt_scd_id': 'dbt_scd_id', 'dbt_updated_at': 'dbt_updated_at'}) }}
39
+ {% endmacro %}
40
+
37
41
  {% macro default__snapshot_staging_table(strategy, source_sql, target_relation) -%}
42
+ {% set columns = config.get('snapshot_table_column_names') or get_snapshot_table_column_names() %}
38
43
 
39
44
  with snapshot_query as (
40
45
 
@@ -48,7 +53,7 @@
48
53
  {{ strategy.unique_key }} as dbt_unique_key
49
54
 
50
55
  from {{ target_relation }}
51
- where dbt_valid_to is null
56
+ where {{ columns.dbt_valid_to }} is null
52
57
 
53
58
  ),
54
59
 
@@ -57,10 +62,10 @@
57
62
  select
58
63
  *,
59
64
  {{ strategy.unique_key }} as dbt_unique_key,
60
- {{ strategy.updated_at }} as dbt_updated_at,
61
- {{ strategy.updated_at }} as dbt_valid_from,
62
- nullif({{ strategy.updated_at }}, {{ strategy.updated_at }}) as dbt_valid_to,
63
- {{ strategy.scd_id }} as dbt_scd_id
65
+ {{ strategy.updated_at }} as {{ columns.dbt_updated_at }},
66
+ {{ strategy.updated_at }} as {{ columns.dbt_valid_from }},
67
+ nullif({{ strategy.updated_at }}, {{ strategy.updated_at }}) as {{ columns.dbt_valid_to }},
68
+ {{ strategy.scd_id }} as {{ columns.dbt_scd_id }}
64
69
 
65
70
  from snapshot_query
66
71
  ),
@@ -70,9 +75,9 @@
70
75
  select
71
76
  *,
72
77
  {{ strategy.unique_key }} as dbt_unique_key,
73
- {{ strategy.updated_at }} as dbt_updated_at,
74
- {{ strategy.updated_at }} as dbt_valid_from,
75
- {{ strategy.updated_at }} as dbt_valid_to
78
+ {{ strategy.updated_at }} as {{ columns.dbt_updated_at }},
79
+ {{ strategy.updated_at }} as {{ columns.dbt_valid_from }},
80
+ {{ strategy.updated_at }} as {{ columns.dbt_valid_to }}
76
81
 
77
82
  from snapshot_query
78
83
  ),
@@ -111,7 +116,7 @@
111
116
  select
112
117
  'update' as dbt_change_type,
113
118
  source_data.*,
114
- snapshotted_data.dbt_scd_id
119
+ snapshotted_data.{{ columns.dbt_scd_id }}
115
120
 
116
121
  from updates_source_data as source_data
117
122
  join snapshotted_data on snapshotted_data.dbt_unique_key = source_data.dbt_unique_key
@@ -128,10 +133,10 @@
128
133
  select
129
134
  'delete' as dbt_change_type,
130
135
  source_data.*,
131
- {{ snapshot_get_time() }} as dbt_valid_from,
132
- {{ snapshot_get_time() }} as dbt_updated_at,
133
- {{ snapshot_get_time() }} as dbt_valid_to,
134
- snapshotted_data.dbt_scd_id
136
+ {{ snapshot_get_time() }} as {{ columns.dbt_valid_from }},
137
+ {{ snapshot_get_time() }} as {{ columns.dbt_updated_at }},
138
+ {{ snapshot_get_time() }} as {{ columns.dbt_valid_to }},
139
+ snapshotted_data.{{ columns.dbt_scd_id }}
135
140
 
136
141
  from snapshotted_data
137
142
  left join deletes_source_data as source_data on snapshotted_data.dbt_unique_key = source_data.dbt_unique_key
@@ -155,12 +160,13 @@
155
160
  {% endmacro %}
156
161
 
157
162
  {% macro default__build_snapshot_table(strategy, sql) %}
163
+ {% set columns = config.get('snapshot_table_column_names') or get_snapshot_table_column_names() %}
158
164
 
159
165
  select *,
160
- {{ strategy.scd_id }} as dbt_scd_id,
161
- {{ strategy.updated_at }} as dbt_updated_at,
162
- {{ strategy.updated_at }} as dbt_valid_from,
163
- nullif({{ strategy.updated_at }}, {{ strategy.updated_at }}) as dbt_valid_to
166
+ {{ strategy.scd_id }} as {{ columns.dbt_scd_id }},
167
+ {{ strategy.updated_at }} as {{ columns.dbt_updated_at }},
168
+ {{ strategy.updated_at }} as {{ columns.dbt_valid_from }},
169
+ nullif({{ strategy.updated_at }}, {{ strategy.updated_at }}) as {{ columns.dbt_valid_to }}
164
170
  from (
165
171
  {{ sql }}
166
172
  ) sbq
@@ -1,5 +1,4 @@
1
1
  {% materialization snapshot, default %}
2
- {%- set config = model['config'] -%}
3
2
 
4
3
  {%- set target_table = model.get('alias', model.get('name')) -%}
5
4
 
@@ -24,7 +23,9 @@
24
23
  {{ run_hooks(pre_hooks, inside_transaction=True) }}
25
24
 
26
25
  {% set strategy_macro = strategy_dispatch(strategy_name) %}
27
- {% set strategy = strategy_macro(model, "snapshotted_data", "source_data", config, target_relation_exists) %}
26
+ {# The model['config'] parameter below is no longer used, but passing anyway for compatibility #}
27
+ {# It was a dictionary of config, instead of the config object from the context #}
28
+ {% set strategy = strategy_macro(model, "snapshotted_data", "source_data", model['config'], target_relation_exists) %}
28
29
 
29
30
  {% if not target_relation_exists %}
30
31
 
@@ -34,7 +35,9 @@
34
35
 
35
36
  {% else %}
36
37
 
37
- {{ adapter.valid_snapshot_target(target_relation) }}
38
+ {% set columns = config.get("snapshot_table_column_names") or get_snapshot_table_column_names() %}
39
+
40
+ {{ adapter.valid_snapshot_target(target_relation, columns) }}
38
41
 
39
42
  {% set build_or_select_sql = snapshot_staging_table(strategy, sql, target_relation) %}
40
43
  {% set staging_table = build_snapshot_staging_table(strategy, sql, target_relation) %}
@@ -7,15 +7,17 @@
7
7
  {% macro default__snapshot_merge_sql(target, source, insert_cols) -%}
8
8
  {%- set insert_cols_csv = insert_cols | join(', ') -%}
9
9
 
10
+ {%- set columns = config.get("snapshot_table_column_names") or get_snapshot_table_column_names() -%}
11
+
10
12
  merge into {{ target.render() }} as DBT_INTERNAL_DEST
11
13
  using {{ source }} as DBT_INTERNAL_SOURCE
12
- on DBT_INTERNAL_SOURCE.dbt_scd_id = DBT_INTERNAL_DEST.dbt_scd_id
14
+ on DBT_INTERNAL_SOURCE.{{ columns.dbt_scd_id }} = DBT_INTERNAL_DEST.{{ columns.dbt_scd_id }}
13
15
 
14
16
  when matched
15
- and DBT_INTERNAL_DEST.dbt_valid_to is null
17
+ and DBT_INTERNAL_DEST.{{ columns.dbt_valid_to }} is null
16
18
  and DBT_INTERNAL_SOURCE.dbt_change_type in ('update', 'delete')
17
19
  then update
18
- set dbt_valid_to = DBT_INTERNAL_SOURCE.dbt_valid_to
20
+ set {{ columns.dbt_valid_to }} = DBT_INTERNAL_SOURCE.{{ columns.dbt_valid_to }}
19
21
 
20
22
  when not matched
21
23
  and DBT_INTERNAL_SOURCE.dbt_change_type = 'insert'
@@ -49,10 +49,13 @@
49
49
  {#
50
50
  Core strategy definitions
51
51
  #}
52
- {% macro snapshot_timestamp_strategy(node, snapshotted_rel, current_rel, config, target_exists) %}
53
- {% set primary_key = config['unique_key'] %}
54
- {% set updated_at = config['updated_at'] %}
55
- {% set invalidate_hard_deletes = config.get('invalidate_hard_deletes', false) %}
52
+
53
+ {% macro snapshot_timestamp_strategy(node, snapshotted_rel, current_rel, model_config, target_exists) %}
54
+ {# The model_config parameter is no longer used, but is passed in anyway for compatibility. #}
55
+ {% set primary_key = config.get('unique_key') %}
56
+ {% set updated_at = config.get('updated_at') %}
57
+ {% set invalidate_hard_deletes = config.get('invalidate_hard_deletes') or false %}
58
+ {% set columns = config.get("snapshot_table_column_names") or get_snapshot_table_column_names() %}
56
59
 
57
60
  {#/*
58
61
  The snapshot relation might not have an {{ updated_at }} value if the
@@ -64,7 +67,7 @@
64
67
  See https://github.com/dbt-labs/dbt-core/issues/2350
65
68
  */ #}
66
69
  {% set row_changed_expr -%}
67
- ({{ snapshotted_rel }}.dbt_valid_from < {{ current_rel }}.{{ updated_at }})
70
+ ({{ snapshotted_rel }}.{{ columns.dbt_valid_from }} < {{ current_rel }}.{{ updated_at }})
68
71
  {%- endset %}
69
72
 
70
73
  {% set scd_id_expr = snapshot_hash_arguments([primary_key, updated_at]) %}
@@ -133,11 +136,12 @@
133
136
  {%- endmacro %}
134
137
 
135
138
 
136
- {% macro snapshot_check_strategy(node, snapshotted_rel, current_rel, config, target_exists) %}
137
- {% set check_cols_config = config['check_cols'] %}
138
- {% set primary_key = config['unique_key'] %}
139
- {% set invalidate_hard_deletes = config.get('invalidate_hard_deletes', false) %}
140
- {% set updated_at = config.get('updated_at', snapshot_get_time()) %}
139
+ {% macro snapshot_check_strategy(node, snapshotted_rel, current_rel, model_config, target_exists) %}
140
+ {# The model_config parameter is no longer used, but is passed in anyway for compatibility. #}
141
+ {% set check_cols_config = config.get('check_cols') %}
142
+ {% set primary_key = config.get('unique_key') %}
143
+ {% set invalidate_hard_deletes = config.get('invalidate_hard_deletes') or false %}
144
+ {% set updated_at = config.get('updated_at') or snapshot_get_time() %}
141
145
 
142
146
  {% set column_added = false %}
143
147
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: dbt-adapters
3
- Version: 1.6.1
3
+ Version: 1.7.0
4
4
  Summary: The set of adapter protocols and base functionality that supports integration with dbt-core
5
5
  Project-URL: Homepage, https://github.com/dbt-labs/dbt-adapters
6
6
  Project-URL: Documentation, https://docs.getdbt.com
@@ -1,5 +1,5 @@
1
1
  dbt/__init__.py,sha256=iY4jdvOxcDhkdr5FiyOTZPHadKtMZDQ-qC6Fw6_EHPM,277
2
- dbt/adapters/__about__.py,sha256=I459338_rcz1NQJHesMxcV5fxqOq2kxjzu-qNexQmFk,18
2
+ dbt/adapters/__about__.py,sha256=9UsQLZYw3LX7NO0PsCa8nGInSg0LC4sQ67EJUs50ljU,18
3
3
  dbt/adapters/__init__.py,sha256=3noHsg-64qI0_Pw6OR9F7l1vU2_qrJvinq8POTtuaZM,252
4
4
  dbt/adapters/cache.py,sha256=WGy4ewnz-J13LverTACBW2iFhGswrWLgm-wiBrQnMzo,20084
5
5
  dbt/adapters/capability.py,sha256=-Mbej2AL_bjQatHpFWUgsQ8z0zwnotyE9Y5DYHnX7NE,2364
@@ -12,7 +12,7 @@ dbt/adapters/base/README.md,sha256=muHQntC07Lh6L1XfVgwKhV5RltOPBLYPdQqd8_7l34c,5
12
12
  dbt/adapters/base/__init__.py,sha256=KGGGbj8jGMjAFJdQ5YHcOpApMMVZ_6Xuni1swhpkqRY,423
13
13
  dbt/adapters/base/column.py,sha256=Uj20UixoxCn2rlv4QDNONyys6CDkDFyG3anCXKf0T2c,5350
14
14
  dbt/adapters/base/connections.py,sha256=-C5dOwGgMKH8n_v6wjwOxV7chBdS0GjOGwNQCUbhhWc,16951
15
- dbt/adapters/base/impl.py,sha256=Ra8-5E478GxVDVG3kaKgQdubok-xJFI-SE1DNuRLuIg,70681
15
+ dbt/adapters/base/impl.py,sha256=7dUeQxHUaC8UpHHayacgUKP2JGGuWgfoh_I00YjN6yc,70604
16
16
  dbt/adapters/base/meta.py,sha256=IKqviGf7gK_qGtrn0t8NaSdUaw8g_M8SjICacMvNwGY,5702
17
17
  dbt/adapters/base/plugin.py,sha256=rm0GjNHnWM2mn0GJOjciZLwn-02xlzWCoMT9u-epwP0,1076
18
18
  dbt/adapters/base/query_headers.py,sha256=UluGd9IYCYkoMiDi5Yx_lnrCOSjWppjwRro4SIGgx8I,3496
@@ -33,7 +33,7 @@ dbt/adapters/events/types.py,sha256=nW7_FgrEmWlM-HWPHrYcJ5K5QLZtfspLizyqlXrJaoE,
33
33
  dbt/adapters/exceptions/__init__.py,sha256=LxRkxHARMzrPegrjha5tQ8vQi1PnL_ooq1SVqm9aiZs,1268
34
34
  dbt/adapters/exceptions/alias.py,sha256=QlCd2jvatfndec1DQLMMBJ-C_7w8yAySuAFHK2ga1g8,798
35
35
  dbt/adapters/exceptions/cache.py,sha256=u720DQQKm8pyf_9loD9HGA9WgaeZAlg0sBn0sGc-rhA,2492
36
- dbt/adapters/exceptions/compilation.py,sha256=KAiCwxyE1B3PrxU-aHvpJp4h6fgEcZf44h4iVz__jFY,8586
36
+ dbt/adapters/exceptions/compilation.py,sha256=2QsAX-z_1K4q8jGtvbC1JM6dEh7lyOF7rTWkV6RXC8o,8720
37
37
  dbt/adapters/exceptions/connection.py,sha256=x82j2Ix242Slm6Ima8Tol3GLOB9yZYH5lq6IV1WKq54,445
38
38
  dbt/adapters/exceptions/database.py,sha256=nIXJdQyPQOZaiKvCkQ3MoKlKOiaN58rtDZflw3CSkug,1618
39
39
  dbt/adapters/record/__init__.py,sha256=u_0eJzN5RL90oL-RNoP2wWGMCGp0kG0lZ0uVWnnGdxs,123
@@ -94,10 +94,10 @@ dbt/include/global_project/macros/materializations/models/incremental/on_schema_
94
94
  dbt/include/global_project/macros/materializations/models/incremental/strategies.sql,sha256=ORGWiYfj-b3_VIps9FDlyx-Q4A2hZzX2aYLocW8b6pU,2613
95
95
  dbt/include/global_project/macros/materializations/seeds/helpers.sql,sha256=Y15ej-D3gm1ExIOMNT208q43gRk8d985WQBuGSooNL0,3920
96
96
  dbt/include/global_project/macros/materializations/seeds/seed.sql,sha256=YSoGzVO3iIUiOKIUM9G7yApGLFH4O9bv_d4KjHo3p4Q,2155
97
- dbt/include/global_project/macros/materializations/snapshots/helpers.sql,sha256=rLnopom7nEzbQ12C9O9yIMh4C8poshYqlVTnmE4gLh0,6012
98
- dbt/include/global_project/macros/materializations/snapshots/snapshot.sql,sha256=q_LzkaeJCXGemzPvHnCWYTUS7ODaS747cYN_zXZHb7k,3874
99
- dbt/include/global_project/macros/materializations/snapshots/snapshot_merge.sql,sha256=Lu3Yq3fEQuOGoDY0NFfruTAuvOEF3wXuo3SF_dK7uqY,858
100
- dbt/include/global_project/macros/materializations/snapshots/strategies.sql,sha256=ahWDMnD-Q_fTGKSjvm5ZwvypmNC6BDVguk-LNk-nHhU,6286
97
+ dbt/include/global_project/macros/materializations/snapshots/helpers.sql,sha256=1b8eabOj1fAN1K6fRpit9dGJB0X1Qf4DjMbZQ-hltlA,6669
98
+ dbt/include/global_project/macros/materializations/snapshots/snapshot.sql,sha256=9Mu5htyKbIfDD2WKTrlKYki9jqAIKHPnG_5-5k6A04I,4144
99
+ dbt/include/global_project/macros/materializations/snapshots/snapshot_merge.sql,sha256=kPaqxd8t-s0uLNb2ngv5d0kqbMHws8nNT7h4e4cFQg8,1034
100
+ dbt/include/global_project/macros/materializations/snapshots/strategies.sql,sha256=CeZFcbFrIebICz8yii9-FYaEcevGEs76f1uTXO-s6M0,6636
101
101
  dbt/include/global_project/macros/materializations/tests/helpers.sql,sha256=rxUxDZm4EvrDbi0H_ePghE34_QLmxGEY2o_LTMc9CU0,1731
102
102
  dbt/include/global_project/macros/materializations/tests/test.sql,sha256=Rz3O_3dWHlIofG3d2CwsP2bXFimRZUIwOevyB0iz1J4,1831
103
103
  dbt/include/global_project/macros/materializations/tests/unit.sql,sha256=KonePuFfwcz5uJ-JW0CrEy8_q-Gl45fonngGmFvQcNU,1252
@@ -157,7 +157,7 @@ dbt/include/global_project/macros/utils/right.sql,sha256=EwNG98CAFIwNDmarwopf7Rk
157
157
  dbt/include/global_project/macros/utils/safe_cast.sql,sha256=1mswwkDACmIi1I99JKb_-vq3kjMe4HhMRV70mW8Bt4Y,298
158
158
  dbt/include/global_project/macros/utils/split_part.sql,sha256=fXEIS0oIiYR7-4lYbb0QbZdG-q2TpV63AFd1ky4I5UM,714
159
159
  dbt/include/global_project/tests/generic/builtin.sql,sha256=p94xdyPwb2TlxgLBqCfrcRfJ1QNgsjPvBm8f0Q5eqZM,1022
160
- dbt_adapters-1.6.1.dist-info/METADATA,sha256=HUGl0XGYZsA8LOfUA988OMIbug__FjBsdrxf-XOh9Jk,2547
161
- dbt_adapters-1.6.1.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
162
- dbt_adapters-1.6.1.dist-info/licenses/LICENSE,sha256=9yjigiJhWcCZvQjdagGKDwrRph58QWc5P2bVSQwXo6s,11344
163
- dbt_adapters-1.6.1.dist-info/RECORD,,
160
+ dbt_adapters-1.7.0.dist-info/METADATA,sha256=gQvoMf7BRxJKW8eClvRaiFTaP7j3XEP9l3u2a5CXyGc,2547
161
+ dbt_adapters-1.7.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
162
+ dbt_adapters-1.7.0.dist-info/licenses/LICENSE,sha256=9yjigiJhWcCZvQjdagGKDwrRph58QWc5P2bVSQwXo6s,11344
163
+ dbt_adapters-1.7.0.dist-info/RECORD,,