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

Add Diff Time after each Data Diff #770

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 15 additions & 3 deletions data_diff/dbt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from contextlib import nullcontext
import json
import time
import os
import re
import time
Expand Down Expand Up @@ -113,7 +114,9 @@ def dbt_diff(
dbt_parser.set_connection()

with log_status_handler.status if log_status_handler else nullcontext():
total_start_time = time.monotonic()
for model in models:
start_time = time.monotonic()
if log_status_handler:
log_status_handler.set_prefix(f"Diffing {model.alias} \n")

Expand Down Expand Up @@ -146,6 +149,8 @@ def dbt_diff(
diff_threads.append(diff_thread)
else:
_local_diff(diff_vars, json_output)
if not is_cloud:
log_status_handler.stop_counter(start_time=start_time)
else:
if json_output:
print(
Expand All @@ -169,7 +174,10 @@ def dbt_diff(
if diff_threads:
for thread in diff_threads:
thread.join()

# TODO: update this to be a function instead
total_end_time = time.monotonic()
total_duration = total_end_time - total_start_time
rich.print(f"[blue][bold]Total Diff Time: {total_duration:.2f}s")
_extension_notification()


Expand Down Expand Up @@ -469,11 +477,15 @@ def _cloud_diff(
diff_percent_list,
"Value Match Percent:",
)
diff_output_str += f"\n{diff_url}\n {diff_output} \n"
diff_output_str += f"\n{diff_url}\n {diff_output}"
rich.print(diff_output_str)
if log_status_handler:
log_status_handler.stop_counter(start_time=start)
else:
diff_output_str += f"\n{diff_url}\n{no_differences_template()}\n"
diff_output_str += f"\n{diff_url}\n{no_differences_template()}"
rich.print(diff_output_str)
if log_status_handler:
log_status_handler.stop_counter(start_time=start)

if log_status_handler:
log_status_handler.cloud_diff_finished(diff_vars.dev_path[-1])
Expand Down
10 changes: 9 additions & 1 deletion data_diff/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import time
import logging
import math
import re
Expand Down Expand Up @@ -455,7 +456,7 @@ def columns_type_changed_template(columns_type_changed) -> str:


def no_differences_template() -> str:
return "[bold][green]No row differences[/][/]\n"
return "[bold][green]No row differences[/][/]"


def print_version_info() -> None:
Expand Down Expand Up @@ -485,6 +486,7 @@ def __init__(self):
super().__init__()
self.status = Status("")
self.prefix = ""
self.diff_time = ""
self.cloud_diff_status = {}

def emit(self, record):
Expand All @@ -497,6 +499,12 @@ def emit(self, record):
def set_prefix(self, prefix_string):
self.prefix = prefix_string

def stop_counter(self, start_time):
end_time = time.monotonic()
duration = end_time - start_time
self.diff_time = f"diff time: {duration:.2f}s"
print(self.diff_time)

def cloud_diff_started(self, model_name):
self.cloud_diff_status[model_name] = "[yellow]In Progress[/]"
self._update_cloud_status()
Expand Down