Skip to content

fix: parse STR_TO_DATE day and week directives - #29365

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:fix/29331-str-to-date-directives
Sep 24, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:fix/29331-str-to-date-directives

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG

Which issue(s) this PR fixes:

Fixes #29331.

What this PR does / why we need it:

STR_TO_DATE (and its TO_DATE alias) returned NULL for MySQL 8.0 date directives %D, %j, %a/%W, %U/%u/%V/%v, %w, and %X/%x. Parse these directives and resolve day-of-year and week dates after all fields have been read. Week dates take precedence over day-of-year, which takes precedence over a directly parsed month/day. Preserve MySQL's week-year pairing, week 00/53 behavior, literal short week-year, English weekday unique-prefix matching, and year-zero conversion boundary. Date-only format inference now includes these directives.

Validation

  • The eight issue queries returned NULL on the base service; the new service returns the exact eight expected dates.
  • Focused directive tests, the full ./pkg/sql/plan/function package, and planner return-type tests passed through mo-cgo-test with matching native artifacts.
  • go vet -mod=readonly passed for ./pkg/sql/plan/function and ./pkg/sql/plan. Incremental golangci-lint 2.5.0 built with Go 1.26.4 reported 0 issues.
  • The new SQL suite passed normal mo-tester comparison twice against a task-owned standalone service: 16/16 statements each run, zero failed/ignored/abnormal. It covers the eight issue queries, boundaries, invalid combinations, and table rows.
  • The existing func_str_to_date.sql suite passed 115/115 after refreshing two expected results for %X%V %W from NULL to its newly supported date 2004-10-18 (including TO_DATE). The service was shut down afterward.
  • gofmt and git diff --check passed. Independent GPT-6 medium design and final whole-diff review found no remaining blockers.

Risk and rollback

The new calendar resolution is limited to formats containing the newly supported directives. Calendar resolution applies only when ordinal or week fields were parsed. Exhausted repeated directives now preserve prior parsed fields; unsupported dynamic-format behavior remains unchanged. Boundary behavior follows MySQL 8.0.45 parsing semantics; the new unit tests cover precedence, year zero, missing ordinal, ambiguous/overlong weekday names, and malformed week pairs. Revert this commit to restore the previous NULL results.

Follow-up fixes and latest main

Independent MySQL 8.0.44 checks found three additional boundaries in the first PR revision: a leading + counts within the width of a numeric directive, an exhausted repeated %j must preserve the first parsed ordinal, and weekday words use MySQL's Latin1 byte classification. The follow-up commit fixes these at their shared parser boundaries, keeps negative inputs rejected, and adds focused UT and public SQL cases. The revised directive suite passed twice on the rebased binary, 16/16 statements each run. The existing func_str_to_date.sql suite passed 115/115. Full function-package UT, planner return-type UT, go vet, and incremental lint also passed locally.

Rebased onto main containing #29370, which replaces the unauthorized Quay MinIO pulls with verified local image builds. On the pre-rebase head, Compose BVT stopped at that image pull, before executing this SQL. Coverage UT separately timed out after 10 minutes in pkg/tests/issues/isolated (TestSpeedupAbortAllTxn); that is not a date-parser test result. CI for the rebased head should be read from its checks.

No distributed topology or GPU test was run locally; this is scalar date parsing.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

深度审查完成,审查 head:1ce3e7363ed93b07a0951a13f6e6fd07b04b9599,merge-base:44e5226a21。未发现需要阻塞合并的正确性问题,代码层面建议合并。

覆盖全部 8 个变更文件,并沿 SQL 绑定、返回类型选择、日期解析、日历字段归一化及 NULL 输出路径核对。对照 MySQL 8.0.45 官方源码检查了 ordinal/week/direct-date 优先级、四种周编号、week-year 配对、week 00/53、跨年与 year-zero 边界、正号宽度、重复指令和 weekday 前缀;另逐一比对了 256 个字节的 Latin1 字母分类,无差异。实现没有新增共享可变状态、异步任务或外部资源。

目标 issue #29331 的八条原始查询均有明确的 BVT 输入和预期日期,另覆盖无效周组合、NULL/无效表行以及 TO_DATE 别名。已查阅现有执行日志:新增 directive BVT 在同一实例两次正常比较均为 16/16,原有 STR_TO_DATE BVT 为 115/115;函数包及 planner 返回类型测试通过。当前 head 的已启用 CI(包括 Ubuntu UT、ARM64 SCA、Coverage 和两组多 CN BVT)均成功。本次复用这些执行证据,未重复启动 SQL 服务或重跑完整测试。

验证范围为本 PR 的标量日期解析契约;prepared format marker 和 row-dependent format 的其他问题仍属于 #28129、#28566,不由本 PR 的通过结果证明已解决。

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed current head 1ce3e73. No blocking findings. The added directives are recognized by return-type inference and parsed through the existing STR_TO_DATE flow. I traced the precedence and calendar construction for ordinal days, all four week modes, week zero/53, strict week-year pairing, and year-boundary normalization; the unit and SQL regression cases cover these boundaries plus invalid/incomplete combinations. The week-mode mapping agrees with MySQL’s documented %U/%u/%V/%v definitions, and CI is green on this head. This self-authored COMMENT is not an approval.

@XuPeng-SH
XuPeng-SH merged commit bff570f into matrixorigin:main Sep 24, 2026
15 of 20 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/29331-str-to-date-directives branch September 24, 2026 19:02

This branch was previously deployed

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

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Compatibility]: STR_TO_DATE returns NULL for supported day and week format directives

2 participants