Skip to content

Commit 730f9d2

Browse files
committed
Add ALTER TABLE MODIFY COMMENT support
Implement parsing and explain output for ALTER TABLE ... MODIFY COMMENT statements: - Add AlterModifyComment command type to AST - Add parser handling in MODIFY case for COMMENT token - Add explain output handling for MODIFY_COMMENT command type - Add child count handling for comment literal This fixes 14 statements across 4 tests: - 02111_modify_table_comment: stmt6, stmt10 - 02155_dictionary_comment: stmt13 - 02792_alter_table_modify_comment: stmt4, stmt9, stmt14, stmt19, stmt24, stmt29, stmt34, stmt39, stmt44, stmt49 - 03142_alter_comment_parameterized_view: stmt3
1 parent bb6a1c6 commit 730f9d2

7 files changed

Lines changed: 20 additions & 20 deletions

File tree

ast/ast.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ const (
653653
AlterDropStatistics AlterCommandType = "DROP_STATISTICS"
654654
AlterClearStatistics AlterCommandType = "CLEAR_STATISTICS"
655655
AlterMaterializeStatistics AlterCommandType = "MATERIALIZE_STATISTICS"
656+
AlterModifyComment AlterCommandType = "MODIFY_COMMENT"
656657
)
657658

658659
// TruncateQuery represents a TRUNCATE statement.

internal/explain/statements.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,10 @@ func explainAlterCommand(sb *strings.Builder, cmd *ast.AlterCommand, indent stri
12101210
if cmd.Comment != "" {
12111211
fmt.Fprintf(sb, "%s Literal \\'%s\\'\n", indent, escapeStringLiteral(cmd.Comment))
12121212
}
1213+
case ast.AlterModifyComment:
1214+
if cmd.Comment != "" {
1215+
fmt.Fprintf(sb, "%s Literal \\'%s\\'\n", indent, escapeStringLiteral(cmd.Comment))
1216+
}
12131217
case ast.AlterAddIndex, ast.AlterDropIndex, ast.AlterClearIndex, ast.AlterMaterializeIndex:
12141218
if cmd.Index != "" {
12151219
fmt.Fprintf(sb, "%s Identifier %s\n", indent, cmd.Index)
@@ -1392,6 +1396,10 @@ func countAlterCommandChildren(cmd *ast.AlterCommand) int {
13921396
if cmd.Comment != "" {
13931397
children++
13941398
}
1399+
case ast.AlterModifyComment:
1400+
if cmd.Comment != "" {
1401+
children++
1402+
}
13951403
case ast.AlterRenameColumn:
13961404
if cmd.ColumnName != "" {
13971405
children++

parser/parser.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4495,6 +4495,14 @@ func (p *Parser) parseAlterCommand() *ast.AlterCommand {
44954495
p.nextToken()
44964496
cmd.StatisticsTypes = p.parseStatisticsTypeList()
44974497
}
4498+
} else if p.currentIs(token.COMMENT) {
4499+
// MODIFY COMMENT 'comment string'
4500+
cmd.Type = ast.AlterModifyComment
4501+
p.nextToken()
4502+
if p.currentIs(token.STRING) {
4503+
cmd.Comment = p.current.Value
4504+
p.nextToken()
4505+
}
44984506
}
44994507
case token.RENAME:
45004508
p.nextToken()
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
22
"explain_todo": {
3-
"stmt10": true,
43
"stmt4": true,
5-
"stmt6": true,
64
"stmt8": true
75
}
86
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt13": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
{
22
"explain_todo": {
3-
"stmt14": true,
4-
"stmt19": true,
53
"stmt22": true,
6-
"stmt24": true,
7-
"stmt29": true,
8-
"stmt34": true,
9-
"stmt39": true,
10-
"stmt4": true,
11-
"stmt44": true,
12-
"stmt49": true,
13-
"stmt7": true,
14-
"stmt9": true
4+
"stmt7": true
155
}
166
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"explain_todo": {
3-
"stmt2": true,
4-
"stmt3": true
3+
"stmt2": true
54
}
65
}

0 commit comments

Comments
 (0)