Skip to content

fix(parser): format data branch statements - #26560

Merged
mergify[bot] merged 3 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-26032
Aug 1, 2026
Merged

mergify[bot] merged 3 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-26032

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

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

Which issue(s) this PR fixes:

Closes #26032

What this PR does / why we need it:

Root cause

The parser creates valid AST nodes for DATA BRANCH DELETE TABLE, CREATE DATABASE, DELETE DATABASE, DIFF, and MERGE, but their Format and TypeName methods still panic with implement me. Existing lifecycle tests explicitly expected those panics. CREATE TABLE had been implemented separately on current main after the issue was filed.

DATA BRANCH PICK did not panic, but it was the only formatter outside the shared data-branch formatting scope. Consequently reserved or escaped table identifiers were emitted without safe quoting. Its BETWEEN SNAPSHOT values were also written as raw SQL text, so parsed names containing whitespace or apostrophes produced SQL that ParseOne rejected.

Changes

  • Implement SQL formatting and type names for the five previously unimplemented data-branch statement nodes.
  • Format the complete data-branch family, including PICK, through one shared identifier and string quoting scope.
  • Restore PICK snapshot names as canonical SQL string literals and preserve escaped identifiers.
  • Format every DIFF output form (AS, FILE, LIMIT, COUNT, and SUMMARY), including LIMIT 0 and an empty file literal.
  • Reuse shared string-literal and conflict-option formatters instead of duplicating restoration logic.
  • Replace panic-expecting lifecycle assertions and add parser-format-parser round-trip coverage for all affected statements, PICK escaped identifiers and string snapshots, and option boundaries.
  • Assert reparsed PICK table, snapshot, keys, and conflict-option semantics.

Tests

  • Pre-fix reproduction: TestDataBranchPickFormatRoundTrip failed both reported cases with malformed identifier and raw snapshot output.
  • go build ./pkg/sql/parsers/tree ./pkg/sql/parsers/dialect/mysql
  • go vet ./pkg/sql/parsers/tree ./pkg/sql/parsers/dialect/mysql
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=240s ./pkg/sql/parsers/tree ./pkg/sql/parsers/dialect/mysql
  • Focused deterministic CGo race stress: TestDataBranchPickFormatRoundTrip, TestDataBranchStatementFormatRoundTrip, TestDataBranchPickFormat, and TestDataBranchDiffFormatOutputOptions each passed independently with -race -count=100 (T=0, 30-second adaptive budget, N=100).
  • .agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=300s ./pkg/sql/parsers/tree ./pkg/sql/parsers/dialect/mysql

All verification is against current main (ffad68fdb).

BVT and residual risk

BVT is not applicable because executing a valid data-branch statement does not call the AST formatter; it cannot reproduce this failure. Focused AST and parser round-trip unit tests exercise the failing ownership boundary directly. No residual functional risk is known; the change is limited to SQL restoration and its tests.

@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 →

@gouhongshen

Copy link
Copy Markdown
Contributor Author

Fixed the requested formatter closure in commit 634d70081.

  • DataBranchPick.Format now uses the shared data-branch identifier/string formatting scope.
  • BETWEEN SNAPSHOT names are restored as escaped SQL string literals through the shared literal helper.
  • Added parser-format-parser regressions for reserved/doubled-backtick table names and whitespace/apostrophe snapshot names.
  • The regressions assert reparsed table, snapshot, key, and conflict-option fields, not only AST type or idempotence.

Both reported cases failed before the fix and now pass. The four directly affected tests passed independently with deterministic CGo -race -count=100; both owning packages also pass complete non-race and race suites.

@gouhongshen
gouhongshen requested a review from XuPeng-SH August 1, 2026 13:50
@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/M Denotes a PR that changes [100,499] lines labels Aug 1, 2026

@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.

Re-reviewed current head 634d700818777bcb2e8e9702feeb4a8b3c1df84f.

The previous DATA BRANCH PICK parse → format → parse closure issue is resolved: PICK now uses the shared identifier/string quoting scope, snapshot names are restored as escaped SQL string literals, and the new tests verify reparsed semantic fields. I also reviewed the complete formatter/grammar closure and unhappy paths; no merge-blocking correctness, lifecycle, compatibility, or performance issue remains.

Independent verification passed: build, vet, focused round-trip tests, full owning-package tests in normal and race modes, plus repeated direct race tests.

@mergify

mergify Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-01 14:38 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-08-01 15:22 UTC · at b0874cbb04eb7ff4056f0ad96d2444c81ae25c19 · squash

This pull request spent 43 minutes 22 seconds in the queue, including 42 minutes 21 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86

@mergify
mergify Bot merged commit 9d968c5 into matrixorigin:main Aug 1, 2026
26 of 27 checks passed
@mergify mergify Bot removed the queued label Aug 1, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
### Root cause

The parser creates valid AST nodes for `DATA BRANCH DELETE TABLE`, `CREATE DATABASE`, `DELETE DATABASE`, `DIFF`, and `MERGE`, but their `Format` and `TypeName` methods still panic with `implement me`. Existing lifecycle tests explicitly expected those panics. `CREATE TABLE` had been implemented separately on current `main` after the issue was filed.

`DATA BRANCH PICK` did not panic, but it was the only formatter outside the shared data-branch formatting scope. Consequently reserved or escaped table identifiers were emitted without safe quoting. Its `BETWEEN SNAPSHOT` values were also written as raw SQL text, so parsed names containing whitespace or apostrophes produced SQL that `ParseOne` rejected.

### Changes

- Implement SQL formatting and type names for the five previously unimplemented data-branch statement nodes.
- Format the complete data-branch family, including `PICK`, through one shared identifier and string quoting scope.
- Restore `PICK` snapshot names as canonical SQL string literals and preserve escaped identifiers.
- Format every `DIFF` output form (`AS`, `FILE`, `LIMIT`, `COUNT`, and `SUMMARY`), including `LIMIT 0` and an empty file literal.
- Reuse shared string-literal and conflict-option formatters instead of duplicating restoration logic.
- Replace panic-expecting lifecycle assertions and add parser-format-parser round-trip coverage for all affected statements, `PICK` escaped identifiers and string snapshots, and option boundaries.
- Assert reparsed `PICK` table, snapshot, keys, and conflict-option semantics.

### Tests

- Pre-fix reproduction: `TestDataBranchPickFormatRoundTrip` failed both reported cases with malformed identifier and raw snapshot output.
- `go build ./pkg/sql/parsers/tree ./pkg/sql/parsers/dialect/mysql`
- `go vet ./pkg/sql/parsers/tree ./pkg/sql/parsers/dialect/mysql`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=240s ./pkg/sql/parsers/tree ./pkg/sql/parsers/dialect/mysql`
- Focused deterministic CGo race stress: `TestDataBranchPickFormatRoundTrip`, `TestDataBranchStatementFormatRoundTrip`, `TestDataBranchPickFormat`, and `TestDataBranchDiffFormatOutputOptions` each passed independently with `-race -count=100` (`T=0`, 30-second adaptive budget, `N=100`).
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=300s ./pkg/sql/parsers/tree ./pkg/sql/parsers/dialect/mysql`

All verification is against current `main` (`ffad68fdb`).

### BVT and residual risk

BVT is not applicable because executing a valid data-branch statement does not call the AST formatter; it cannot reproduce this failure. Focused AST and parser round-trip unit tests exercise the failing ownership boundary directly. No residual functional risk is known; the change is limited to SQL restoration and its tests.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
### Root cause

The parser creates valid AST nodes for `DATA BRANCH DELETE TABLE`, `CREATE DATABASE`, `DELETE DATABASE`, `DIFF`, and `MERGE`, but their `Format` and `TypeName` methods still panic with `implement me`. Existing lifecycle tests explicitly expected those panics. `CREATE TABLE` had been implemented separately on current `main` after the issue was filed.

`DATA BRANCH PICK` did not panic, but it was the only formatter outside the shared data-branch formatting scope. Consequently reserved or escaped table identifiers were emitted without safe quoting. Its `BETWEEN SNAPSHOT` values were also written as raw SQL text, so parsed names containing whitespace or apostrophes produced SQL that `ParseOne` rejected.

### Changes

- Implement SQL formatting and type names for the five previously unimplemented data-branch statement nodes.
- Format the complete data-branch family, including `PICK`, through one shared identifier and string quoting scope.
- Restore `PICK` snapshot names as canonical SQL string literals and preserve escaped identifiers.
- Format every `DIFF` output form (`AS`, `FILE`, `LIMIT`, `COUNT`, and `SUMMARY`), including `LIMIT 0` and an empty file literal.
- Reuse shared string-literal and conflict-option formatters instead of duplicating restoration logic.
- Replace panic-expecting lifecycle assertions and add parser-format-parser round-trip coverage for all affected statements, `PICK` escaped identifiers and string snapshots, and option boundaries.
- Assert reparsed `PICK` table, snapshot, keys, and conflict-option semantics.

### Tests

- Pre-fix reproduction: `TestDataBranchPickFormatRoundTrip` failed both reported cases with malformed identifier and raw snapshot output.
- `go build ./pkg/sql/parsers/tree ./pkg/sql/parsers/dialect/mysql`
- `go vet ./pkg/sql/parsers/tree ./pkg/sql/parsers/dialect/mysql`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=240s ./pkg/sql/parsers/tree ./pkg/sql/parsers/dialect/mysql`
- Focused deterministic CGo race stress: `TestDataBranchPickFormatRoundTrip`, `TestDataBranchStatementFormatRoundTrip`, `TestDataBranchPickFormat`, and `TestDataBranchDiffFormatOutputOptions` each passed independently with `-race -count=100` (`T=0`, 30-second adaptive budget, `N=100`).
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=300s ./pkg/sql/parsers/tree ./pkg/sql/parsers/dialect/mysql`

All verification is against current `main` (`ffad68fdb`).

### BVT and residual risk

BVT is not applicable because executing a valid data-branch statement does not call the AST formatter; it cannot reproduce this failure. Focused AST and parser round-trip unit tests exercise the failing ownership boundary directly. No residual functional risk is known; the change is limited to SQL restoration and its tests.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
### Root cause

The parser creates valid AST nodes for `DATA BRANCH DELETE TABLE`, `CREATE DATABASE`, `DELETE DATABASE`, `DIFF`, and `MERGE`, but their `Format` and `TypeName` methods still panic with `implement me`. Existing lifecycle tests explicitly expected those panics. `CREATE TABLE` had been implemented separately on current `main` after the issue was filed.

`DATA BRANCH PICK` did not panic, but it was the only formatter outside the shared data-branch formatting scope. Consequently reserved or escaped table identifiers were emitted without safe quoting. Its `BETWEEN SNAPSHOT` values were also written as raw SQL text, so parsed names containing whitespace or apostrophes produced SQL that `ParseOne` rejected.

### Changes

- Implement SQL formatting and type names for the five previously unimplemented data-branch statement nodes.
- Format the complete data-branch family, including `PICK`, through one shared identifier and string quoting scope.
- Restore `PICK` snapshot names as canonical SQL string literals and preserve escaped identifiers.
- Format every `DIFF` output form (`AS`, `FILE`, `LIMIT`, `COUNT`, and `SUMMARY`), including `LIMIT 0` and an empty file literal.
- Reuse shared string-literal and conflict-option formatters instead of duplicating restoration logic.
- Replace panic-expecting lifecycle assertions and add parser-format-parser round-trip coverage for all affected statements, `PICK` escaped identifiers and string snapshots, and option boundaries.
- Assert reparsed `PICK` table, snapshot, keys, and conflict-option semantics.

### Tests

- Pre-fix reproduction: `TestDataBranchPickFormatRoundTrip` failed both reported cases with malformed identifier and raw snapshot output.
- `go build ./pkg/sql/parsers/tree ./pkg/sql/parsers/dialect/mysql`
- `go vet ./pkg/sql/parsers/tree ./pkg/sql/parsers/dialect/mysql`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=240s ./pkg/sql/parsers/tree ./pkg/sql/parsers/dialect/mysql`
- Focused deterministic CGo race stress: `TestDataBranchPickFormatRoundTrip`, `TestDataBranchStatementFormatRoundTrip`, `TestDataBranchPickFormat`, and `TestDataBranchDiffFormatOutputOptions` each passed independently with `-race -count=100` (`T=0`, 30-second adaptive budget, `N=100`).
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=300s ./pkg/sql/parsers/tree ./pkg/sql/parsers/dialect/mysql`

All verification is against current `main` (`ffad68fdb`).

### BVT and residual risk

BVT is not applicable because executing a valid data-branch statement does not call the AST formatter; it cannot reproduce this failure. Focused AST and parser round-trip unit tests exercise the failing ownership boundary directly. No residual functional risk is known; the change is limited to SQL restoration and its tests.

Approved by: @XuPeng-SH

This branch was previously deployed

1 inactive deployment
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/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: DATA BRANCH AST SQL formatting panics for CREATE, DELETE, DIFF, and MERGE

3 participants