fix: support YEARWEEK function (Fixes #24234)#24238
Open
LeftHandCold wants to merge 4 commits intomatrixorigin:3.0-devfrom
Open
fix: support YEARWEEK function (Fixes #24234)#24238LeftHandCold wants to merge 4 commits intomatrixorigin:3.0-devfrom
LeftHandCold wants to merge 4 commits intomatrixorigin:3.0-devfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds MySQL-compatibility surface area around date/time, JSON, comparison operators, and DDL planning/execution—most notably implementing YEARWEEK(date[, mode]) on 3.0-dev and extending support for several MySQL idioms that were previously rejected.
Changes:
- Add
YEARWEEK()function (date/datetime/timestamp; optional mode) and register new function IDs/operators. - Add support for MySQL JSON operators
->/->>and the null-safe equality operator<=>(binder + function execution). - Implement multi-table
DROP TABLEplanning/execution (including FK-related handling), plus expand JSON casting/comparison behavior and related tests.
Reviewed changes
Copilot reviewed 32 out of 34 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/distributed/cases/join/apply.result | Updates expected output for JSON numeric comparison in APPLY/UNNEST scenario. |
| test/distributed/cases/function/func_null_safe_equal.sql | Adds distributed SQL coverage for <=> semantics across types/tuples. |
| test/distributed/cases/function/func_null_safe_equal.result | Expected results for new <=> distributed test case. |
| test/distributed/cases/function/func_json_arrow.sql | Adds distributed SQL coverage for JSON -> / ->> operators. |
| test/distributed/cases/function/func_json_arrow.result | Expected results for JSON arrow operator distributed test case. |
| test/distributed/cases/ddl/drop_table_multiple.sql | Adds distributed SQL coverage for multi-table DROP TABLE. |
| test/distributed/cases/ddl/drop_table_multiple.result | Expected results for multi-table DROP TABLE distributed test case. |
| proto/plan.proto | Extends DropTable protobuf to carry per-target entries for multi-table drop. |
| pkg/sql/plan/function/list_operator.go | Registers <=> as a supported comparison operator with type-checking/casting. |
| pkg/sql/plan/function/list_builtIn.go | Registers YEARWEEK() built-in overloads. |
| pkg/sql/plan/function/init.go | Adds name/encoded-id constants for <=>. |
| pkg/sql/plan/function/function_id_test.go | Updates fixed function-id map (but currently missing YEARWEEK). |
| pkg/sql/plan/function/function_id.go | Adds function IDs for <=> and YEARWEEK, registers names. |
| pkg/sql/plan/function/func_compare_test.go | Adds unit tests for mixed-type numeric comparisons and <=> behavior. |
| pkg/sql/plan/function/func_compare_fix.go | Reworks mixed-type numeric comparisons (exact rational fallback + special float handling). |
| pkg/sql/plan/function/func_compare.go | Implements <=> execution and updates mismatch-compare callbacks. |
| pkg/sql/plan/function/func_cast_test.go | Adds tests for JSON→numeric cast precision/overflow/null/container handling. |
| pkg/sql/plan/function/func_cast.go | Enables JSON→numeric casts and implements JSON scalar parsing + numeric append logic. |
| pkg/sql/plan/function/func_binary.go | Implements YearWeekDate/Datetime/Timestamp executors. |
| pkg/sql/plan/deepcopy.go | Adds DeepCopyDropTable to correctly clone nested multi-table drop plans. |
| pkg/sql/plan/build_expr_test.go | Adds binder/plan tests for tuple <=> expansion and mismatch handling. |
| pkg/sql/plan/build_ddl_test.go | Adds tests for FK-drop target set logic in multi-table drop. |
| pkg/sql/plan/build_ddl.go | Implements multi-table DROP TABLE planning and FK-target checks. |
| pkg/sql/plan/build_alter_table_test.go | Adds DDL compatibility tests around JSON→numeric type changes. |
| pkg/sql/plan/build_alter_modify_column.go | Blocks JSON→numeric type changes in DDL while allowing runtime casts. |
| pkg/sql/plan/base_binder.go | Adds binding for <=>, including tuple-to-AND expansion. |
| pkg/sql/parsers/dialect/mysql/scanner.go | Adds lexer support for ->> as LONG_ARROW. |
| pkg/sql/parsers/dialect/mysql/mysql_sql_test.go | Adds parser/pretty-print tests for -> / ->> rewrite forms. |
| pkg/sql/parsers/dialect/mysql/mysql_sql.y | Adds grammar rules translating -> / ->> to json_extract / json_unquote(json_extract). |
| pkg/sql/compile/ddl.go | Executes multi-table drop by iterating per-target DropTable entries. |
| pkg/frontend/authenticate_test.go | Adds authorization/ownership tests for multi-table drop and plan privilege extraction. |
| pkg/frontend/authenticate.go | Extends privilege extraction + auth + implicit revoke logic to handle multi-table drop. |
fc416ef to
dc9a383
Compare
Cherry-pick YEARWEEK implementation from main (original commit 9f71c57) to 3.0-dev. Adds YEARWEEK(date[, mode]) / YEARWEEK(datetime[, mode]) / YEARWEEK(timestamp[, mode]) returning YYYYWW integer format. Co-authored-by: fengttt <fengttt@gmail.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Latest 3.0-dev already includes YEARWEEK scaffolding, so keep the upstream overloads and fix their mode handling to be row-wise with NULL propagation. Add string input coverage for the same mode/null cases. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
da72360 to
40d8cf0
Compare
Exercise all YEARWEEK overload registrations through GetFunctionByName and the registered execute methods so the new built-in registry paths are covered. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ouyuanning
approved these changes
Apr 29, 2026
aunjgr
approved these changes
Apr 29, 2026
XuPeng-SH
approved these changes
May 6, 2026
Contributor
Merge Queue Status
Waiting for
All merge conditions
Waiting for any of
All queue conditions
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
fixes #24234
What this PR does / why we need it:
Finishes YEARWEEK support on 3.0-dev after the latest temporal compatibility backport added the initial overloads.
YEARWEEK(date[, mode])is a standard MySQL function that returns year and week as YYYYWW format. This PR keeps the latest 3.0-dev scaffolding and fixes correctness gaps in mode handling:mode & 7) instead of clampingValidation
go test ./pkg/sql/plan/function -count=1