dbt-adapters 1.7.0__py3-none-any.whl → 1.7.2__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.7.0"
1
+ version = "1.7.2"
@@ -6,6 +6,7 @@ from typing import (
6
6
  Dict,
7
7
  FrozenSet,
8
8
  Iterator,
9
+ List,
9
10
  Optional,
10
11
  Set,
11
12
  Tuple,
@@ -341,6 +342,16 @@ class BaseRelation(FakeAPIObject, Hashable):
341
342
  )
342
343
  return cls.from_dict(kwargs)
343
344
 
345
+ @classmethod
346
+ def scd_args(cls: Type[Self], primary_key: Union[str, List[str]], updated_at) -> List[str]:
347
+ scd_args = []
348
+ if isinstance(primary_key, list):
349
+ scd_args.extend(primary_key)
350
+ else:
351
+ scd_args.append(primary_key)
352
+ scd_args.append(updated_at)
353
+ return scd_args
354
+
344
355
  @property
345
356
  def can_be_renamed(self) -> bool:
346
357
  return self.type in self.renameable_relations
@@ -32,6 +32,9 @@
32
32
 
33
33
  {% set to_drop = [] %}
34
34
 
35
+ {% set incremental_strategy = config.get('incremental_strategy') or 'default' %}
36
+ {% set strategy_sql_macro_func = adapter.get_incremental_strategy_macro(context, incremental_strategy) %}
37
+
35
38
  {% if existing_relation is none %}
36
39
  {% set build_sql = get_create_table_as_sql(False, target_relation, sql) %}
37
40
  {% elif full_refresh_mode %}
@@ -52,9 +55,7 @@
52
55
  {% endif %}
53
56
 
54
57
  {#-- Get the incremental_strategy, the macro to use for the strategy, and build the sql --#}
55
- {% set incremental_strategy = config.get('incremental_strategy') or 'default' %}
56
58
  {% set incremental_predicates = config.get('predicates', none) or config.get('incremental_predicates', none) %}
57
- {% set strategy_sql_macro_func = adapter.get_incremental_strategy_macro(context, incremental_strategy) %}
58
59
  {% set strategy_arg_dict = ({'target_relation': target_relation, 'temp_relation': temp_relation, 'unique_key': unique_key, 'dest_columns': dest_columns, 'incremental_predicates': incremental_predicates }) %}
59
60
  {% set build_sql = strategy_sql_macro_func(strategy_arg_dict) %}
60
61
 
@@ -49,22 +49,24 @@
49
49
 
50
50
  snapshotted_data as (
51
51
 
52
- select *,
53
- {{ strategy.unique_key }} as dbt_unique_key
54
-
52
+ select *, {{ unique_key_fields(strategy.unique_key) }}
55
53
  from {{ target_relation }}
56
- where {{ columns.dbt_valid_to }} is null
54
+ where
55
+ {% if config.get('dbt_valid_to_current') %}
56
+ {# Check for either dbt_valid_to_current OR null, in order to correctly update records with nulls #}
57
+ ( {{ columns.dbt_valid_to }} = {{ config.get('dbt_valid_to_current') }} or {{ columns.dbt_valid_to }} is null)
58
+ {% else %}
59
+ {{ columns.dbt_valid_to }} is null
60
+ {% endif %}
57
61
 
58
62
  ),
59
63
 
60
64
  insertions_source_data as (
61
65
 
62
- select
63
- *,
64
- {{ strategy.unique_key }} as dbt_unique_key,
66
+ select *, {{ unique_key_fields(strategy.unique_key) }},
65
67
  {{ strategy.updated_at }} as {{ columns.dbt_updated_at }},
66
68
  {{ strategy.updated_at }} as {{ columns.dbt_valid_from }},
67
- nullif({{ strategy.updated_at }}, {{ strategy.updated_at }}) as {{ columns.dbt_valid_to }},
69
+ {{ get_dbt_valid_to_current(strategy, columns) }},
68
70
  {{ strategy.scd_id }} as {{ columns.dbt_scd_id }}
69
71
 
70
72
  from snapshot_query
@@ -72,9 +74,7 @@
72
74
 
73
75
  updates_source_data as (
74
76
 
75
- select
76
- *,
77
- {{ strategy.unique_key }} as dbt_unique_key,
77
+ select *, {{ unique_key_fields(strategy.unique_key) }},
78
78
  {{ strategy.updated_at }} as {{ columns.dbt_updated_at }},
79
79
  {{ strategy.updated_at }} as {{ columns.dbt_valid_from }},
80
80
  {{ strategy.updated_at }} as {{ columns.dbt_valid_to }}
@@ -86,9 +86,7 @@
86
86
 
87
87
  deletes_source_data as (
88
88
 
89
- select
90
- *,
91
- {{ strategy.unique_key }} as dbt_unique_key
89
+ select *, {{ unique_key_fields(strategy.unique_key) }}
92
90
  from snapshot_query
93
91
  ),
94
92
  {% endif %}
@@ -100,13 +98,11 @@
100
98
  source_data.*
101
99
 
102
100
  from insertions_source_data as source_data
103
- left outer join snapshotted_data on snapshotted_data.dbt_unique_key = source_data.dbt_unique_key
104
- where snapshotted_data.dbt_unique_key is null
105
- or (
106
- snapshotted_data.dbt_unique_key is not null
107
- and (
108
- {{ strategy.row_changed }}
109
- )
101
+ left outer join snapshotted_data
102
+ on {{ unique_key_join_on(strategy.unique_key, "snapshotted_data", "source_data") }}
103
+ where {{ unique_key_is_null(strategy.unique_key, "snapshotted_data") }}
104
+ or ({{ unique_key_is_not_null(strategy.unique_key, "snapshotted_data") }} and ({{ strategy.row_changed }})
105
+
110
106
  )
111
107
 
112
108
  ),
@@ -119,7 +115,8 @@
119
115
  snapshotted_data.{{ columns.dbt_scd_id }}
120
116
 
121
117
  from updates_source_data as source_data
122
- join snapshotted_data on snapshotted_data.dbt_unique_key = source_data.dbt_unique_key
118
+ join snapshotted_data
119
+ on {{ unique_key_join_on(strategy.unique_key, "snapshotted_data", "source_data") }}
123
120
  where (
124
121
  {{ strategy.row_changed }}
125
122
  )
@@ -139,8 +136,9 @@
139
136
  snapshotted_data.{{ columns.dbt_scd_id }}
140
137
 
141
138
  from snapshotted_data
142
- left join deletes_source_data as source_data on snapshotted_data.dbt_unique_key = source_data.dbt_unique_key
143
- where source_data.dbt_unique_key is null
139
+ left join deletes_source_data as source_data
140
+ on {{ unique_key_join_on(strategy.unique_key, "snapshotted_data", "source_data") }}
141
+ where {{ unique_key_is_null(strategy.unique_key, "source_data") }}
144
142
  )
145
143
  {%- endif %}
146
144
 
@@ -166,7 +164,7 @@
166
164
  {{ strategy.scd_id }} as {{ columns.dbt_scd_id }},
167
165
  {{ strategy.updated_at }} as {{ columns.dbt_updated_at }},
168
166
  {{ strategy.updated_at }} as {{ columns.dbt_valid_from }},
169
- nullif({{ strategy.updated_at }}, {{ strategy.updated_at }}) as {{ columns.dbt_valid_to }}
167
+ {{ get_dbt_valid_to_current(strategy, columns) }}
170
168
  from (
171
169
  {{ sql }}
172
170
  ) sbq
@@ -210,3 +208,52 @@
210
208
  {% endif %}
211
209
  {% endif %}
212
210
  {% endmacro %}
211
+
212
+
213
+ {% macro get_dbt_valid_to_current(strategy, columns) %}
214
+ {% set dbt_valid_to_current = config.get('dbt_valid_to_current') or "null" %}
215
+ coalesce(nullif({{ strategy.updated_at }}, {{ strategy.updated_at }}), {{dbt_valid_to_current}})
216
+ as {{ columns.dbt_valid_to }}
217
+ {% endmacro %}
218
+
219
+
220
+ {% macro unique_key_fields(unique_key) %}
221
+ {% if unique_key | is_list %}
222
+ {% for key in unique_key %}
223
+ {{ key }} as dbt_unique_key_{{ loop.index }}
224
+ {%- if not loop.last %} , {%- endif %}
225
+ {% endfor %}
226
+ {% else %}
227
+ {{ unique_key }} as dbt_unique_key
228
+ {% endif %}
229
+ {% endmacro %}
230
+
231
+
232
+ {% macro unique_key_join_on(unique_key, identifier, from_identifier) %}
233
+ {% if unique_key | is_list %}
234
+ {% for key in unique_key %}
235
+ {{ identifier }}.dbt_unique_key_{{ loop.index }} = {{ from_identifier }}.dbt_unique_key_{{ loop.index }}
236
+ {%- if not loop.last %} and {%- endif %}
237
+ {% endfor %}
238
+ {% else %}
239
+ {{ identifier }}.dbt_unique_key = {{ from_identifier }}.dbt_unique_key
240
+ {% endif %}
241
+ {% endmacro %}
242
+
243
+
244
+ {% macro unique_key_is_null(unique_key, identifier) %}
245
+ {% if unique_key | is_list %}
246
+ {{ identifier }}.dbt_unique_key_1 is null
247
+ {% else %}
248
+ {{ identifier }}.dbt_unique_key is null
249
+ {% endif %}
250
+ {% endmacro %}
251
+
252
+
253
+ {% macro unique_key_is_not_null(unique_key, identifier) %}
254
+ {% if unique_key | is_list %}
255
+ {{ identifier }}.dbt_unique_key_1 is not null
256
+ {% else %}
257
+ {{ identifier }}.dbt_unique_key is not null
258
+ {% endif %}
259
+ {% endmacro %}
@@ -46,20 +46,22 @@
46
46
  {% do adapter.expand_target_column_types(from_relation=staging_table,
47
47
  to_relation=target_relation) %}
48
48
 
49
+ {% set remove_columns = ['dbt_change_type', 'DBT_CHANGE_TYPE', 'dbt_unique_key', 'DBT_UNIQUE_KEY'] %}
50
+ {% if unique_key | is_list %}
51
+ {% for key in strategy.unique_key %}
52
+ {{ remove_columns.append('dbt_unique_key_' + loop.index|string) }}
53
+ {{ remove_columns.append('DBT_UNIQUE_KEY_' + loop.index|string) }}
54
+ {% endfor %}
55
+ {% endif %}
56
+
49
57
  {% set missing_columns = adapter.get_missing_columns(staging_table, target_relation)
50
- | rejectattr('name', 'equalto', 'dbt_change_type')
51
- | rejectattr('name', 'equalto', 'DBT_CHANGE_TYPE')
52
- | rejectattr('name', 'equalto', 'dbt_unique_key')
53
- | rejectattr('name', 'equalto', 'DBT_UNIQUE_KEY')
58
+ | rejectattr('name', 'in', remove_columns)
54
59
  | list %}
55
60
 
56
61
  {% do create_columns(target_relation, missing_columns) %}
57
62
 
58
63
  {% set source_columns = adapter.get_columns_in_relation(staging_table)
59
- | rejectattr('name', 'equalto', 'dbt_change_type')
60
- | rejectattr('name', 'equalto', 'DBT_CHANGE_TYPE')
61
- | rejectattr('name', 'equalto', 'dbt_unique_key')
62
- | rejectattr('name', 'equalto', 'DBT_UNIQUE_KEY')
64
+ | rejectattr('name', 'in', remove_columns)
63
65
  | list %}
64
66
 
65
67
  {% set quoted_source_columns = [] %}
@@ -14,7 +14,12 @@
14
14
  on DBT_INTERNAL_SOURCE.{{ columns.dbt_scd_id }} = DBT_INTERNAL_DEST.{{ columns.dbt_scd_id }}
15
15
 
16
16
  when matched
17
- and DBT_INTERNAL_DEST.{{ columns.dbt_valid_to }} is null
17
+ {% if config.get("dbt_valid_to_current") %}
18
+ and (DBT_INTERNAL_DEST.{{ columns.dbt_valid_to }} = {{ config.get('dbt_valid_to_current') }} or
19
+ DBT_INTERNAL_DEST.{{ columns.dbt_valid_to }} is null)
20
+ {% else %}
21
+ and DBT_INTERNAL_DEST.{{ columns.dbt_valid_to }} is null
22
+ {% endif %}
18
23
  and DBT_INTERNAL_SOURCE.dbt_change_type in ('update', 'delete')
19
24
  then update
20
25
  set {{ columns.dbt_valid_to }} = DBT_INTERNAL_SOURCE.{{ columns.dbt_valid_to }}
@@ -70,7 +70,8 @@
70
70
  ({{ snapshotted_rel }}.{{ columns.dbt_valid_from }} < {{ current_rel }}.{{ updated_at }})
71
71
  {%- endset %}
72
72
 
73
- {% set scd_id_expr = snapshot_hash_arguments([primary_key, updated_at]) %}
73
+ {% set scd_args = api.Relation.scd_args(primary_key, updated_at) %}
74
+ {% set scd_id_expr = snapshot_hash_arguments(scd_args) %}
74
75
 
75
76
  {% do return({
76
77
  "unique_key": primary_key,
@@ -166,7 +167,8 @@
166
167
  )
167
168
  {%- endset %}
168
169
 
169
- {% set scd_id_expr = snapshot_hash_arguments([primary_key, updated_at]) %}
170
+ {% set scd_args = api.Relation.scd_args(primary_key, updated_at) %}
171
+ {% set scd_id_expr = snapshot_hash_arguments(scd_args) %}
170
172
 
171
173
  {% do return({
172
174
  "unique_key": primary_key,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: dbt-adapters
3
- Version: 1.7.0
3
+ Version: 1.7.2
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
@@ -16,14 +16,13 @@ Classifier: License :: OSI Approved :: Apache Software License
16
16
  Classifier: Operating System :: MacOS :: MacOS X
17
17
  Classifier: Operating System :: Microsoft :: Windows
18
18
  Classifier: Operating System :: POSIX :: Linux
19
- Classifier: Programming Language :: Python :: 3.8
20
19
  Classifier: Programming Language :: Python :: 3.9
21
20
  Classifier: Programming Language :: Python :: 3.10
22
21
  Classifier: Programming Language :: Python :: 3.11
23
22
  Classifier: Programming Language :: Python :: 3.12
24
- Requires-Python: >=3.8.0
23
+ Requires-Python: >=3.9.0
25
24
  Requires-Dist: agate<2.0,>=1.0
26
- Requires-Dist: dbt-common<2.0,>=1.8
25
+ Requires-Dist: dbt-common<2.0,>=1.11
27
26
  Requires-Dist: mashumaro[msgpack]<4.0,>=3.0
28
27
  Requires-Dist: protobuf<5.0,>=3.0
29
28
  Requires-Dist: pytz>=2015.7
@@ -1,5 +1,5 @@
1
1
  dbt/__init__.py,sha256=iY4jdvOxcDhkdr5FiyOTZPHadKtMZDQ-qC6Fw6_EHPM,277
2
- dbt/adapters/__about__.py,sha256=9UsQLZYw3LX7NO0PsCa8nGInSg0LC4sQ67EJUs50ljU,18
2
+ dbt/adapters/__about__.py,sha256=nmG3pZh3PHNxtCaqlmZrGx0G1CNyDdjUYvAO0SpMB8E,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
@@ -16,7 +16,7 @@ dbt/adapters/base/impl.py,sha256=7dUeQxHUaC8UpHHayacgUKP2JGGuWgfoh_I00YjN6yc,706
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
19
- dbt/adapters/base/relation.py,sha256=MhwrOGOv6DeijeFy6n61PNdVsa6ZDOMHwwQqIMXYn-Y,18364
19
+ dbt/adapters/base/relation.py,sha256=uBvDb3XwYSu5t5RVj-OwfQgJFcxP9qBPgSqgQ_yzYbI,18708
20
20
  dbt/adapters/clients/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
21
  dbt/adapters/clients/jinja.py,sha256=NsZOiBpOLunS46hRL5OcX1MpY3Ih6_87Vgz4qd_PNbc,768
22
22
  dbt/adapters/contracts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -87,17 +87,17 @@ dbt/include/global_project/macros/materializations/models/clone/can_clone_table.
87
87
  dbt/include/global_project/macros/materializations/models/clone/clone.sql,sha256=X85U0zwq_OINxeZ7JDer9i3BgQZvgGM-tKTvITrQx5s,2716
88
88
  dbt/include/global_project/macros/materializations/models/clone/create_or_replace_clone.sql,sha256=qr33DwFOpRG0wGVsGvr63-MexYMNZC9xKdGOPmICp_c,367
89
89
  dbt/include/global_project/macros/materializations/models/incremental/column_helpers.sql,sha256=hslQlGKW0oW97srfugsFVRR-L6RrzRcnwr3uLhzI0X4,2577
90
- dbt/include/global_project/macros/materializations/models/incremental/incremental.sql,sha256=sS8XtG-T_-Gn1tCjSTFSlmJqkgu08-upWEs_UJ_RfXI,4377
90
+ dbt/include/global_project/macros/materializations/models/incremental/incremental.sql,sha256=8gyBXan-saJ9GTSa8d05vMa-RSwyZ7pStOeHJpHU4BI,4374
91
91
  dbt/include/global_project/macros/materializations/models/incremental/is_incremental.sql,sha256=Sm1TqOeqcCQofj3REFcA97yukPB1J_mClDd55r5GewE,478
92
92
  dbt/include/global_project/macros/materializations/models/incremental/merge.sql,sha256=Xg5-Gc9jHego-wpdfg6yEIQv7EClz6-xcJEeFXuZiwQ,5197
93
93
  dbt/include/global_project/macros/materializations/models/incremental/on_schema_change.sql,sha256=EOgcrYhwOGVPnyaBu7kIfe8LTOYVOu-AhxMtBs8ETpQ,4927
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=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
97
+ dbt/include/global_project/macros/materializations/snapshots/helpers.sql,sha256=h7VuSOq7gYwh2G2sh16AjP-57SsDG1M_ail22RNHAOk,8550
98
+ dbt/include/global_project/macros/materializations/snapshots/snapshot.sql,sha256=zxFMzo9MHii__ciSOGSoUT3dtBmSqHjtkIc9xah8axw,4011
99
+ dbt/include/global_project/macros/materializations/snapshots/snapshot_merge.sql,sha256=-uCvd2_E4AfWWEBRyQLiGCpuHgOG-MczlbLIWyGfAzM,1287
100
+ dbt/include/global_project/macros/materializations/snapshots/strategies.sql,sha256=5NB6nHW6qi-IcSf-ALwokTKHfOfV5Hzz4tGotgrV7JA,6746
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.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,,
160
+ dbt_adapters-1.7.2.dist-info/METADATA,sha256=MBPlx_JfK9iYRkF61AxSwob5KA15Y_4irl6FW99QO7Y,2498
161
+ dbt_adapters-1.7.2.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
162
+ dbt_adapters-1.7.2.dist-info/licenses/LICENSE,sha256=9yjigiJhWcCZvQjdagGKDwrRph58QWc5P2bVSQwXo6s,11344
163
+ dbt_adapters-1.7.2.dist-info/RECORD,,