Skip to content

fix(mtree): fetch complex-typed columns as text so their diffs repair#139

Open
danolivo wants to merge 1 commit into
fix/ACE-201/typed-repairfrom
fix/ACE-202/complex-types-repair
Open

fix(mtree): fetch complex-typed columns as text so their diffs repair#139
danolivo wants to merge 1 commit into
fix/ACE-201/typed-repairfrom
fix/ACE-202/complex-types-repair

Conversation

@danolivo

@danolivo danolivo commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

table-repair aborted on tables with geometric, network, range, bit, enum or xml columns when the diff came from the Merkle-tree engine: one unparseable value fails the whole upsert batch, so nothing gets repaired. The classic engine was largely unaffected because its row fetch already casts arrays, json, bytea and any non-known-scalar type to ::TEXT, so those values travel as Postgres' own text form and parse straight back on repair. The mtree engine's row fetch used a bare SELECT *, so the same columns arrived as opaque pgx driver structs and reached the report as Go-formatted garbage -- a JSON-quoted "(61,122)" for point, {54 154 i e true} for a range, base64 for xml.

Extract the classic engine's cast policy into a shared helper, SelectColExpr, and build both engines' row-fetch SELECT lists with it. The mtree fetch now names its columns explicitly with the same ::TEXT casts, so diff reports carry identical, repairable text on both engines for every type, with no per-type conversion code to maintain.

Since text pass-through is now the designed repair path for such types, the per-value "unknown or complex pgType" warning (one line per row per column, thousands in a modest repair) is demoted to a debug message; the fallbacks for non-string values, which do indicate a value that bypassed normalisation, still warn.

Unit tests cover the cast-policy decision table; the typed-columns integration test now also spans point, int4range, bit, inet, xml and a real enum type, asserting the Merkle-tree diff of 100 divergent rows repairs completely and converges the nodes.

table-repair aborted on tables with geometric, network, range, bit, enum or
xml columns when the diff came from the Merkle-tree engine: one unparseable
value fails the whole upsert batch, so nothing gets repaired. The classic
engine was largely unaffected because its row fetch already casts arrays,
json, bytea and any non-known-scalar type to ::TEXT, so those values travel
as Postgres' own text form and parse straight back on repair. The mtree
engine's row fetch used a bare SELECT *, so the same columns arrived as
opaque pgx driver structs and reached the report as Go-formatted garbage --
a JSON-quoted "(61,122)" for point, {54 154 i e true} for a range, base64
for xml.

Extract the classic engine's cast policy into a shared helper,
SelectColExpr, and build both engines' row-fetch SELECT lists with it. The
mtree fetch now names its columns explicitly with the same ::TEXT casts, so
diff reports carry identical, repairable text on both engines for every
type, with no per-type conversion code to maintain.

Since text pass-through is now the designed repair path for such types, the
per-value "unknown or complex pgType" warning (one line per row per column,
thousands in a modest repair) is demoted to a debug message; the fallbacks
for non-string values, which do indicate a value that bypassed
normalisation, still warn.

Unit tests cover the cast-policy decision table; the typed-columns
integration test now also spans point, int4range, bit, inet, xml and a real
enum type, asserting the Merkle-tree diff of 100 divergent rows repairs
completely and converges the nodes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 73424bc3-03d6-4728-8689-66b7f4e1e5a9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ACE-202/complex-types-repair

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 7 complexity · 0 duplication

Metric Results
Complexity 7
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.

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