-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow to compare queries in
compare_table
function (#16)
- Loading branch information
Showing
3 changed files
with
84 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright (c) QuantCo 2024-2025 | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
import sqlalchemy as sa | ||
|
||
import sqlcompyre as sc | ||
|
||
|
||
def test_compare_queries_join_columns_inferred( | ||
engine: sa.Engine, table_students: sa.Table | ||
): | ||
comparison = sc.compare_tables( | ||
engine, sa.select(table_students), sa.select(table_students) | ||
) | ||
assert comparison.join_columns == ["id"] | ||
|
||
|
||
def test_compare_queries_select(engine: sa.Engine, table_students: sa.Table): | ||
comparison = sc.compare_tables( | ||
engine, | ||
sa.select(table_students).where(table_students.c["age"] >= 30), | ||
sa.select(table_students).where(table_students.c["age"] >= 20), | ||
) | ||
assert comparison.row_counts.diff == 2 | ||
assert comparison.row_matches.n_joined_total == 2 | ||
|
||
|
||
def test_compare_queries_subquery(engine: sa.Engine, table_students: sa.Table): | ||
comparison = sc.compare_tables( | ||
engine, | ||
sa.select(table_students).where(table_students.c["age"] >= 30).subquery(), | ||
sa.select(table_students).where(table_students.c["age"] >= 20).subquery(), | ||
) | ||
assert comparison.row_counts.diff == 2 | ||
assert comparison.row_matches.n_joined_total == 2 |