Skip to content

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

Open
LeftHandCold wants to merge 3 commits intomatrixorigin:3.0-devfrom
LeftHandCold:fix/interval-parenthesized-modulo-3.0-dev
Open

fix: parse interval parenthesized modulo (Fixes #24235)#24242
LeftHandCold wants to merge 3 commits intomatrixorigin:3.0-devfrom
LeftHandCold:fix/interval-parenthesized-modulo-3.0-dev

Conversation

@LeftHandCold
Copy link
Copy Markdown
Contributor

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 <223556219+Copilot@users.noreply.github.com>
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
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

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.

Comment thread pkg/sql/parsers/dialect/mysql/mysql_lexer.go Outdated
Comment thread pkg/sql/parsers/dialect/mysql/mysql_lexer.go
Comment thread pkg/sql/parsers/dialect/mysql/mysql_lexer.go Outdated
Add the repository license header required by SCA for the issue matrixorigin#24235 parser coverage test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Treat comments around INTERVAL parenthesized modulo expressions as trivia and avoid copying unchanged SQL on the common parse path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

4 participants