Skip to content

[Bug]: FORMAT truncates zero-decimal values and loses the negative sign while rounding #28213

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

#10152 was closed in 2023 and contains only an attached result sheet. The concrete rounding, sign-loss, and decimal-limit behavior below remains on current main.

Branch Name

main

Commit ID

e7bb0572235ec4bac81eb098eb0ad8900f0065ab

Other Environment Information

  • Local standalone MatrixOne; MySQL text protocol
  • Reference: MySQL 8.3.0

Actual Behavior

FORMAT() truncates instead of rounding when D = 0, and loses the minus sign when a fractional value is rounded:

SELECT FORMAT(1.5,0), FORMAT(2.5,0), FORMAT(-1.5,0), FORMAT(-2.5,0);
-- MatrixOne: 1, 2, -1, -2
-- MySQL:    2, 3, -2, -3

SELECT FORMAT(-1.25,1), FORMAT(-1.35,1);
-- MatrixOne: 1.2, 1.4
-- MySQL:    -1.3, -1.4

The decimal-place limit also differs:

SELECT LENGTH(FORMAT(1.5,100));
-- MatrixOne: 102
-- MySQL:    32  (30 fractional digits)

Decimal columns and constants produce the same results; all cases were reproduced three times.

Expected Behavior

FORMAT() must round at every valid D, preserve the sign, and cap D at 30 as MySQL does.

Steps to Reproduce

SELECT FORMAT(1.5,0), FORMAT(2.5,0), FORMAT(-1.5,0), FORMAT(-2.5,0);
SELECT FORMAT(-1.25,1), FORMAT(-1.35,1);
SELECT LENGTH(FORMAT(1.5,100));

Additional information

The formatting routine performs fractional rounding only inside if position > 0; its rounding branch resets the output buffer after the minus sign has already been removed and written; and it does not cap the parsed scale.

Activity

  1. added this to the MO-202609 milestone on Sep 5, 2026
  2. added
    kind/bug
    on Sep 5, 2026
  3. added theissue type on Sep 5, 2026
  4. self-assigned this
    on Sep 5, 2026
  5. added a commit that references this issue on Sep 10, 2026
    1603316
  6. Ariznawlll commented on Sep 10, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:fc621e3616d229c7a29d0c80e73ed8eb1997459c
    • 部署方式:本地单机 1 Log / 1 TN / 1 CN
    • 测试日期:2026-09-10

    原问题验证

    FORMAT(1.5,0)、FORMAT(2.5,0)、FORMAT(-1.5,0)、FORMAT(-2.5,0) 连续 3 次稳定返回 2 / 3 / -2 / -3;FORMAT(-1.25,1)、FORMAT(-1.35,1) 返回 -1.3 / -1.4,负号不再丢失。

    Happy Path 覆盖

    1. DECIMAL 列中的 1.5、-1.5、-1.25、-1.35 按 D=0/1 得到与常量相同的正确结果。
    2. FORMAT(1.5,100) 的结果长度为 32,即整数、分隔符和 30 位小数,正确执行上限保护。

    Unhappy Path 覆盖

    本 issue 的 D=100 是合法边界而非应拒绝输入;已验证其被限制到 30 位小数且查询后数据可继续读取。畸形文本参数的无 panic 覆盖见 #28475。

    白盒验证

    修复 PR matrixone#28508 已合入;pkg/vectorize/format 的定向单测在本地最新 main 上通过。

    回归测试

    已加入 MOTR PR #153:issue_28213_28475_28476_28478_28480_format_compatibility.test。新用例连续 3 次通过,共 90 statements / 90 successes。

    测试证据

    • 本地构建二进制的 Git commit 为 fc621e3616。
    • 回归提交:1cc567ea。

    测试结论

    测试通过。

  7. added 3 commits that reference this issue on Sep 17, 2026
    ef793b0
    79163fe
    7a03d78
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions