Skip to content

Commit

Permalink
fix: Use less common name as match suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusMerkleQC committed Nov 6, 2024
1 parent fb576c8 commit a5499cc
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions sqlcompyre/analysis/table_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,13 @@ def row_matches(self) -> RowMatches:
@cached_property
def column_matches(self) -> ColumnMatches:
"""A comparison between the column values of the two tables."""
MATCH_SUFFIX = "_match"
inner_join = self._inner_join()

# Query for testing equality of column values in matching rows
cases = [
sa.case((self._is_equal(left_column, right_column), 1.0), else_=0.0).label(
f"{left_column}_match"
f"{left_column}_{MATCH_SUFFIX}"
)
for left_column, right_column in self.column_name_mapping.items()
if left_column not in self.join_columns
Expand All @@ -268,10 +269,10 @@ def column_matches(self) -> ColumnMatches:
case_stmt = select(*cases).select_from(inner_join).subquery()

# Compute fraction of matching values
cols_to_avg = [col for col in case_stmt.c if "_match" in col.name]
cols_to_avg = [col for col in case_stmt.c if f"_{MATCH_SUFFIX}" in col.name]
avgs = select(
*[
sa.func.avg(col).label(f"{col.name.replace('_match', '')}")
sa.func.avg(col).label(f"{col.name.replace(f'_{MATCH_SUFFIX}', '')}")
for col in cols_to_avg
]
)
Expand Down

0 comments on commit a5499cc

Please sign in to comment.