forked from datafold/data-diff
-
Notifications
You must be signed in to change notification settings - Fork 0
lightweight cli output update #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,7 @@ class DiffStats: | |
table2_count: int | ||
unchanged: int | ||
diff_percent: float | ||
extra_column_diffs: Dict[str, int] | ||
|
||
|
||
@dataclass | ||
|
@@ -123,6 +124,40 @@ def _get_stats(self) -> DiffStats: | |
|
||
return DiffStats(diff_by_sign, table1_count, table2_count, unchanged, diff_percent) | ||
|
||
def _get_stats_dbt(self) -> DiffStats: | ||
list(self) # Consume the iterator into result_list, if we haven't already | ||
|
||
key_columns = self.info_tree.info.tables[0].key_columns | ||
diff_by_key = {} | ||
extra_column_values_store = {} | ||
|
||
extra_columns = self.info_tree.info.tables[0].extra_columns | ||
extra_column_diffs = {k:0 for k in extra_columns} | ||
|
||
for sign, values in self.result_list: | ||
k = values[: len(self.info_tree.info.tables[0].key_columns)] | ||
extra_column_values = values[len(self.info_tree.info.tables[0].key_columns) :] | ||
if k in diff_by_key: | ||
assert sign != diff_by_key[k] | ||
diff_by_key[k] = "!" | ||
for i in range(0,len(extra_columns)): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to implement this using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the tip @erezsh that's new to me, I'll try it out. |
||
if extra_column_values[i] != extra_column_values_store[k][i]: | ||
extra_column_diffs[extra_columns[i]] += 1 | ||
else: | ||
diff_by_key[k] = sign | ||
extra_column_values_store[k] = extra_column_values | ||
|
||
diff_by_sign = {k: 0 for k in "+-!"} | ||
for sign in diff_by_key.values(): | ||
diff_by_sign[sign] += 1 | ||
|
||
table1_count = self.info_tree.info.rowcounts[1] | ||
table2_count = self.info_tree.info.rowcounts[2] | ||
unchanged = table1_count - diff_by_sign["-"] - diff_by_sign["!"] | ||
diff_percent = 1 - unchanged / max(table1_count, table2_count) | ||
|
||
return DiffStats(diff_by_sign, table1_count, table2_count, unchanged, diff_percent, extra_column_diffs) | ||
|
||
def get_stats_string(self): | ||
|
||
diff_stats = self._get_stats() | ||
|
@@ -142,6 +177,32 @@ def get_stats_string(self): | |
|
||
return string_output | ||
|
||
def get_stats_string_dbt(self): | ||
|
||
diff_stats = self._get_stats_dbt() | ||
string_output = "" | ||
string_output += f"{diff_stats.table1_count} rows in table A\n" | ||
string_output += f"{diff_stats.table2_count} rows in table B\n" | ||
string_output += f"{diff_stats.diff_by_sign['-']} rows exclusive to table A (not present in B)\n" | ||
string_output += f"{diff_stats.diff_by_sign['+']} rows exclusive to table B (not present in A)\n" | ||
string_output += f"{diff_stats.diff_by_sign['!']} rows updated\n" | ||
string_output += f"{diff_stats.unchanged} rows unchanged\n" | ||
string_output += f"{100*diff_stats.diff_percent:.2f}% difference score\n" | ||
|
||
string_output = "\n| Rows Added\t| Rows Removed\n" | ||
string_output += "------------------------------------------------------------\n" | ||
leoebfolsom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
string_output += f"| {diff_stats.diff_by_sign['-']}\t\t| {diff_stats.diff_by_sign['+']}\n" | ||
string_output += "------------------------------------------------------------\n\n" | ||
string_output += f"Updated Rows: {diff_stats.diff_by_sign['!']}\n" | ||
string_output += f"Identical Rows: {diff_stats.unchanged}\n\n" | ||
|
||
string_output += f"Values Updated:" | ||
|
||
for k, v in diff_stats.extra_column_diffs.items(): | ||
string_output += f"\n{k}: {v}" | ||
|
||
return string_output | ||
|
||
def get_stats_dict(self): | ||
|
||
diff_stats = self._get_stats() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.