Skip to content

fix(parser): allow reserved keywords as aliases after AS - #24503

Merged
XuPeng-SH merged 11 commits into
matrixorigin:mainfrom
VioletQwQ-0:fix/24410-reserved-keyword-alias
May 28, 2026
Merged

fix(parser): allow reserved keywords as aliases after AS#24503
XuPeng-SH merged 11 commits into
matrixorigin:mainfrom
VioletQwQ-0:fix/24410-reserved-keyword-alias

Conversation

@VioletQwQ-0

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:

issue #24410

What this PR does / why we need it:

Allows reserved keywords (ROWS, CURRENT_TIME, CURRENT_TIMESTAMP, LOCALTIME, LOCALTIMESTAMP) to be used as column aliases after AS, matching MySQL behavior.

Before this fix:

SELECT NOW() AS current_time;  -- parser error near "current_time"
SELECT COUNT(*) AS rows FROM t; -- parser error near "rows"

After:

SELECT NOW() AS current_time;  -- works
SELECT COUNT(*) AS rows FROM t; -- works

Implementation

Lexer-level fix in mysql_lexer.go: track lastToken and convert the 5 reserved keyword tokens to ID when they immediately follow AS. No grammar changes needed.

Scope

This PR addresses sub-issue 1 of #24410 (reserved word aliases). Sub-issues 2 and 3 (TIMESTAMPDIFF units and aggregate-in-TIMESTAMPDIFF) were already fixed by #23161 (Dec 2025).

Test plan

  • Parser regression tests (6 alias cases + 3 regression cases)
  • End-to-end MO instance verification
  • Full parser test suite passes
  • Existing ROWS (window functions) and CURRENT_TIME() (function call) behavior unchanged

🤖 Generated with Claude Code

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify mergify Bot added the kind/bug Something isn't working label May 20, 2026
@matrix-meow matrix-meow added the size/S Denotes a PR that changes [10,99] lines label May 20, 2026
@VioletQwQ-0
VioletQwQ-0 force-pushed the fix/24410-reserved-keyword-alias branch from 470fe9f to c06f250 Compare May 20, 2026 09:34
…n#24410)

Treat ROWS, CURRENT_TIME, CURRENT_TIMESTAMP, LOCALTIME, and
LOCALTIMESTAMP as identifiers when they follow AS in the lexer.
This lets statements like SELECT 1 AS rows and
SELECT NOW() AS current_time parse successfully, matching
MySQL behavior.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me. I pulled the latest head, re-checked the lexer change against the current main base, and did not find a blocker. The allowlist is intentionally narrow, the AS-context rewrite only applies to the five reserved tokens needed for issue #24410, and it does not interfere with their original keyword uses like CURRENT_TIME() or ROWS in window frames. The added parser tests and the parser package test suite both look good for this fix.

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/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants