Skip to content

fix: WEEK() function mode parameter support (Fixes #24236)#24239

Merged
mergify[bot] merged 4 commits intomatrixorigin:3.0-devfrom
LeftHandCold:fix/week-mode-param-3.0-dev
May 6, 2026
Merged

fix: WEEK() function mode parameter support (Fixes #24236)#24239
mergify[bot] merged 4 commits intomatrixorigin:3.0-devfrom
LeftHandCold:fix/week-mode-param-3.0-dev

Conversation

@LeftHandCold
Copy link
Copy Markdown
Contributor

@LeftHandCold LeftHandCold commented Apr 28, 2026

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

fixes #24236

What this PR does / why we need it:

Re-implements WEEK() mode parameter support from main on 3.0-dev while preserving existing one-argument WEEK behavior.

MySQL's WEEK(date, mode) accepts an integer 0-7 as second argument to control week numbering semantics. Previously, MatrixOne's WEEK only registered single-argument overloads, causing WEEK(date, 3) to fail with "invalid argument function week, bad value [DATE BIGINT]".

This PR:

  • Preserves the legacy one-argument WEEK(date) / WEEK(datetime) result path used by existing BVT cases
  • Applies MySQL mode semantics only when the second mode argument is provided
  • Registers (T_date, T_int64) and (T_datetime, T_int64) overloads
  • Handles non-constant mode values and row-level NULL mode values correctly
  • Adds coverage for the 2000-01-01 default WEEK case that failed BVT

Validation

  • go test ./pkg/sql/plan/function -count=1

Copilot AI review requested due to automatic review settings April 28, 2026 08:29
@matrix-meow matrix-meow added the size/XXL Denotes a PR that changes 2000+ lines label Apr 28, 2026
@mergify mergify Bot added the kind/bug Something isn't working label Apr 28, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR broadens MySQL-compatibility in the SQL layer by adding WEEK(date, mode) overloads and also introducing several additional MySQL behaviors (null-safe <=>, JSON ->/->> operators, JSON→numeric casts, and multi-table DROP TABLE) spanning parser, planner, compiler, and frontend privilege handling.

Changes:

  • Add WEEK(date|datetime, int64 mode) overloads and update week computation to accept a mode argument.
  • Implement MySQL operators/features: null-safe equal <=>, JSON -> / ->> parsing, and JSON→numeric casting behavior.
  • Add support for multi-table DROP TABLE through plan/proto, planning, compilation, and privilege extraction/auth checks, plus distributed test coverage.

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 results now that JSON can be compared/cast to numeric.
test/distributed/cases/function/func_null_safe_equal.sql Adds distributed SQL coverage for <=> semantics.
test/distributed/cases/function/func_null_safe_equal.result Expected outputs for <=> distributed tests.
test/distributed/cases/function/func_json_arrow.sql Adds distributed SQL coverage for JSON -> / ->> operators.
test/distributed/cases/function/func_json_arrow.result Expected outputs for JSON arrow operator tests.
test/distributed/cases/ddl/drop_table_multiple.sql Adds distributed coverage for multi-table DROP TABLE behavior.
test/distributed/cases/ddl/drop_table_multiple.result Expected outputs for multi-table DROP TABLE tests.
proto/plan.proto Extends DropTable plan message with per-table entries for multi-drop.
pkg/sql/plan/function/list_operator.go Registers <=> operator and its type-checking/cast behavior.
pkg/sql/plan/function/list_builtIn.go Registers 2-arg WEEK() overloads for `(date
pkg/sql/plan/function/init.go Adds encoded ID/name constants for <=>.
pkg/sql/plan/function/function_id_test.go Updates function-id registry expectations for new <=> id.
pkg/sql/plan/function/function_id.go Adds NULL_SAFE_EQUAL function id and registers <=> name.
pkg/sql/plan/function/func_unary.go Reworks DateToWeek / DatetimeToWeek to accept an optional mode.
pkg/sql/plan/function/func_compare_test.go Adds unit tests for numeric comparisons and <=> edge cases.
pkg/sql/plan/function/func_compare_fix.go Rewrites numeric type-mismatch comparison fallback (exact/approx paths).
pkg/sql/plan/function/func_compare.go Implements <=> execution and updates mismatch-compare callsites.
pkg/sql/plan/function/func_cast_test.go Adds unit tests for JSON→numeric casting semantics (precision/overflow/null).
pkg/sql/plan/function/func_cast.go Enables JSON→numeric casts and implements conversion logic.
pkg/sql/plan/deepcopy.go Adds deep-copy support for recursive multi-drop DropTable plans.
pkg/sql/plan/build_expr_test.go Adds plan-binding tests for tuple <=> behavior.
pkg/sql/plan/build_ddl_test.go Adds tests for FK-related drop-target logic in multi-drop.
pkg/sql/plan/build_ddl.go Implements multi-table DROP TABLE planning and FK-target checking.
pkg/sql/plan/build_alter_table_test.go Adds tests asserting JSON→numeric remains blocked for DDL 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 binder support for <=> including tuple expansion to AND of <=>.
pkg/sql/parsers/dialect/mysql/scanner.go Adds tokenization for ->> (LONG_ARROW).
pkg/sql/parsers/dialect/mysql/mysql_sql_test.go Adds SQL pretty-print tests for -> / ->> rewrites.
pkg/sql/parsers/dialect/mysql/mysql_sql.y Adds grammar rules translating ->/->> into json_extract / json_unquote(json_extract).
pkg/sql/compile/ddl.go Executes multi-drop by iterating per-table entries and adds warning-on-missing-child-table path.
pkg/frontend/authenticate_test.go Adds privilege/ownership tests for multi-table DROP TABLE and plan tip extraction.
pkg/frontend/authenticate.go Updates privilege tip extraction and privilege/ownership checks for multi-drop.

Comment thread pkg/sql/plan/function/func_unary.go Outdated
Comment thread pkg/sql/plan/function/func_compare.go
Comment thread pkg/sql/plan/function/func_compare_fix.go
Comment thread pkg/sql/plan/build_ddl.go
Exercise WEEK through registered overloads and cover NULL/select-list branches for the two-argument mode implementation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mergify mergify Bot added the queued label May 6, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 6, 2026

Merge Queue Status

  • Entered queue2026-05-06 10:11 UTC · Rule: release-3.0
  • Checks passed · in-place
  • Merged2026-05-06 11:53 UTC · at 03c8946cf275c2170982021d0e1c5a8ac708de5e · squash

This pull request spent 1 hour 41 minutes 42 seconds in the queue, including 53 minutes 1 second running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • branch-protection-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI (3.0) / Coverage
    • check-neutral = Matrixone Utils CI (3.0) / Coverage
    • check-skipped = Matrixone Utils CI (3.0) / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)

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.

6 participants