Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 877a098

Browse files
committed
final changes and lint
1 parent 2263a3c commit 877a098

File tree

4 files changed

+26
-22
lines changed

4 files changed

+26
-22
lines changed

data_diff/dbt.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@
1212
from dbt_artifacts_parser.parser import parse_run_results, parse_manifest
1313
from dbt.config.renderer import ProfileRenderer
1414

15-
from .tracking import set_entrypoint_name, create_end_event_json, create_start_event_json, send_event_json, is_tracking_enabled
15+
from .tracking import (
16+
set_entrypoint_name,
17+
create_end_event_json,
18+
create_start_event_json,
19+
send_event_json,
20+
is_tracking_enabled,
21+
)
1622
from .utils import run_as_daemon, truncate_error
1723
from . import connect_to_table, diff_tables, Algorithm
1824

@@ -23,7 +29,6 @@
2329
LOWER_DBT_V = "1.0.0"
2430
UPPER_DBT_V = "1.5.0"
2531

26-
set_entrypoint_name("CLI-dbt")
2732

2833
@dataclass
2934
class DiffVars:
@@ -37,6 +42,7 @@ class DiffVars:
3742
def dbt_diff(
3843
profiles_dir_override: Optional[str] = None, project_dir_override: Optional[str] = None, is_cloud: bool = False
3944
) -> None:
45+
set_entrypoint_name("CLI-dbt")
4046
dbt_parser = DbtParser(profiles_dir_override, project_dir_override, is_cloud)
4147
models = dbt_parser.get_models()
4248
dbt_parser.set_project_dict()
@@ -200,6 +206,7 @@ def _cloud_diff(diff_vars: DiffVars) -> None:
200206

201207
start = time.monotonic()
202208
error = None
209+
diff_id = None
203210
try:
204211
response = requests.request("POST", url, headers=headers, json=payload, timeout=30)
205212
response.raise_for_status()
@@ -217,29 +224,29 @@ def _cloud_diff(diff_vars: DiffVars) -> None:
217224
+ "\n"
218225
)
219226
except BaseException as ex: # Catch KeyboardInterrupt too
220-
error = ex
227+
error = ex
221228
finally:
222229
# we don't currently have much of this information
223230
# but I imagine a future iteration of this _cloud method
224231
# will poll for results
225232
if is_tracking_enabled():
226233
err_message = truncate_error(repr(error))
227234
event_json = create_end_event_json(
228-
is_success = error is None,
229-
runtime_seconds = time.monotonic() - start,
230-
data_source_1_type = "",
231-
data_source_2_type = "",
232-
table1_count = 0,
233-
table2_count = 0,
234-
diff_count = 0,
235-
error = err_message,
236-
diff_id = diff_id,
237-
is_cloud = True
235+
is_success=error is None,
236+
runtime_seconds=time.monotonic() - start,
237+
data_source_1_type="",
238+
data_source_2_type="",
239+
table1_count=0,
240+
table2_count=0,
241+
diff_count=0,
242+
error=err_message,
243+
diff_id=diff_id,
244+
is_cloud=True,
238245
)
239246
send_event_json(event_json)
240247

241-
if error:
242-
raise error
248+
if error:
249+
raise error
243250

244251

245252
class DbtParser:

data_diff/diff_tables.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from data_diff.info_tree import InfoTree, SegmentInfo
1616

17+
from .utils import run_as_daemon, safezip, getLogger, truncate_error
1718
from .thread_utils import ThreadedYielder
1819
from .table_segment import TableSegment
1920
from .tracking import create_end_event_json, create_start_event_json, send_event_json, is_tracking_enabled
@@ -31,8 +32,6 @@ class Algorithm(Enum):
3132
DiffResult = Iterator[Tuple[str, tuple]] # Iterator[Tuple[Literal["+", "-"], tuple]]
3233

3334

34-
35-
3635
@dataclass
3736
class ThreadBase:
3837
"Provides utility methods for optional threading"
@@ -120,7 +119,6 @@ def _get_stats(self) -> DiffStats:
120119
return DiffStats(diff_by_sign, table1_count, table2_count, unchanged, diff_percent)
121120

122121
def get_stats_string(self):
123-
124122
diff_stats = self._get_stats()
125123
string_output = ""
126124
string_output += f"{diff_stats.table1_count} rows in table A\n"
@@ -139,7 +137,6 @@ def get_stats_string(self):
139137
return string_output
140138

141139
def get_stats_dict(self):
142-
143140
diff_stats = self._get_stats()
144141
json_output = {
145142
"rows_A": diff_stats.table1_count,
@@ -186,7 +183,6 @@ def _diff_tables_wrapper(self, table1: TableSegment, table2: TableSegment, info_
186183
start = time.monotonic()
187184
error = None
188185
try:
189-
190186
# Query and validate schema
191187
table1, table2 = self._threaded_call("with_schema", [table1, table2])
192188
self._validate_and_adjust_columns(table1, table2)

data_diff/tracking.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def create_end_event_json(
9292
diff_count: int,
9393
error: Optional[str],
9494
diff_id: Optional[int] = None,
95-
is_cloud: bool = False
95+
is_cloud: bool = False,
9696
):
9797
return {
9898
"event": "os_diff_run_end",
@@ -111,7 +111,7 @@ def create_end_event_json(
111111
"data_diff_version:": __version__,
112112
"entrypoint_name": entrypoint_name,
113113
"is_cloud": is_cloud,
114-
"diff_id": diff_id
114+
"diff_id": diff_id,
115115
},
116116
}
117117

data_diff/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def get_timestamp(_match):
7373

7474
return re.sub("%t", get_timestamp, name)
7575

76+
7677
def truncate_error(error: str):
7778
first_line = error.split("\n", 1)[0]
7879
return re.sub("'(.*?)'", "'***'", first_line)

0 commit comments

Comments
 (0)