Skip to content

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

Closed

Description

@Ariznawlll

Description

The AST nodes for several valid DATA BRANCH statements cannot be restored to SQL. Calling tree.String on the parsed statement panics with implement me.

The affected statements are:

  • DATA BRANCH CREATE TABLE
  • DATA BRANCH DELETE TABLE
  • DATA BRANCH CREATE DATABASE
  • DATA BRANCH DELETE DATABASE
  • DATA BRANCH DIFF
  • DATA BRANCH MERGE

DATA BRANCH PICK implements the same formatter interface and restores successfully.

Environment

  • Branch: main
  • Commit: e15943929885c2c5c83daed90f0f8caeb9a1f0d0
  • Platform: macOS arm64

Reproduction

stmt, err := mysql.ParseOne(
    context.Background(),
    "data branch diff child against parent output count",
    1,
)
if err != nil {
    panic(err)
}

fmt.Println(tree.String(stmt, dialect.MYSQL))

The same result occurs for the other affected statements listed above. The check was repeated three times. As a control, the following statement formats normally:

DATA BRANCH PICK child INTO parent KEYS (1) WHEN CONFLICT SKIP;

Actual result

panic: implement me

The panic comes from the statement's Format implementation in pkg/sql/parsers/tree/data_branch.go. The corresponding TypeName methods are also unimplemented.

Expected result

Every valid data-branch AST should implement the standard formatter contract and restore to equivalent SQL without panicking.

Additional context

The current lifecycle unit tests explicitly expect these formatter calls to panic, so the missing implementations are not detected as failures by the existing suite.

Activity

  1. added this to the MO-202607 milestone on Jul 22, 2026
  2. added
    kind/bug
    on Jul 22, 2026
  3. added theissue type on Jul 22, 2026
  4. added
    severity/s0
    ai-easy
    and removed on Aug 1, 2026
  5. added and removed
    severity/s0
    on Aug 2, 2026
  6. gouhongshen commented on Aug 2, 2026

    @gouhongshen
    Contributor

    fixed

  7. Ariznawlll commented on Aug 4, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:c58cd292d3e6e039a8882654d3b20ad345171e87
    • 部署方式:macOS arm64,本地源码定向 Go 测试
    • 测试日期:2026-08-04

    原问题验证

    对 DATA BRANCH CREATE/DELETE TABLE、CREATE/DELETE DATABASE、DIFF、MERGE 的合法 AST 执行 SQL 格式化和重新解析。原来会触发 panic: implement me 的路径现在均可完成 round-trip,连续执行 3 轮没有 panic。

    Happy Path 覆盖

    1. CREATE/DELETE TABLE 与 CREATE/DELETE DATABASE 均能恢复为等价 SQL。
    2. DIFF 的输出选项和 MERGE 的冲突选项能够正确格式化。
    3. PICK formatter 继续正常工作,作为未回归对照。

    Unhappy Path 覆盖

    1. 不适用:该问题针对已经成功构造的合法 AST 的 formatter contract;非法 SQL 会在 parser 阶段被拒绝,不能进入本问题的 Format 路径。
    2. 所有目标语句连续格式化 3 轮,均未出现 secondary panic。

    白盒验证

    执行:

    go test ./pkg/sql/parsers/tree \
      -run '^(TestDataBranchStatementFormatRoundTrip|TestDataBranchPickFormatRoundTrip|TestDataBranchDiffFormatOutputOptions|TestDataBranchMergeFormatConflictOptions)$' \
      -count=3
    

    结果:ok github.com/matrixorigin/matrixone/pkg/sql/parsers/tree。

    回归测试

    • 修复及回归测试:PR #26560
    • 回归文件:pkg/sql/parsers/tree/data_branch_test.go

    测试证据

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

ai-easykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions