Conversation
### What problem does this PR solve? Issue Number: None Related PR: None Problem Summary: A comment on a VARIANT predefined field is printed without SQL-literal escaping, so the output of SHOW CREATE TABLE cannot be replayed when the comment contains a quote: ```sql CREATE TABLE t (id INT, v VARIANT<'price':INT COMMENT "O'Reilly">) ...; SHOW CREATE TABLE t; -- v variant<'price':int COMMENT 'O'Reilly', ...> -- replaying it fails: no viable alternative at input 'variant<'price':int COMMENT 'O'Reilly' ``` Root cause: both `catalog.VariantField.toSql` (used by SHOW CREATE TABLE through `Column.toSql`) and `nereids.types.VariantField.toSql` wrap the raw comment in single quotes. The parser side was also inconsistent with the rest of the grammar: `visitVariantSubColType` only strips the outer quotes and unescapes backslashes, so a doubled quote such as `'O''Reilly'` is stored as `O''Reilly`. Fix, following how STRUCT field comments are already handled: - print the comment with `SqlUtils.quoteStringLiteral` / `SqlLiteralUtils.quoteStringLiteral`; - parse it with `SqlLiteralUtils.parseStringLiteral`, like `visitComplexColType` does. After the fix the comment above is printed as `COMMENT "O'Reilly"`, and quotes, doubled quotes and backslashes survive a SHOW CREATE TABLE → CREATE TABLE round trip. ### Release note Fix SHOW CREATE TABLE output that could not be replayed when a VARIANT predefined field comment contains quotes or backslashes. ### Check List (For Author) - Test: Regression test (variant_p0/predefine/test_variant_predefine_comment_escape) / Unit Test (TypeTest#testVariantFieldCommentToSqlRoundTrip) - Behavior changed: Yes. SHOW CREATE TABLE prints predefined field comments as double-quoted, escaped literals; a doubled quote inside a comment is now stored as a single quote, like column and STRUCT field comments. - Does this need documentation: No Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
eldenmoon
requested review from
924060929,
englefly,
morrySnow and
starocean999
as code owners
September 18, 2026 09:38
Member
Author
|
run buildall |
Contributor
TPC-H: Total hot run time: 27538 ms |
Contributor
TPC-DS: Total hot run time: 153415 ms |
Contributor
ClickBench: Total hot run time: 24.06 s |
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 problem does this PR solve?
Issue Number: None
Related PR: None
Problem Summary:
A comment on a VARIANT predefined field is printed without SQL-literal escaping, so the output of SHOW CREATE TABLE cannot be replayed when the comment contains a quote:
Root cause: both
catalog.VariantField.toSql(used by SHOW CREATE TABLE throughColumn.toSql) andnereids.types.VariantField.toSqlwrap the raw comment in single quotes. The parser side was also inconsistent with the rest of the grammar:visitVariantSubColTypeonly strips the outer quotes and unescapes backslashes, so a doubled quote such as'O''Reilly'is stored asO''Reilly.Fix, following how STRUCT field comments are already handled:
SqlUtils.quoteStringLiteral/SqlLiteralUtils.quoteStringLiteral;SqlLiteralUtils.parseStringLiteral, likevisitComplexColTypedoes.After the fix the comment above is printed as
COMMENT "O'Reilly", and quotes, doubled quotes and backslashes survive a SHOW CREATE TABLE → CREATE TABLE round trip.Release note
Fix SHOW CREATE TABLE output that could not be replayed when a VARIANT predefined field comment contains quotes or backslashes.
Check List (For Author)
🤖 Generated with Claude Code