Skip to content

fix(parser): support Unicode select aliases - #25793

Closed
ULookup wants to merge 3 commits into
matrixorigin:mainfrom
ULookup:codex/fix-25014-unicode-identifiers
Closed

ULookup wants to merge 3 commits into
matrixorigin:mainfrom
ULookup:codex/fix-25014-unicode-identifiers

Conversation

@ULookup

@ULookup ULookup commented Jul 16, 2026 •

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:

issue #25014

What this PR does / why we need it:

The MySQL scanner only treated ASCII letters as the start and continuation of unquoted identifiers, so select aliases containing Arabic, Chinese, or other BMP Unicode characters failed to parse.

This change enables valid BMP Unicode identifier scanning only when the lexer is reading the token after AS. Other grammar contexts retain their original tokenization and parser error positions. Invalid UTF-8, NUL, and supplementary characters remain rejected, including numeric, hexadecimal, and binary prefix paths.

Regression coverage includes Arabic and Chinese aliases, numeric prefixes, quoted aliases, invalid UTF-8, NUL, supplementary characters, bind variables, and exact legacy errors for non-alias DDL and account paths.

Validation:

  • make build
  • go vet ./pkg/sql/parsers/...
  • go test -count=1 ./pkg/sql/parsers/...
  • go test -race -count=1 -run 'TestUnicodeIdentifier|TestInvalidUnicodeIdentifiers' ./pkg/sql/parsers/dialect/mysql
  • Verified through the MySQL protocol against a locally built MatrixOne service using an 8-row Chinese/Arabic dataset with grouping, NULL aggregation, and computed amounts; Unicode result-column headers were returned correctly.
  • Verified the affected DDL and account cases still return parser error 1064 with the original error columns.

@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 →

@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Jul 16, 2026
@mergify mergify Bot added the kind/bug Something isn't working label Jul 16, 2026
@ULookup ULookup changed the title fix(parser): support Unicode identifiers fix(parser): support Unicode select aliases Jul 16, 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

This PR updates the MySQL dialect scanner/lexer to accept BMP Unicode characters in unquoted identifiers only in the token position immediately following AS, enabling Unicode SELECT aliases (e.g. Arabic/Chinese). It also strengthens identifier validation to continue rejecting invalid UTF-8, NUL, and supplementary-plane characters, with regression tests covering both valid/invalid cases and legacy error positioning in non-alias contexts.

Changes:

  • Add a lexer-controlled allowUnicodeIdentifier flag to let the scanner treat non-ASCII bytes as identifier characters only after AS.
  • Validate quoted identifiers (and Unicode-enabled identifiers) to reject invalid UTF-8, NUL, and supplementary characters; propagate LEX_ERROR through numeric/hex/binary-prefixed identifier paths.
  • Add scanner- and parser-level tests for Unicode aliases and invalid Unicode inputs, plus error-position stability checks for non-alias statements.

Reviewed changes

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

File Description
pkg/sql/parsers/dialect/mysql/scanner.go Adds Unicode-aware identifier scanning/validation helpers and threads them into identifier/number/backtick-ID scanning.
pkg/sql/parsers/dialect/mysql/mysql_lexer.go Enables Unicode identifier scanning when the previously lexed token is AS.
pkg/sql/parsers/dialect/mysql/scanner_test.go Adds unit tests for Unicode identifiers and invalid Unicode/UTF-8 cases at the scanner level.
pkg/sql/parsers/dialect/mysql/mysql_sql_test.go Adds parser-level regression tests for valid/invalid Unicode aliases and error-position expectations.

Comment on lines +55 to +57
// allowUnicodeIdentifier is enabled by the lexer only where the grammar
// accepts Unicode aliases. Other contexts retain the original tokenization.
allowUnicodeIdentifier bool
Comment on lines 152 to 154
func (l *Lexer) Lex(lval *yySymType) int {
l.scanner.allowUnicodeIdentifier = l.lastToken == AS
typ, str := l.scanner.Scan()
mergify Bot pushed a commit that referenced this pull request Jul 22, 2026
This PR continues the unfinished work from #25793 while preserving its original commits and authorship.

Review established that current `main` already accepts the quoted Arabic and Chinese aliases reported in #25014. It also established that the parser receives raw COM_QUERY bytes without the negotiated client character set, so enforcing UTF-8/BMP rules inside the scanner would reject valid non-UTF-8 client input such as latin1 `0xE9`.

The production scanner changes have therefore been removed. The final diff is deliberately test-only and records the existing compatibility contract:

- quoted Arabic and Chinese aliases remain accepted;
- escaped delimiters preserve Unicode contents;
- raw latin1 bytes remain accepted on both the fast and escaped-delimiter paths;
- raw client bytes are not reclassified by interpreting them as unconditional UTF-8.

Character-set-aware identifier validation must happen after a future COM_QUERY normalization boundary has decoded `character_set_client`; this PR does not introduce that broader protocol change.

Approved by: @XuPeng-SH, @gouhongshen
@VioletQwQ-0

Copy link
Copy Markdown
Collaborator

Superseded by merged PR #25879. The final takeover preserved the compatible behavior with regression coverage and removed the scanner-side charset validation that lacked COM_QUERY client-charset context.

VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…igin#25879)

This PR continues the unfinished work from matrixorigin#25793 while preserving its original commits and authorship.

Review established that current `main` already accepts the quoted Arabic and Chinese aliases reported in matrixorigin#25014. It also established that the parser receives raw COM_QUERY bytes without the negotiated client character set, so enforcing UTF-8/BMP rules inside the scanner would reject valid non-UTF-8 client input such as latin1 `0xE9`.

The production scanner changes have therefore been removed. The final diff is deliberately test-only and records the existing compatibility contract:

- quoted Arabic and Chinese aliases remain accepted;
- escaped delimiters preserve Unicode contents;
- raw latin1 bytes remain accepted on both the fast and escaped-delimiter paths;
- raw client bytes are not reclassified by interpreting them as unconditional UTF-8.

Character-set-aware identifier validation must happen after a future COM_QUERY normalization boundary has decoded `character_set_client`; this PR does not introduce that broader protocol change.

Approved by: @XuPeng-SH, @gouhongshen
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…igin#25879)

This PR continues the unfinished work from matrixorigin#25793 while preserving its original commits and authorship.

Review established that current `main` already accepts the quoted Arabic and Chinese aliases reported in matrixorigin#25014. It also established that the parser receives raw COM_QUERY bytes without the negotiated client character set, so enforcing UTF-8/BMP rules inside the scanner would reject valid non-UTF-8 client input such as latin1 `0xE9`.

The production scanner changes have therefore been removed. The final diff is deliberately test-only and records the existing compatibility contract:

- quoted Arabic and Chinese aliases remain accepted;
- escaped delimiters preserve Unicode contents;
- raw latin1 bytes remain accepted on both the fast and escaped-delimiter paths;
- raw client bytes are not reclassified by interpreting them as unconditional UTF-8.

Character-set-aware identifier validation must happen after a future COM_QUERY normalization boundary has decoded `character_set_client`; this PR does not introduce that broader protocol change.

Approved by: @XuPeng-SH, @gouhongshen
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…igin#25879)

This PR continues the unfinished work from matrixorigin#25793 while preserving its original commits and authorship.

Review established that current `main` already accepts the quoted Arabic and Chinese aliases reported in matrixorigin#25014. It also established that the parser receives raw COM_QUERY bytes without the negotiated client character set, so enforcing UTF-8/BMP rules inside the scanner would reject valid non-UTF-8 client input such as latin1 `0xE9`.

The production scanner changes have therefore been removed. The final diff is deliberately test-only and records the existing compatibility contract:

- quoted Arabic and Chinese aliases remain accepted;
- escaped delimiters preserve Unicode contents;
- raw latin1 bytes remain accepted on both the fast and escaped-delimiter paths;
- raw client bytes are not reclassified by interpreting them as unconditional UTF-8.

Character-set-aware identifier validation must happen after a future COM_QUERY normalization boundary has decoded `character_set_client`; this PR does not introduce that broader protocol change.

Approved by: @XuPeng-SH, @gouhongshen

This branch was successfully deployed

No deployments
ci — 0b863c11 Deployed Jul 20, 2026 by VioletQwQ-0 via Matrixone Utils CI / Coverage #41439
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.

Non-ASCII (Arabic/Chinese) column identifiers rejected even when backtick-quoted (error 1064) — v4.0.0-rc2

4 participants