Skip to content

Commit 4b1adb3

Browse files
committed
Add APPLY PATCHES and CLEAR COLUMN IN PARTITION support
- Add AlterApplyPatches command type for ALTER TABLE ... APPLY PATCHES IN PARTITION - Add IN PARTITION parsing for CLEAR COLUMN command - Fix Partition output wrapper in explain for CLEAR COLUMN
1 parent c424670 commit 4b1adb3

9 files changed

Lines changed: 33 additions & 44 deletions

File tree

ast/ast.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ const (
644644
AlterMovePartition AlterCommandType = "MOVE_PARTITION"
645645
AlterFreezePartition AlterCommandType = "FREEZE_PARTITION"
646646
AlterFreeze AlterCommandType = "FREEZE"
647+
AlterApplyPatches AlterCommandType = "APPLY_PATCHES"
647648
AlterDeleteWhere AlterCommandType = "DELETE_WHERE"
648649
AlterUpdate AlterCommandType = "UPDATE"
649650
AlterAddProjection AlterCommandType = "ADD_PROJECTION"

internal/explain/statements.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,8 @@ func explainAlterCommand(sb *strings.Builder, cmd *ast.AlterCommand, indent stri
11981198
fmt.Fprintf(sb, "%s Identifier %s\n", indent, cmd.ColumnName)
11991199
}
12001200
if cmd.Partition != nil {
1201-
Node(sb, cmd.Partition, depth+1)
1201+
fmt.Fprintf(sb, "%s Partition (children 1)\n", indent)
1202+
Node(sb, cmd.Partition, depth+2)
12021203
}
12031204
case ast.AlterCommentColumn:
12041205
if cmd.ColumnName != "" {
@@ -1233,7 +1234,7 @@ func explainAlterCommand(sb *strings.Builder, cmd *ast.AlterCommand, indent stri
12331234
case ast.AlterModifySetting:
12341235
fmt.Fprintf(sb, "%s Set\n", indent)
12351236
case ast.AlterDropPartition, ast.AlterDetachPartition, ast.AlterAttachPartition,
1236-
ast.AlterReplacePartition, ast.AlterFetchPartition, ast.AlterMovePartition, ast.AlterFreezePartition:
1237+
ast.AlterReplacePartition, ast.AlterFetchPartition, ast.AlterMovePartition, ast.AlterFreezePartition, ast.AlterApplyPatches:
12371238
if cmd.Partition != nil {
12381239
// PARTITION ALL is shown as Partition_ID (empty) in EXPLAIN AST
12391240
if ident, ok := cmd.Partition.(*ast.Identifier); ok && strings.ToUpper(ident.Name()) == "ALL" {
@@ -1430,7 +1431,7 @@ func countAlterCommandChildren(cmd *ast.AlterCommand) int {
14301431
case ast.AlterModifySetting:
14311432
children = 1
14321433
case ast.AlterDropPartition, ast.AlterDetachPartition, ast.AlterAttachPartition,
1433-
ast.AlterReplacePartition, ast.AlterFetchPartition, ast.AlterMovePartition, ast.AlterFreezePartition:
1434+
ast.AlterReplacePartition, ast.AlterFetchPartition, ast.AlterMovePartition, ast.AlterFreezePartition, ast.AlterApplyPatches:
14341435
if cmd.Partition != nil {
14351436
children++
14361437
}

parser/parser.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4569,10 +4569,18 @@ func (p *Parser) parseAlterCommand() *ast.AlterCommand {
45694569
} else if p.currentIs(token.COLUMN) {
45704570
cmd.Type = ast.AlterClearColumn
45714571
p.nextToken()
4572-
if p.currentIs(token.IDENT) {
4572+
if p.currentIs(token.IDENT) || p.current.Token.IsKeyword() {
45734573
cmd.ColumnName = p.current.Value
45744574
p.nextToken()
45754575
}
4576+
// Parse IN PARTITION
4577+
if p.currentIs(token.IN) {
4578+
p.nextToken() // skip IN
4579+
if p.currentIs(token.PARTITION) {
4580+
p.nextToken() // skip PARTITION
4581+
cmd.Partition = p.parseExpression(LOWEST)
4582+
}
4583+
}
45764584
} else if p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "PROJECTION" {
45774585
cmd.Type = ast.AlterClearProjection
45784586
p.nextToken()
@@ -4760,6 +4768,20 @@ func (p *Parser) parseAlterCommand() *ast.AlterCommand {
47604768
}
47614769
}
47624770
}
4771+
case token.APPLY:
4772+
// APPLY PATCHES IN PARTITION expr
4773+
p.nextToken() // skip APPLY
4774+
if p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "PATCHES" {
4775+
p.nextToken() // skip PATCHES
4776+
cmd.Type = ast.AlterApplyPatches
4777+
if p.currentIs(token.IN) {
4778+
p.nextToken() // skip IN
4779+
if p.currentIs(token.PARTITION) {
4780+
p.nextToken() // skip PARTITION
4781+
cmd.Partition = p.parseExpression(LOWEST)
4782+
}
4783+
}
4784+
}
47634785
case token.DELETE:
47644786
// DELETE WHERE condition - mutation to delete rows
47654787
cmd.Type = ast.AlterDeleteWhere
Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt11": true,
4-
"stmt24": true,
5-
"stmt31": true,
6-
"stmt34": true,
7-
"stmt37": true,
8-
"stmt38": true,
9-
"stmt43": true,
10-
"stmt44": true,
11-
"stmt48": true,
12-
"stmt8": true
13-
}
14-
}
1+
{}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt4": true,
4-
"stmt6": true
5-
}
6-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt28": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt9": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt4": true,
4-
"stmt5": true
5-
}
6-
}
1+
{}

parser/testdata/03100_lwu_22_detach_attach_patches/metadata.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
{
22
"explain_todo": {
3-
"stmt21": true,
43
"stmt23": true,
5-
"stmt24": true,
64
"stmt25": true,
75
"stmt26": true,
8-
"stmt27": true,
96
"stmt28": true,
10-
"stmt30": true,
117
"stmt33": true,
128
"stmt37": true
139
}

0 commit comments

Comments
 (0)