Skip to content

[Compatibility]: TIME_FORMAT emits specifier letters for missing date fields #28567

Closed

Description

@Ariznawlll

现象

MatrixOne main(ac660ae56ecd37bab3dd8c61193617a323377029)的 TIME_FORMAT() 对日期类 format specifier 直接去掉 % 并输出字母,和 MySQL 的零日期/NULL 语义不同。

SELECT TIME_FORMAT(CAST('12:34:56.123456' AS TIME(6)),
                   '%Y-%m-%d %H:%i:%s.%f');
SELECT TIME_FORMAT(CAST('12:34:56.123456' AS TIME(6)), '%W');
SELECT TIME_FORMAT(CAST('12:34:56.123456' AS TIME(6)), '%M');
SELECT TIME_FORMAT(CAST('12:34:56.123456' AS TIME(6)), '%X-%V');

MatrixOne:

Y-m-d 12:34:56.123456
W
M
X-V

MySQL 8.0.46:

0000-00-00 12:34:56.123456
NULL
NULL
NULL

%Y、%m、%d 在 MySQL 中分别得到 0000、00、00,MatrixOne 则分别得到 Y、m、d。时间类 %H:%i:%s.%f、%% 和未知 %q 控制组在两端一致。

期望

TIME_FORMAT() 应按 MySQL 语义处理缺失的日期部分:数值日期字段输出零值,需要日期名称或周历上下文的字段返回 NULL;不能将 format specifier 的字母误当成普通文本。

代码定位

pkg/sql/plan/function/func_binary.go 的 makeTimeFormat 仅实现时间类 specifier;default 分支直接执行 buf.WriteRune(b)。代码注释认为这与 MySQL 的“忽略非时间 specifier”行为一致,但 MySQL 实际会对数字日期字段输出零值,并对日期名称/周历字段返回 NULL。

复现信息

  • MatrixOne main:ac660ae56ecd37bab3dd8c61193617a323377029
  • MySQL:8.0.46
  • 代表性 specifier 和控制组重复执行 3 次,结果一致

Activity

  1. added this to the MO-202609 milestone on Sep 10, 2026
  2. added theissue type on Sep 10, 2026
  3. XuPeng-SH commented on Sep 10, 2026

    @XuPeng-SH
    Contributor

    Triage routing: assigned to @jiangxinmeng1. Labels normalized to kind/bug + needs-triage (existing compatibility labels, when present, are retained).

    Recommended PR decomposition:

    • PR-T2 — temporal formatting/localization (#28567 + #28597): correct missing-date format specifiers and make lc_time_names affect localized date functions. They share formatting/rendering and locale semantics.
    • Keep #28566 separate because row-dependent format expressions require a planner/constness and vectorized-execution change; keep EXTRACT, TIMESTAMPDIFF, DST, and TIMESTAMP default semantics separate.

    Suggested priority: P2 for #28567; P3 for #28597 unless a supported locale compatibility workload makes it urgent.

  4. XuPeng-SH commented on Sep 27, 2026

    @XuPeng-SH
    Contributor

    QA handoff after merged PR #28851 (merge a99db843c7b4630a86883addc9424433d93fc2d2). This issue was a non-closing related report; the merge and shared BVT counts are not an independent PASS for this reproducer.

    Latest MatrixOne contract: C24 in the merged temporal design. TIME_FORMAT uses duration-aware clock fields; numeric date directives use the zero calendar, while calendar names and week/year directives without a meaningful TIME value return NULL. It must not substitute today’s date or emit raw directive letters for known directives.

    Please rerun the original reproducer on main at or after the merge and record the exact SHA, deployment, SQL mode/time zone, client path, observed rows/types/NULLs and active warnings or errors. Rerun every original format, plus negative/>24-hour TIME, unknown directives, NULL and empty format controls.

    Keep the issue open until the issue-specific acceptance is demonstrated with happy and unhappy controls. If any part still fails, post the exact observed-versus-expected result and return it to development; if it passes, record evidence and close the issue. @Ariznawlll

  5. Ariznawlll commented on Oct 2, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • Commit:d50a2d475a406829f67127fef7b2ad4abc1c1d3d
    • 部署方式:本地全新单 CN mo-service,独立数据目录;MySQL 文本协议与 server-side PREPARE
    • 测试日期:2026-10-02

    原问题验证

    按 issue 原始语义在上述 commit 重新执行并重复 3 次。缺失年月日字段按 contract 生成 partial/zero calendar;名称类函数对不可完整解释值返回 NULL。

    Happy Path 覆盖

    覆盖仅年、年月、仅时间及完整日期输入。

    Unhappy Path 覆盖

    覆盖 malformed、partial-zero、NULL 以及名称提取;无内部错误。

    白盒验证

    关联修复 #28851 已进入当前 main。同时将本 issue 的可公开观察契约固化为独立回归,避免只依赖实现细节或共享测试间接判断。

    回归测试

    测试证据

    • 精确测试版本:d50a2d475a406829f67127fef7b2ad4abc1c1d3d
    • 当前结果:缺失年月日字段按 contract 生成 partial/zero calendar;名称类函数对不可完整解释值返回 NULL。
    • 回归代码与 golden result 已提交到 MOTR #209;本地全量 14_issue_regression 中观察到的旧 GOROOT/历史 golden/并发锁冲突属于既有无关失败,以上新增用例单独重跑均稳定通过。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

area/compatibilitykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions