Skip to content

Commit

Permalink
fine-tune implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusMerkleQC committed Nov 6, 2024
1 parent 7809009 commit a610fcd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion sqlcompyre/analysis/schema_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def table_names(self) -> Names:
return Names(
left=set(self.left_tables.keys()),
right=set(self.right_tables.keys()),
column_name_mapping=None,
name_mapping=None,
ignore_casing=self.ignore_casing,
)

Expand Down
2 changes: 1 addition & 1 deletion sqlcompyre/analysis/table_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def column_names(self) -> Names:
return Names(
left={col.name for col in self.left_table.columns},
right={col.name for col in self.right_table.columns},
column_name_mapping=self.column_name_mapping,
name_mapping=self.column_name_mapping,
ignore_casing=self.ignore_casing,
)

Expand Down
31 changes: 18 additions & 13 deletions sqlcompyre/results/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ def __init__(
self,
left: set[str],
right: set[str],
column_name_mapping: dict[str, str] | None,
name_mapping: dict[str, str] | None,
ignore_casing: bool,
):
"""
Args:
left: Names from the "left" database object.
right: Names from the "right" database object.
column_name_mapping: Mapping of column names from the "left" to the "right" database object.
name_mapping: Mapping from the "left" to the "right" database object.
ignore_casing: Whether to ignore casing for name equality.
"""
if ignore_casing:
Expand All @@ -27,7 +27,10 @@ def __init__(
else:
self._set_left = left
self._set_right = right
self.column_name_mapping = column_name_mapping
self.name_mapping = name_mapping
self.inverse_name_mapping = (
{v: k for k, v in name_mapping.items()} if name_mapping else {}
)

@cached_property
def left(self) -> list[str]:
Expand All @@ -47,20 +50,22 @@ def in_common(self) -> list[str]:
@cached_property
def missing_left(self) -> list[str]:
"""Ordered list of names provided only by the "right" database object."""
renamed_keys = (
set(self.column_name_mapping.values())
if self.column_name_mapping
else set()
)
return sorted(self._set_right - self._set_left - renamed_keys)
if self.name_mapping:
right_renamed = {
self.inverse_name_mapping.get(k, k) for k in self._set_right
}
else:
right_renamed = self._set_right
return sorted(right_renamed - self._set_left)

@cached_property
def missing_right(self) -> list[str]:
"""Ordered list of names provided only by the "left" database object."""
renamed_keys = (
set(self.column_name_mapping.keys()) if self.column_name_mapping else set()
)
return sorted(self._set_left - self._set_right - renamed_keys)
if self.name_mapping:
left_renamed = {self.name_mapping.get(k, k) for k in self._set_left}
else:
left_renamed = self._set_left
return sorted(self._set_left - left_renamed)

@cached_property
def equal(self) -> bool:
Expand Down

0 comments on commit a610fcd

Please sign in to comment.