Skip to content

Commit 8738b5d

Browse files
kyleconroyclaude
andcommitted
Add support for ALTER TABLE DROP DETACHED PARTITION
- Add AlterDropDetachedPartition type in ast/ast.go - Parse DROP DETACHED PARTITION syntax in parser/parser.go - Handle new command type in explain output Fixes 03203_drop_detached_partition_all/stmt7 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent cbde83c commit 8738b5d

4 files changed

Lines changed: 14 additions & 9 deletions

File tree

ast/ast.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,9 @@ const (
680680
AlterMaterializeTTL AlterCommandType = "MATERIALIZE_TTL"
681681
AlterModifySetting AlterCommandType = "MODIFY_SETTING"
682682
AlterResetSetting AlterCommandType = "RESET_SETTING"
683-
AlterDropPartition AlterCommandType = "DROP_PARTITION"
684-
AlterDetachPartition AlterCommandType = "DETACH_PARTITION"
683+
AlterDropPartition AlterCommandType = "DROP_PARTITION"
684+
AlterDropDetachedPartition AlterCommandType = "DROP_DETACHED_PARTITION"
685+
AlterDetachPartition AlterCommandType = "DETACH_PARTITION"
685686
AlterAttachPartition AlterCommandType = "ATTACH_PARTITION"
686687
AlterReplacePartition AlterCommandType = "REPLACE_PARTITION"
687688
AlterFetchPartition AlterCommandType = "FETCH_PARTITION"

internal/explain/statements.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,7 +1850,7 @@ func explainAlterCommand(sb *strings.Builder, cmd *ast.AlterCommand, indent stri
18501850
}
18511851
case ast.AlterModifySetting:
18521852
fmt.Fprintf(sb, "%s Set\n", indent)
1853-
case ast.AlterDropPartition, ast.AlterDetachPartition, ast.AlterAttachPartition,
1853+
case ast.AlterDropPartition, ast.AlterDropDetachedPartition, ast.AlterDetachPartition, ast.AlterAttachPartition,
18541854
ast.AlterReplacePartition, ast.AlterFetchPartition, ast.AlterMovePartition, ast.AlterFreezePartition, ast.AlterApplyPatches, ast.AlterApplyDeletedMask:
18551855
if cmd.Partition != nil {
18561856
// PARTITION ALL is shown as Partition_ID (empty) in EXPLAIN AST
@@ -2149,7 +2149,7 @@ func countAlterCommandChildren(cmd *ast.AlterCommand) int {
21492149
}
21502150
case ast.AlterModifySetting:
21512151
children = 1
2152-
case ast.AlterDropPartition, ast.AlterDetachPartition, ast.AlterAttachPartition,
2152+
case ast.AlterDropPartition, ast.AlterDropDetachedPartition, ast.AlterDetachPartition, ast.AlterAttachPartition,
21532153
ast.AlterReplacePartition, ast.AlterFetchPartition, ast.AlterMovePartition, ast.AlterFreezePartition, ast.AlterApplyPatches, ast.AlterApplyDeletedMask:
21542154
if cmd.Partition != nil {
21552155
children++

parser/parser.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5475,6 +5475,14 @@ func (p *Parser) parseAlterCommand() *ast.AlterCommand {
54755475
cmd.ConstraintName = p.current.Value
54765476
p.nextToken()
54775477
}
5478+
} else if p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "DETACHED" {
5479+
// DROP DETACHED PARTITION
5480+
p.nextToken() // skip DETACHED
5481+
if p.currentIs(token.PARTITION) {
5482+
p.nextToken() // skip PARTITION
5483+
cmd.Type = ast.AlterDropDetachedPartition
5484+
cmd.Partition = p.parseExpression(LOWEST)
5485+
}
54785486
} else if p.currentIs(token.PARTITION) {
54795487
cmd.Type = ast.AlterDropPartition
54805488
p.nextToken()
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt7": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)