Repository navigation
fix: parse STR_TO_DATE day and week directives - #29365
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
ef2c8f5 to
1ce3e73
Compare
XuPeng-SH
left a comment
There was a problem hiding this comment.
深度审查完成,审查 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
left a comment
There was a problem hiding this comment.
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.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #29331.
What this PR does / why we need it:
STR_TO_DATE(and itsTO_DATEalias) 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
./pkg/sql/plan/functionpackage, and planner return-type tests passed throughmo-cgo-testwith matching native artifacts.go vet -mod=readonlypassed for./pkg/sql/plan/functionand./pkg/sql/plan. Incrementalgolangci-lint2.5.0 built with Go 1.26.4 reported 0 issues.func_str_to_date.sqlsuite passed 115/115 after refreshing two expected results for%X%V %Wfrom NULL to its newly supported date2004-10-18(includingTO_DATE). The service was shut down afterward.gofmtandgit diff --checkpassed. 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%jmust 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 existingfunc_str_to_date.sqlsuite passed 115/115. Full function-package UT, planner return-type UT,go vet, and incremental lint also passed locally.Rebased onto
maincontaining #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 inpkg/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.