fix(parser): stop column name leaking into CAST(... AS UNSIGNED/SIGNED) type (#25131) - #25169
Merged
Merged
Conversation
…D) type (matrixorigin#25131) GROUP BY CAST(col AS UNSIGNED) with the same CAST in SELECT and ORDER BY failed with "column must appear in the GROUP BY clause or be used in an aggregate function". Root cause: in the mysql grammar, `integer_opt` (the optional INTEGER/INT keyword after SIGNED/UNSIGNED in a cast type) had an empty action `{}` that never assigned `$$`. goyacc therefore left stale stack memory in it — for `CAST(col AS UNSIGNED)` that stale value was the preceding column name. The `UNSIGNED integer_opt` rule uses it as the type's FamilyString, so the cast rendered as e.g. `cast(zsd04.vgpos as vgpos unsigned)`. ORDER BY qualifies its column refs (via qualifyColumnNames) and keys the grouped-expression lookup on tree.String of the cast; the leaked column name made that key differ from the GROUP BY key, so the match failed and the bare column was reported as not grouped. (SELECT happened to bind the cast directly, so it only surfaced once ORDER BY was present.) Fix: make the empty `integer_opt` action assign `$$ = ""` so the cast target type is rendered deterministically (`as unsigned` / `as signed`). This also fixes the same latent corruption for CAST(... AS SIGNED). Regenerated mysql_sql.go (0 conflicts). Adds parser round-trip regression cases and a BVT case (dml/select/group_by_cast) covering the issue's reproductions plus SIGNED, UNSIGNED INTEGER, DESC ordering, and integer-column variants. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
iamlinjunhong
approved these changes
Jun 26, 2026
heni02
approved these changes
Jun 26, 2026
Contributor
|
Queued — the merge queue status continues in this comment ↓. |
Contributor
Merge Queue Status
This pull request spent 21 seconds in the queue, including 2 seconds running CI. Required conditions to merge
|
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:
issue #25131
What this PR does / why we need it:
GROUP BY CAST(col AS UNSIGNED)with the sameCASTinSELECTandORDER BYfailed with:even though the
SELECT,GROUP BY, andORDER BYexpressions are theidentical
CAST(col AS UNSIGNED).Root cause
In the mysql grammar,
integer_opt(the optionalINTEGER/INTkeywordafter
SIGNED/UNSIGNEDin a cast type) had an empty action{}that neverassigned
$$. goyacc leaves stale parser-stack memory in an unassigned$$,and for
CAST(col AS UNSIGNED)that stale<str>value was the precedingcolumn name. The
UNSIGNED integer_optrule uses it as the type'sFamilyString, so the cast rendered as e.g.:ORDER BYqualifies its column references (qualifyColumnNames) and keys thegrouped-expression lookup on
tree.Stringof the cast. The leaked column namemade that key differ from the
GROUP BYkey, so the match failed and the barecolumn was reported as not grouped. (
SELECTbinds the cast directly, so thecorruption only surfaced once
ORDER BYwas present.)Fix
Assign
$$ = ""in the emptyinteger_optaction so the cast target type isrendered deterministically (
as unsigned/as signed). This also fixes thesame latent corruption for
CAST(... AS SIGNED). Regeneratedmysql_sql.go(0 shift/reduce conflicts; regeneration is deterministic).
Tests
mysql_sql_test.go(TestValid):cast(col as unsigned)/cast(col as signed)in GROUP BY/ORDER BY renderstably.
dml/select/group_by_castcovering the issue's tworeproductions plus SIGNED, UNSIGNED INTEGER, DESC ordering, and
integer-column variants.
dml/select(1047) andfunction/builtin(247) pass.🤖 Generated with Claude Code