Skip to content

[Bug]: DATE/DATETIME numeric casts use epoch values instead of MySQL packed temporal numbers #25263

Closed

Description

@Ariznawlll

Bug Report

MatrixOne Version

Latest origin/main verified locally at 33e96877604ad4b847ea7d5c55eb09429de1a5b6.

Reproduce Steps

set time_zone = '+00:00';

select cast(cast('2024-01-02' as date) as signed),
       cast(cast('2024-01-02' as date) as decimal(20,0)),
       cast('2024-01-02' as date) + 0;

select cast(cast('2024-01-02 03:04:05.123456' as datetime(6)) as signed),
       cast(cast('2024-01-02 03:04:05.123456' as datetime(6)) as decimal(20,6)),
       cast('2024-01-02 03:04:05.123456' as datetime(6)) + 0;

Expected Behavior

MySQL returns packed temporal numeric values:

20240102    20240102    20240102
20240102030405    20240102030405.123456    20240102030405.123456

Actual Behavior

MatrixOne uses epoch-style values for DATE / DATETIME, and DATE -> DECIMAL errors:

select cast(cast('2024-01-02' as date) as signed);        -- 19724
select cast(cast('2024-01-02' as date) as decimal(20,0)); -- ERROR 20203: invalid argument operator cast, bad value [DATE DECIMAL128]
select cast('2024-01-02' as date) + 0;                    -- 19724

select cast(cast('2024-01-02 03:04:05.123456' as datetime(6)) as signed);        -- 1704164645
select cast(cast('2024-01-02 03:04:05.123456' as datetime(6)) as decimal(20,6)); -- 1704164645.123456
select cast('2024-01-02 03:04:05.123456' as datetime(6)) + 0;                    -- 1704164645.123456

TIME -> numeric was checked separately and matches MySQL:

select cast(cast('03:04:05.123456' as time(6)) as signed),
       cast(cast('03:04:05.123456' as time(6)) as decimal(20,6)),
       cast('03:04:05.123456' as time(6)) + 0;

Both MySQL and MatrixOne return:

30405    30405.123456    30405.123456

Notes

Found during Batch A of the MySQL compatibility type-conversion exploration. Existing TimeToInt.sql covers temporal-to-numeric behavior broadly, so no duplicate passing BVT was added for the matching TIME rows; the differing DATE/DATETIME rows were excluded from BVT.

Activity

  1. added
    kind/bug
    severity/s1
    on Jun 30, 2026
  2. added this to the MO-202607 milestone on Jul 1, 2026
  3. added theissue type on Jul 1, 2026
  4. added
    ai-medium
    on Jul 1, 2026
  5. added
    ai-light
    and removed
    ai-medium
    on Jul 10, 2026
  6. added a commit that references this issue on Jul 15, 2026
  7. added a commit that references this issue on Jul 24, 2026
  8. daviszhen commented on Jul 30, 2026

    @daviszhen
    Contributor

    fixed

  9. Ariznawlll commented on Jul 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main(截至 2026-07-30 16:30,Asia/Shanghai)
    • commit:41332062a6740978f269088a92ee362a888c7bd7
    • 部署方式:从该官方 commit 源码构建;etc/launch-with-proxy/launch.toml(2 CN + 1 TN + Proxy),SQL 入口 127.0.0.1:6001
    • 测试日期:2026-07-30

    原问题验证

    DATE/DATETIME 转 SIGNED、DECIMAL 和 +0 均返回 MySQL packed temporal number:DATE 为 20240102,DATETIME(6) 为 20240102030405.123456;完整黑盒 3/3 通过。

    Happy Path 覆盖

    1. leap day 2000-02-29 转为 20000229。
    2. 上界 9999-12-31 23:59:59.999999 保留完整 packed 值和微秒。
    3. TIME 对照仍返回 30405/30405.123456,未被 DATE/DATETIME 修复破坏。

    Unhappy Path 覆盖

    1. NULL DATE/DATETIME 转数值保持 NULL。
    2. 非法字符串 not-a-date 转 DATE 返回 NULL,后续 SELECT 1 正常。

    白盒验证

    temporal cast/binder 定向测试通过;最终 SQL 和额外非法输入输出均已保存为证据。

    回归测试

    修复提交 5c3243d2f 已扩展 temporal predicate、zero temporal、load-data 与函数 BVT/UT。

    测试证据

    完整 3 轮 SQL 结果、测试脚本、Proxy 黑盒日志、定向 UT 与 -race 输出:https://gist.github.com/Ariznawlll/b8f1a22642a58fd5264482687534728b

    测试结论

    测试通过。

  10. Ariznawlll commented on Jul 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    motr 黑盒回归已补充

    • PR:matrixorigin/motr#72
    • 用例:suites/14_issue_regression/t/issue_25263_temporal_numeric_cast.test
    • 覆盖:DATE/DATETIME packed 数字转换含微秒/闰日/最大值;非法日期为 NULL 且会话可继续使用
    • 本地验证:基于 MatrixOne main@41332062a6740978f269088a92ee362a888c7bd7,该批 14 个用例连续 3 轮为 42/42 成功(504/504 语句);完整 14_issue_regression suite 为 124 成功、0 失败。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-lightkind/bugseverity/s1

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions