Skip to content

Commit 460c05e

Browse files
authored
Fix: Improve the change categorization results by pre-matching root AST nodes (#831)
1 parent a5419e9 commit 460c05e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

sqlmesh/core/model/definition.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,12 @@ def is_breaking_change(self, previous: Model) -> t.Optional[bool]:
674674
if not isinstance(previous, SqlModel):
675675
return None
676676

677-
edits = ChangeDistiller(t=0.5).diff(previous.render_query(), self.render_query())
677+
previous_query = previous.render_query()
678+
this_query = self.render_query()
679+
680+
edits = ChangeDistiller(t=0.5).diff(
681+
previous_query, this_query, matchings=[(previous_query, this_query)]
682+
)
678683
inserted_expressions = {e.expression for e in edits if isinstance(e, Insert)}
679684

680685
for edit in edits:

tests/core/test_snapshot.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,11 @@ def test_categorize_change_sql(make_snapshot):
540540
# A complex projection has been added.
541541
assert (
542542
categorize_change(
543-
new=make_snapshot(SqlModel(name="a", query=parse_one("select 1, fun(a * 2)::INT, ds"))),
543+
new=make_snapshot(
544+
SqlModel(
545+
name="a", query=parse_one("select 1, fun(another_fun(a + 1) * 2)::INT, ds")
546+
)
547+
),
544548
old=old_snapshot,
545549
config=config,
546550
)

0 commit comments

Comments
 (0)