Skip to content

fix(diff): cast daterange and rerun row fetches to text so repairs work#143

Open
mason-sharp wants to merge 1 commit into
mainfrom
fix/ACE-202/types-again
Open

fix(diff): cast daterange and rerun row fetches to text so repairs work#143
mason-sharp wants to merge 1 commit into
mainfrom
fix/ACE-202/types-again

Conversation

@mason-sharp

Copy link
Copy Markdown
Member

IsKnownScalarType matched format_type names by prefix, so "daterange" passed as "date" and was the one complex type still fetched un-cast -- its Go-struct form in the diff report failed the whole upsert batch on repair (malformed range literal). Strip the typmod and require an exact match, which also covers datemultirange and UDTs sharing a scalar's prefix.

table-rerun's row fetch never applied the cast policy at all; it now consults the same NeedsTextCast so rerun reports stay repairable.

The typed-columns integration test gains a daterange column and a rerun leg; the cast-policy decision table covers the collision cases.

IsKnownScalarType matched format_type names by prefix, so "daterange"
passed as "date" and was the one complex type still fetched un-cast --
its Go-struct form in the diff report failed the whole upsert batch on
repair (malformed range literal). Strip the typmod and require an exact
match, which also covers datemultirange and UDTs sharing a scalar's
prefix.

table-rerun's row fetch never applied the cast policy at all; it now
consults the same NeedsTextCast so rerun reports stay repairable.

The typed-columns integration test gains a daterange column and a rerun
leg; the cast-policy decision table covers the collision cases.
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e06c7041-b86d-477f-96b2-2fb43c4aaeae

📥 Commits

Reviewing files that changed from the base of the PR and between beecb35 and ed1dcad.

📒 Files selected for processing (4)
  • internal/consistency/diff/table_rerun.go
  • pkg/common/utils.go
  • pkg/common/utils_test.go
  • tests/integration/mtree_typed_repair_test.go

📝 Walkthrough

Walkthrough

Introduces a NeedsTextCast helper function that centralizes logic for determining when column values must be cast to TEXT in diff SELECT expressions, based on rewritten scalar-type detection. This is wired into the table rerun fetch query, covered by unit tests, and validated in integration tests via a new daterange column and rerun-mode diff assertion.

Changes

Type-Aware TEXT Casting for Diff Rerun

Layer / File(s) Summary
NeedsTextCast helper and scalar detection
pkg/common/utils.go, pkg/common/utils_test.go
Adds exported NeedsTextCast(colType string) bool centralizing cast policy for arrays, json/jsonb, bytea, and unknown types; rewrites IsKnownScalarType with typmod stripping and exact-match switch logic; SelectColExpr delegates to the new helper; test table extended with new type cases.
Rerun fetch query casting
internal/consistency/diff/table_rerun.go
fetchRowsByPkeys retrieves per-column PostgreSQL types via queries.GetColumnTypes and conditionally selects columns as t.<col>::TEXT versus raw t.<col> based on NeedsTextCast.
Integration test coverage for daterange and rerun
tests/integration/mtree_typed_repair_test.go
Adds a col_daterange column to typed repair DDL and seed data with generated daterange(...) values, and adds a rerun diff task assertion verifying no rerun diff reports are produced after convergence.

Poem

A rabbit hopped through columns wide,
TEXT-casting rules now codified,
Ranges of dates, jsonb, and byte,
All checked and cast just right! 🐇
Rerun the diff, converge with glee —
No leftover reports for me!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: fixing diff repair handling by casting complex types and rerun fetches to text.
Description check ✅ Passed The description accurately explains the scalar-type fix, rerun cast policy reuse, and the related test coverage changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ACE-202/types-again

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@mason-sharp mason-sharp requested a review from rasifr July 9, 2026 22:23
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.

2 participants