Skip to content

fix: parse interval parenthesized modulo (Fixes #24235) - #24242

Merged
mergify[bot] merged 4 commits into
matrixorigin:3.0-devfrom
LeftHandCold:fix/interval-parenthesized-modulo-3.0-dev
May 7, 2026
Merged

mergify[bot] merged 4 commits into
matrixorigin:3.0-devfrom
LeftHandCold:fix/interval-parenthesized-modulo-3.0-dev

Conversation

@LeftHandCold

Copy link
Copy Markdown
Collaborator

What type of PR is this?

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

Which issue(s) this PR fixes:

fixes #24235

What this PR does / why we need it:

Allows DATE_ADD/DATE_SUB interval operands to contain parenthesized modulo arithmetic before the time unit, such as:

DATE_SUB(CURRENT_DATE, INTERVAL (DAYOFWEEK(CURRENT_DATE) + 5) % 7 DAY)
DATE_SUB(CURRENT_DATE, INTERVAL (DAYOFWEEK(CURRENT_DATE) + 5) % 7 + 7 DAY)

The existing grammar already accepts the equivalent unary-plus expression form, so this PR narrowly normalizes INTERVAL (expr) % ... to that existing parse path without increasing yacc conflicts. It also keeps string/comment contents unchanged during normalization.

Validation

  • go test ./pkg/sql/parsers/dialect/mysql -count=1

Normalize INTERVAL (expr) % n forms to the existing unary-plus parse path so DATE_ADD and DATE_SUB can accept modulo arithmetic before the time unit. Add parser coverage for issue matrixorigin#24235 examples.

Fixes matrixorigin#24235

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings April 28, 2026 12:03
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Apr 28, 2026
@mergify
mergify Bot requested a review from XuPeng-SH April 28, 2026 12:04
@mergify mergify Bot added the kind/bug Something isn't working label Apr 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes MySQL dialect parsing for DATE_ADD/DATE_SUB ... INTERVAL (expr) % n <unit> by normalizing that specific shape into an equivalent unary-plus form that the existing grammar already accepts.

Changes:

  • Preprocesses SQL input to rewrite INTERVAL (expr) % ... into INTERVAL +(expr) % ... while skipping strings/backticks/comments.
  • Applies the normalization in both MySQLParser.Parse and NewLexer code paths.
  • Adds regression tests covering the failing queries and the normalization behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
pkg/sql/parsers/dialect/mysql/mysql_lexer.go Adds SQL normalization pass and helper scanners to support parenthesized modulo in INTERVAL operands.
pkg/sql/parsers/dialect/mysql/interval_issue24235_test.go Adds regression tests for issue #24235 and unit test for normalization behavior.

Add the repository license header required by SCA for the issue matrixorigin#24235 parser coverage test.

Co-authored-by: Copilot <[email protected]>
@mergify mergify Bot added the queued label May 7, 2026
@mergify

mergify Bot commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-05-07 03:15 UTC · Rule: release-3.0
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-05-07 04:09 UTC · at 8889bf1dffe2679479c87edf7d3a535c656cdc7f · squash

This pull request spent 53 minutes 53 seconds in the queue, including 53 minutes 36 seconds 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)

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.

5 participants