Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions recce/util/change_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
normalize_change_category,
to_v2_change_category,
)
from recce.util.cll import set_operation_scopes

CHANGE_CATEGORY_UNKNOWN = NodeChange(category="unknown")
CHANGE_CATEGORY_BREAKING = NodeChange(category="breaking")
Expand Down Expand Up @@ -345,15 +346,17 @@ def selected_column_change_status(ref_column: exp.Column) -> Optional[ChangeStat
def _diff_union_scope(old_scope: Scope, new_scope: Scope, scope_changes_map: dict[Scope, NodeChange]) -> NodeChange:
assert old_scope.expression.key == "union"
assert new_scope.expression.key == "union"
assert len(old_scope.union_scopes) == len(new_scope.union_scopes)
assert new_scope.union_scopes is not None
assert len(new_scope.union_scopes) > 0
old_sub_scopes = set_operation_scopes(old_scope)
new_sub_scopes = set_operation_scopes(new_scope)
assert len(old_sub_scopes) == len(new_sub_scopes)
assert new_sub_scopes is not None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT (pre-existing, preserved by the rewrite): this is not None guard is unreachable as a guard — line 351 already calls len() on new_sub_scopes, so a None would raise TypeError there first and this assert can never be the thing that fires.

Since these three lines were rewritten anyway, moving it above the len() comparison would make it do what it reads like it does:

old_sub_scopes = set_operation_scopes(old_scope)
new_sub_scopes = set_operation_scopes(new_scope)
assert new_sub_scopes is not None
assert len(old_sub_scopes) == len(new_sub_scopes)
assert len(new_sub_scopes) > 0

No behavioural impact on either sqlglot version — purely a readability fix, entirely your call.

assert len(new_sub_scopes) > 0

result_left = scope_changes_map.get(new_scope.union_scopes[0])
result_left = scope_changes_map.get(new_sub_scopes[0])
change_category = result_left.category
changed_columns = result_left.columns.copy()

for sub_scope in new_scope.union_scopes[1:]:
for sub_scope in new_sub_scopes[1:]:
result_right = scope_changes_map.get(sub_scope)
if change_category == "partial_breaking":
if result_right.category in ["breaking"]:
Expand Down
9 changes: 8 additions & 1 deletion recce/util/cll.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,20 @@ def _dedeup_depends_on(depends_on: List[CllColumnDep]) -> List[CllColumnDep]:
return dedup_list


def set_operation_scopes(scope: Scope) -> List[Scope]:
# sqlglot 30.19 renamed Scope.union_scopes to Scope.set_operation_scopes.
if hasattr(scope, "set_operation_scopes"):
return scope.set_operation_scopes
return scope.union_scopes


def _cll_set_scope(scope: Scope, scope_cll_map: dict[Scope, CllResult]) -> CllResult:
# model-to-column
m2c: List[CllColumnDep] = []
# column-to-column
c2c_map: Dict[str, CllColumn] = {}

for union_scope in scope.union_scopes:
for union_scope in set_operation_scopes(scope):
sub_scope_result = scope_cll_map.get(union_scope)
if sub_scope_result is None:
raise RecceException(f"Scope {union_scope} not found in scope_cll_map")
Expand Down
Loading