Skip to content

[Bug]: WEEK(date, mode) two-argument form rejected with 'bad value [DATE BIGINT]' #24236

Closed

Description

@dengn

Branch Name

main (v3.0.9 release tag)

Commit ID

39cfa47

Other Environment Information

  • Hardware parameters: n/a (release build)
  • OS type: n/a
  • Others: discovered via NL2SQL workload generating standard MySQL syntax

Actual Behavior

Calling WEEK(date, mode) with the standard 2-argument form fails at runtime with an "invalid argument" error reporting the type combination [DATE BIGINT] is not accepted.

ERROR 20203 (HY000): invalid argument function week, bad value [DATE BIGINT]

Expected Behavior

MySQL WEEK(date, mode) is a standard 2-argument function where:

  • date is a DATE / DATETIME
  • mode is an integer 0..7 controlling the week-numbering semantics (whether week starts on Sunday/Monday, whether it's an ISO week, etc.)

It should accept an integer literal (parsed as BIGINT) for the mode argument and either auto-cast to the expected smaller integer type or document/permit the BIGINT path.

Reference: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_week

Steps to Reproduce

-- 1-arg form works:
SELECT WEEK(CURRENT_DATE);

-- 2-arg form fails with error 20203:
SELECT WEEK(CURRENT_DATE, 3);
SELECT WEEK(CURRENT_DATE, 0);
SELECT WEEK('2026-04-20', 3);

Additional information

The error string bad value [DATE BIGINT] suggests MatrixOne's WEEK only registers a signature for one argument type (or for (DATE, smaller-int)) and the integer literal 3 is being typed as BIGINT without an implicit conversion path.

Suggested fix paths:

  1. Register a WEEK(DATE, INT64) signature; or
  2. Add an implicit BIGINT → smaller-int cast for mode; or
  3. Treat literal integers in this argument position as a constrained type.

This is one of three related issues filed from the same NL2SQL session that produced typical "this week vs last week" SQL. The other two are:

  • YEARWEEK function not supported (preferred cleanest form)
  • Parser error on arithmetic expression inside INTERVAL clause (fallback path also broken)

The combined effect is that agents (and human users) writing standard MySQL week-aligned comparisons have no working idiom available in v3.0.9.

Activity

  1. added 2 commits that reference this issue on Apr 28, 2026
    bf93e18
    6d5c216
  2. added a commit that references this issue on May 6, 2026
    59fe939
  3. Ariznawlll commented on May 7, 2026

    @Ariznawlll
    Collaborator

    验证结果

    已验证 WEEK(date, mode) 双参数形式在当前 main 分支上可正常工作,所有 mode 0~7 结果与 MySQL 完全对齐。

    测试环境

    • MO: mysql -h 127.0.0.1 -P 6001 -udump -p111
    • MySQL: mysql -u root -pweilu0220

    验证内容

    SELECT WEEK('2026-05-07', 0);  -- 18 ✅
    SELECT WEEK('2026-05-07', 1);  -- 19 ✅
    SELECT WEEK('2026-05-07', 2);  -- 18 ✅
    SELECT WEEK('2026-05-07', 3);  -- 19 ✅
    SELECT WEEK('2026-05-07', 4);  -- 18 ✅
    SELECT WEEK('2026-05-07', 5);  -- 18 ✅
    SELECT WEEK('2026-05-07', 6);  -- 18 ✅
    SELECT WEEK('2026-05-07', 7);  -- 18 ✅
    
    -- BIGINT mode (原始 issue 场景)
    SELECT WEEK('2026-05-07', CAST(3 AS SIGNED));   -- 19 ✅
    SELECT WEEK('2026-05-07', CAST(3 AS UNSIGNED)); -- 19 ✅
    
    -- 年份边界
    SELECT WEEK('2024-01-01', 0), WEEK('2024-01-01', 1), WEEK('2024-01-01', 3); -- 0, 1, 1 ✅
    SELECT WEEK('2024-12-31', 0), WEEK('2024-12-31', 1), WEEK('2024-12-31', 3); -- 52, 53, 1 ✅
    SELECT WEEK('2023-01-01', 0), WEEK('2023-01-01', 1), WEEK('2023-01-01', 3); -- 1, 0, 52 ✅
    SELECT WEEK('2020-12-31', 1), WEEK('2020-12-31', 3); -- 53, 53 ✅
    
    -- NULL / DATETIME / CAST
    SELECT WEEK(NULL, 3);  -- NULL ✅
    SELECT WEEK('2026-01-01 12:00:00', 3); -- 1 ✅
    SELECT WEEK(CAST('2026-05-07' AS DATE), 3); -- 19 ✅

    所有结果与 MySQL 一致。已提交 BVT case(93 条用例,100% 通过):

    • test/distributed/cases/function/func_datetime_week.test

    遗留问题

    WEEK(date) 单参数形式未正确读取 @@default_week_format(MO 返回 19 即 mode=1 行为,MySQL 返回 18 即 mode=0),已单独提 issue。

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions