Skip to content

fix(data branch): use lineage mapping for diff output tables - #32971

Merged
mergify[bot] merged 3 commits into
matrixorigin:mainfrom
VioletQwQ-0:fix/data-branch-output-as-altered-columns
Nov 21, 2026
Merged

mergify[bot] merged 3 commits into
matrixorigin:mainfrom
VioletQwQ-0:fix/data-branch-output-as-altered-columns

Conversation

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #32969

What this PR does / why we need it:

Summary

Fixes DATA BRANCH DIFF ... OUTPUT AS schema evolution / column lineage resolution bugs and fixes related column mapping, row ordering, TIMESTAMP formatting, DECIMAL attribute, and Unicode case-fold edge cases.

Root Cause & Changes

  1. Lineage-mapped OUTPUT AS DDL & base history projection (pkg/frontend/data_branch.go, pkg/frontend/data_branch_hashdiff.go, pkg/frontend/data_branch_output.go):
    • Updated reconcileDataBranchEndpointSchema to index target data columns positionally (tarDataIdx skipping catalog.Row_ID), populate lcaColNames, baseColNames, and baseColToTarIdx accurately across altered/renamed/reordered schemas, and keep dataBranchIndexedSpecialUpdateColIdxes consistent via commonutil.EqualFoldKey.
    • Added excludeTargetOnly in dataBranchSourceColToTargetIdx so base-side historical batches exclude target-only slots instead of leaking or failing type checks across COPY ALTER.
    • Updated diffOutputTable.createSQL / materializeDiffOutputAsTable to resolve target-only and renamed common columns from endpoint definitions cleanly, and preserved sels reordering in runLCAProbeWithReaderFallback even when len(missedRows) == 0.
  2. Type attributes & Unicode case-fold consistency (pkg/frontend/data_branch.go, pkg/frontend/data_branch_output.go):
    • Added NumericAttributes checks to dataBranchColumnTypeAttributesEqual and isDataBranchLogicalTypeEquivalent (catching DECIMAL UNSIGNED/ZEROFILL mismatches).
    • Used commonutil.EqualFoldKey consistently across checkSchemaCompatibilityWithResolver, dataBranchLineageEndpointColumns duplicate visible-target checks, resolveProjectedIdxes, newDiffOutputTable, nextAvailableDiffOutputColumnName, and dataBranchIndexedSpecialUpdateColIdxes, explicitly rejecting fold-equivalent visible columns (e.g. s vs ſ) and deduplicating output metadata columns against __mo_diff_source/__mo_diff_flag while preserving lowercase map keys in dataBranchLineageEndpointColumns for existing callers.
  3. TIMESTAMP DST fold & extreme-offset OUTPUT AS materialization (pkg/frontend/data_branch_output.go):
    • Batched OUTPUT AS TIMESTAMP literals with sticky per-row negative fixed offsets (-rowOffsetHours) to preserve DST fall-back fold instants (e.g., America/New_York), 1970-01-01 minimum storable instants under positive offsets, and year-9999 values that would otherwise overflow UTC.
  4. Tests (pkg/frontend/data_branch_hashdiff_test.go, pkg/frontend/data_branch_output_test.go, test/distributed/cases/git4data/branch/diff/diff_output_as_altered_columns.{sql,result}):
    • Added unit and BVT coverage for altered/renamed/COPY ALTER columns, historical base DROP COLUMN, runLCAProbeWithReaderFallback sels ordering, DST fold / min-max TIMESTAMP batching, DECIMAL UNSIGNED, and Unicode fold (s/ſ/__mo_diff_ſource) edge cases.

Non-Goals / Deferred (Pre-Existing Out-of-Scope)

  • Pre-existing historical COPY ALTER slot collision on non-target-only columns (data_branch_hashdiff.go:3217) and pre-existing CTAS bypass of validateUniquePersistedTableColumns (pkg/sql/plan/build_ddl.go:3474) are baseline behaviors untouched by this PR.

QA Decision

  • QA required: yes (SQL-visible DATA BRANCH DIFF ... OUTPUT AS schema evolution, type compatibility, and timestamp behavior fix; adds BVT suite test/distributed/cases/git4data/branch/diff/diff_output_as_altered_columns.sql).

Verification (Exact Final HEAD 6f357bbcdb9c3e9e881db12a6a975e325ef59d9b)

  • Unit Tests: .agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=10m -run 'Test.*DataBranch|TestMaterializeDiffOutputAsTable|TestDiffOutputTable|TestLCAProbe|TestRunLCAProbe|TestCheckSchemaCompatibility|TestValidateDataBranch' ./pkg/frontend -> 404/404 PASS (160 top-level + 244 subtests, 0 failed, 0 skipped; TestValidateDataBranch* 6/6, TestCheckSchemaCompatibility* 22/22).
  • Binary: make build-with-prebuilt-native -> vcs.revision=6f357bbcdb9c3e9e881db12a6a975e325ef59d9b, vcs.modified=false, SHA-256 a669585282cfcb7fe765045c79b27d4cbd55f0213e2afefd3d3ac9c88a404ad7 verified before and after BVT.
  • Static Check: make static-check-selected STATIC_CHECK_PACKAGES=./pkg/frontend GOLANGCI_LINT_CONCURRENCY=4 -> 0 issues..
  • BVT:
    • bvt-r10-final/output: focused 131/131 (100%), regressions (3 scripts: diff_17, diff_output_as_altered_columns, diff_schema_evolve) 563/563 (100%).
    • bvt-r10-final/regressions: focused 131/131 (100%), regressions (55 scripts) 4457/4457 (100%).

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify mergify Bot added the kind/bug Something isn't working label Nov 20, 2026
@mergify

mergify Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@XuPeng-SH

XuPeng-SH commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: dc1dc9e637970be0ced7bb9c6a546d97a4bd0a84

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

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.

mo-bot review · mo-bot-local · review

Commit: dc1dc9e637970be0ced7bb9c6a546d97a4bd0a84

Assessment: approve

The output table now uses the reconciled column mapping, preserves target column order, and writes NULL for target-only fields on base rows. Fallback reads preserve the input key order, and fixed-offset inserts preserve timestamp instants across DST folds and the year-9999 boundary.

Model: gpt-6.2-sol / xhigh

Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3

Validation:

  • Verified the frozen checkout, patch, and git diff --check. Private /tmp and loopback preflight passed. Native build inputs matched the retained build ledger.

  • All 404 selected frontend tests and subtests passed, including all-hit row ordering, historical projection, Unicode name handling, decimal attributes, timestamp round-trips, and cleanup after insert failure. See frontend-tests-retry.log and checks/1795243073638998415-3.json.

  • A two-CN embedded MySQL probe verified persisted values after COPY ALTER, both DST-fold instants, a timestamp beyond UTC year 9999, session time-zone preservation, and rejection of incompatible decimal attributes before table creation. See public-sql.log and checks/1795243142135552921-3.json.

  • Frozen CI reports successful Ubuntu unit tests and both BVT jobs. The repository selector assigns the changed SQL case to BVT group 1.

Limitations:

  • The local public SQL check covered focused scenarios. Detailed author BVT counts apply to pre-merge revision 6f357bb, and the frozen CI evidence provides job-level status.

@mergify mergify Bot added the queued label Nov 21, 2026
@mergify

mergify Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into main as a9dda36 at 07:49 UTC

1 h 9 min in the queue, 1 h 8 min of it CI.

So far

  • ✅ Entered the queue Sat 21 Nov, 06:40 · rule main · triggered by rule Automatic queue on approval for main
  • ✅ Passed · in place
  • ✅ Merged 07:49 · a9dda36 · squash
3 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection
  • any of · required by GitHub branch protection:
    • check-success = CI Required
    • check-neutral = CI Required
    • check-skipped = CI Required

Times in UTC · dashboard · how the merge queue works

@mergify
mergify Bot merged commit a9dda36 into matrixorigin:main Nov 21, 2026
@mergify mergify Bot removed the queued label Nov 21, 2026
mergify Bot pushed a commit that referenced this pull request Nov 26, 2026
## What type of PR is this?

- [x] BUG

## Which issue(s) this PR fixes:

issue #32003

## What this PR does / why we need it:

An unconditional DELETE can use the same physical table replacement path as TRUNCATE. Data Branch previously recorded that replacement as row-preserving ALTER lineage. Subsequent DIFF and PICK could retain changes from the cleared generation without seeing the implied deletions. In the reported sequence, PICK returned success without restoring the requested row.

Record clear boundaries in existing branch lineage metadata and reconstruct changes against the appropriate comparison snapshot. Keep COPY ALTER row-preserving; do not infer clear boundaries retroactively from legacy ALTER records or missing history.

- Apply both halves of a mixed PICK batch: restore independently deleted keys and still update the surviving keys.
- In bounded PICK across a clear, limit insert/update columns to the source layout at the upper snapshot. Preserve destination values for later columns on UPDATE and use destination defaults on INSERT.
- Reject matching-row comparisons when a shared column's historical introduction value cannot be reconstructed, rather than silently treating it as unchanged.

Validation on `f42550e540b` (base `dc204213996`, including #32970 and #32971):

- All three review cases reproduced on `8734ac51866` and were added to `test/distributed/cases/git4data/branch/merge/merge_issue_32003.sql`.
- 295 focused unit tests and embedded SQL `TestDataBranchAfterTableClear` / `TestDataBranchClearBoundaryAfterGC` passed.
- Exact-head local BVT: 385/385 statements, no skips. This covers `merge_issue_32003`, `branch_rebuild_lifecycle`, `diff_older_ancestor_snapshot` and `diff_output_as_altered_columns`.

Validation on `ee35455eb5a`:

- The bounded PICK hydration regression checks both an upper snapshot before the ALTER and one at the ALTER. Both assert that the upper-snapshot relation supplies the renamed and newly added column values, while preserving the row ID and commit timestamp. Six related frontend tests passed in three consecutive local runs.
- The previously failing Ubuntu unit and coverage jobs on `5f5b752c299` both stopped at the stale upper-snapshot mock expectation. CI for the new head is tracked separately.

QA required: yes. The fix changes persisted lineage interpretation and SQL-visible Data Branch behavior. Local SQL verifies final rows and error outcomes, including restart/GC coverage. Multi-CN/Proxy on the PR head remains pending.



Approved-by: XuPeng-SH <[email protected]>
@VioletQwQ-0
VioletQwQ-0 deleted the fix/data-branch-output-as-altered-columns branch December 1, 2026 03:47

This branch was previously deployed

1 inactive deployment
ci — 691c13de Deployed Nov 21, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants