dbt-common 1.1.0__py3-none-any.whl → 1.3.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.
- dbt_common/__about__.py +1 -1
- dbt_common/contracts/metadata.py +59 -0
- dbt_common/record.py +42 -7
- {dbt_common-1.1.0.dist-info → dbt_common-1.3.0.dist-info}/METADATA +1 -1
- {dbt_common-1.1.0.dist-info → dbt_common-1.3.0.dist-info}/RECORD +7 -6
- {dbt_common-1.1.0.dist-info → dbt_common-1.3.0.dist-info}/WHEEL +0 -0
- {dbt_common-1.1.0.dist-info → dbt_common-1.3.0.dist-info}/licenses/LICENSE +0 -0
dbt_common/__about__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
version = "1.
|
1
|
+
version = "1.3.0"
|
@@ -0,0 +1,59 @@
|
|
1
|
+
from dataclasses import dataclass
|
2
|
+
from typing import Dict, Optional, Union, NamedTuple
|
3
|
+
|
4
|
+
from dbt_common.dataclass_schema import dbtClassMixin
|
5
|
+
from dbt_common.utils.formatting import lowercase
|
6
|
+
|
7
|
+
|
8
|
+
@dataclass
|
9
|
+
class StatsItem(dbtClassMixin):
|
10
|
+
id: str
|
11
|
+
label: str
|
12
|
+
value: Union[bool, str, float, None]
|
13
|
+
include: bool
|
14
|
+
description: Optional[str] = None
|
15
|
+
|
16
|
+
|
17
|
+
StatsDict = Dict[str, StatsItem]
|
18
|
+
|
19
|
+
|
20
|
+
@dataclass
|
21
|
+
class TableMetadata(dbtClassMixin):
|
22
|
+
type: str
|
23
|
+
schema: str
|
24
|
+
name: str
|
25
|
+
database: Optional[str] = None
|
26
|
+
comment: Optional[str] = None
|
27
|
+
owner: Optional[str] = None
|
28
|
+
|
29
|
+
|
30
|
+
CatalogKey = NamedTuple(
|
31
|
+
"CatalogKey", [("database", Optional[str]), ("schema", str), ("name", str)]
|
32
|
+
)
|
33
|
+
|
34
|
+
|
35
|
+
@dataclass
|
36
|
+
class ColumnMetadata(dbtClassMixin):
|
37
|
+
type: str
|
38
|
+
index: int
|
39
|
+
name: str
|
40
|
+
comment: Optional[str] = None
|
41
|
+
|
42
|
+
|
43
|
+
ColumnMap = Dict[str, ColumnMetadata]
|
44
|
+
|
45
|
+
|
46
|
+
@dataclass
|
47
|
+
class CatalogTable(dbtClassMixin):
|
48
|
+
metadata: TableMetadata
|
49
|
+
columns: ColumnMap
|
50
|
+
stats: StatsDict
|
51
|
+
# the same table with two unique IDs will just be listed two times
|
52
|
+
unique_id: Optional[str] = None
|
53
|
+
|
54
|
+
def key(self) -> CatalogKey:
|
55
|
+
return CatalogKey(
|
56
|
+
lowercase(self.metadata.database),
|
57
|
+
self.metadata.schema.lower(),
|
58
|
+
self.metadata.name.lower(),
|
59
|
+
)
|
dbt_common/record.py
CHANGED
@@ -59,14 +59,18 @@ class Diff:
|
|
59
59
|
class RecorderMode(Enum):
|
60
60
|
RECORD = 1
|
61
61
|
REPLAY = 2
|
62
|
+
RECORD_QUERIES = 3
|
62
63
|
|
63
64
|
|
64
65
|
class Recorder:
|
65
66
|
_record_cls_by_name: Dict[str, Type] = {}
|
66
67
|
_record_name_by_params_name: Dict[str, str] = {}
|
67
68
|
|
68
|
-
def __init__(
|
69
|
+
def __init__(
|
70
|
+
self, mode: RecorderMode, types: Optional[List], recording_path: Optional[str] = None
|
71
|
+
) -> None:
|
69
72
|
self.mode = mode
|
73
|
+
self.types = types
|
70
74
|
self._records_by_type: Dict[str, List[Record]] = {}
|
71
75
|
self._replay_diffs: List["Diff"] = []
|
72
76
|
|
@@ -118,13 +122,14 @@ class Recorder:
|
|
118
122
|
records_by_type: Dict[str, List[Record]] = {}
|
119
123
|
|
120
124
|
for record_type_name in loaded_dct:
|
125
|
+
# TODO: this breaks with QueryRecord on replay since it's
|
126
|
+
# not in common so isn't part of cls._record_cls_by_name yet
|
121
127
|
record_cls = cls._record_cls_by_name[record_type_name]
|
122
128
|
rec_list = []
|
123
129
|
for record_dct in loaded_dct[record_type_name]:
|
124
130
|
rec = record_cls.from_dict(record_dct)
|
125
131
|
rec_list.append(rec) # type: ignore
|
126
132
|
records_by_type[record_type_name] = rec_list
|
127
|
-
|
128
133
|
return records_by_type
|
129
134
|
|
130
135
|
def expect_record(self, params: Any) -> Any:
|
@@ -147,17 +152,44 @@ class Recorder:
|
|
147
152
|
|
148
153
|
|
149
154
|
def get_record_mode_from_env() -> Optional[RecorderMode]:
|
150
|
-
|
151
|
-
|
152
|
-
|
155
|
+
"""
|
156
|
+
Get the record mode from the environment variables.
|
157
|
+
|
158
|
+
If the mode is not set to 'RECORD' or 'REPLAY', return None.
|
159
|
+
Expected format: 'DBT_RECORDER_MODE=RECORD'
|
160
|
+
"""
|
161
|
+
record_mode = os.environ.get("DBT_RECORDER_MODE")
|
153
162
|
|
154
|
-
|
155
|
-
|
163
|
+
if record_mode is None:
|
164
|
+
return None
|
165
|
+
|
166
|
+
if record_mode.lower() == "record":
|
156
167
|
return RecorderMode.RECORD
|
168
|
+
# replaying requires a file path, otherwise treat as noop
|
169
|
+
elif record_mode.lower() == "replay" and os.environ.get("DBT_RECORDER_FILE_PATH") is not None:
|
170
|
+
return RecorderMode.REPLAY
|
157
171
|
|
172
|
+
# if you don't specify record/replay it's a noop
|
158
173
|
return None
|
159
174
|
|
160
175
|
|
176
|
+
def get_record_types_from_env() -> Optional[List]:
|
177
|
+
"""
|
178
|
+
Get the record subset from the environment variables.
|
179
|
+
|
180
|
+
If no types are provided, there will be no filtering.
|
181
|
+
Invalid types will be ignored.
|
182
|
+
Expected format: 'DBT_RECORDER_TYPES=QueryRecord,FileLoadRecord,OtherRecord'
|
183
|
+
"""
|
184
|
+
record_types_str = os.environ.get("DBT_RECORDER_TYPES")
|
185
|
+
|
186
|
+
# if all is specified we don't want any type filtering
|
187
|
+
if record_types_str is None or record_types_str.lower == "all":
|
188
|
+
return None
|
189
|
+
|
190
|
+
return record_types_str.split(",")
|
191
|
+
|
192
|
+
|
161
193
|
def record_function(record_type, method=False, tuple_result=False):
|
162
194
|
def record_function_inner(func_to_record):
|
163
195
|
# To avoid runtime overhead and other unpleasantness, we only apply the
|
@@ -176,6 +208,9 @@ def record_function(record_type, method=False, tuple_result=False):
|
|
176
208
|
if recorder is None:
|
177
209
|
return func_to_record(*args, **kwargs)
|
178
210
|
|
211
|
+
if recorder.types is not None and record_type.__name__ not in recorder.types:
|
212
|
+
return func_to_record(*args, **kwargs)
|
213
|
+
|
179
214
|
# For methods, peel off the 'self' argument before calling the
|
180
215
|
# params constructor.
|
181
216
|
param_args = args[1:] if method else args
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: dbt-common
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.3.0
|
4
4
|
Summary: The shared common utilities that dbt-core and adapter implementations use
|
5
5
|
Project-URL: Homepage, https://github.com/dbt-labs/dbt-common
|
6
6
|
Project-URL: Repository, https://github.com/dbt-labs/dbt-common.git
|
@@ -1,4 +1,4 @@
|
|
1
|
-
dbt_common/__about__.py,sha256=
|
1
|
+
dbt_common/__about__.py,sha256=qg6ZAU0TpLWOHtkFC272q_j3aVEzW76H0lONbKcgFA8,18
|
2
2
|
dbt_common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
3
|
dbt_common/constants.py,sha256=-Y5DIL1SDPQWtlCNizXRYxFgbx1D7LaLs1ysamvGMRk,278
|
4
4
|
dbt_common/context.py,sha256=BhgT7IgyvpZHEtIdFVVuBBBX5LuU7obXT7NvIPeuD2g,1760
|
@@ -6,7 +6,7 @@ dbt_common/dataclass_schema.py,sha256=t3HGD0oXTSjitctuCVHv3iyq5BT3jxoSxv_VGkrJlE
|
|
6
6
|
dbt_common/helper_types.py,sha256=NoxqGFAq9bOjh7rqtz_eepXAxk20n3mmW_gUVpnMyYU,3901
|
7
7
|
dbt_common/invocation.py,sha256=Zw8jRPn75oi2VrUD6qGvaCDtSyIfqm5pJlPpRjs3s1E,202
|
8
8
|
dbt_common/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
|
-
dbt_common/record.py,sha256=
|
9
|
+
dbt_common/record.py,sha256=fwp8Q2x0UiB9fHbMFkmOlAgKLst1dhDxQpSSsd04aDw,8204
|
10
10
|
dbt_common/semver.py,sha256=2zoZYCQ7PfswqslT2NHuMGgPGMuMuX-yRThVoqfDWQU,13954
|
11
11
|
dbt_common/tests.py,sha256=6lC_JuRtoYO6cbAF8-R5aTM4HtQiM_EH8X5m_97duGY,315
|
12
12
|
dbt_common/ui.py,sha256=rc2TEM29raBFc_LXcg901pMDD07C2ohwp9qzkE-7pBY,2567
|
@@ -17,6 +17,7 @@ dbt_common/clients/jinja.py,sha256=i6VQ94FU4F6ZCQLHTxNSeGHmvyYSIe34nDhNkH6wO08,1
|
|
17
17
|
dbt_common/clients/system.py,sha256=OOhRDWR5t0Ns3OhkqjPTNTtyl_RMRWPDHWCzDoFtgkA,23014
|
18
18
|
dbt_common/contracts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
19
19
|
dbt_common/contracts/constraints.py,sha256=hyqTW2oPB1dfXWW388LWnL-EFdqTpQciKISH3CeLkro,1267
|
20
|
+
dbt_common/contracts/metadata.py,sha256=K_M06Rue0wmrQhFP_mq3uvQszq10CIt93oGiAVgbRfE,1293
|
20
21
|
dbt_common/contracts/util.py,sha256=RZpeEExSKdyFwTq7MM3rd1ZkAf11C7I-bgppUJ6SXOg,741
|
21
22
|
dbt_common/contracts/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
22
23
|
dbt_common/contracts/config/base.py,sha256=jWLf6SBUy7wngYs0Z5Zmx1O1v86XRueYaABlZ0W2Bxc,8356
|
@@ -55,7 +56,7 @@ dbt_common/utils/encoding.py,sha256=6_kSY2FvGNYMg7oX7PrbvVioieydih3Kl7Ii802LaHI,
|
|
55
56
|
dbt_common/utils/executor.py,sha256=Zyzd1wML3aN-iYn9ZG2Gc_jj5vknmvQNyH-c0RaPIpo,2446
|
56
57
|
dbt_common/utils/formatting.py,sha256=JUn5rzJ-uajs9wPCN0-f2iRFY1pOJF5YjTD9dERuLoc,165
|
57
58
|
dbt_common/utils/jinja.py,sha256=XNfZHuZhLM_R_yPmzYojPm6bF7QOoxIjSWrkJRw6wks,965
|
58
|
-
dbt_common-1.
|
59
|
-
dbt_common-1.
|
60
|
-
dbt_common-1.
|
61
|
-
dbt_common-1.
|
59
|
+
dbt_common-1.3.0.dist-info/METADATA,sha256=WLyv25ll2nMlvoBBwbM8rrEIyB6MwbUTpT69REVxOg4,5264
|
60
|
+
dbt_common-1.3.0.dist-info/WHEEL,sha256=zEMcRr9Kr03x1ozGwg5v9NQBKn3kndp6LSoSlVg-jhU,87
|
61
|
+
dbt_common-1.3.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
62
|
+
dbt_common-1.3.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|