Skip to content

feat(breaking): add column rename detection to schema diff analysis#1282

Draft
even-wei wants to merge 2 commits intomainfrom
spacedock-ensign/explore-integrate-sql-equivalence-poc
Draft

feat(breaking): add column rename detection to schema diff analysis#1282
even-wei wants to merge 2 commits intomainfrom
spacedock-ensign/explore-integrate-sql-equivalence-poc

Conversation

@even-wei
Copy link
Copy Markdown
Contributor

@even-wei even-wei commented Apr 8, 2026

PR checklist

  • Ensure you have added or ran the appropriate tests for your PR.
  • DCO signed

What type of PR is this?

Feature — adds column rename detection to the breaking change analysis pipeline.

What this PR does / why we need it:

When a dbt model column is renamed (e.g., number_of_ordersorder_count), the schema diff currently shows it as a separate "removed" + "added" pair. This is noisy and obscures the developer's intent.

This PR adds rename detection to the existing breaking change analysis in _diff_select_scope(). After the column comparison loop identifies removed and added columns, it compares their underlying SQL expressions (stripped of aliases). Columns with identical expressions are paired as renames instead of remove+add.

Changes:

  • recce/models/types.py: Add "renamed" to ChangeStatus literal type; add rename_map: Optional[dict[str, str]] to NodeChange model
  • recce/util/breaking.py: Add _unalias() helper and rename detection logic (~30 lines) in _diff_select_scope()
  • tests/util/test_breaking.py: Add 12 new rename detection tests + update 2 existing tests

Which issue(s) this PR fixes:

Resolves DRC-3185

Special notes for your reviewer:

  • This is Phase 1 (backend only). Frontend rendering of "renamed" status will come in Phase 3.
  • The rename_map field on NodeChange has no consumers yet — it carries metadata for future frontend use.
  • Known gaps deferred to Phase 3: rename_map case normalization in adapter, union scope rename_map merging, star propagation category escalation for "renamed". All documented in the review report.
  • The rename detection uses greedy first-match pairing, which is correct for the common case (1:1 renames). Ambiguous cases (multiple columns with identical expressions) are handled but the pairing is deterministic rather than optimal.

Does this PR introduce a user-facing change?:

Backend-only change. The "renamed" status will be surfaced in the UI in a future Phase 3 PR. No user-visible change yet.

even-wei and others added 2 commits April 8, 2026 19:28
Extend ChangeStatus with "renamed" and add rename_map to NodeChange.
After column comparison in _diff_select_scope(), detect removed+added
column pairs with identical underlying expressions (stripped of alias)
and reclassify them as renames.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: even-wei <evenwei@infuseai.io>
Add RenameDetectionTest class with 12 test cases covering: simple
rename, bare-to-alias, multiple renames, expression change (not rename),
rename + add/remove/modify, no false positives, derived expressions,
and ambiguous greedy matching. Update existing test that now correctly
detects a rename instead of removed+added.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: even-wei <evenwei@infuseai.io>
@even-wei even-wei self-assigned this Apr 8, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
recce/models/types.py 98.03% <100.00%> (+0.01%) ⬆️
recce/util/breaking.py 90.73% <100.00%> (+0.61%) ⬆️
tests/util/test_breaking.py 98.80% <100.00%> (+0.32%) ⬆️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant