Skip to content

Commit e471e45

Browse files
kyleconroyclaude
andcommitted
Handle PARTITION ID syntax in UPDATE mutation commands
- Parse PARTITION ID 'value' syntax in ALTER UPDATE - Handle both InExpr mis-parse fix path and direct IN PARTITION path - Add Partition_ID output handling for AlterUpdate explain Fixes 02399_merge_tree_mutate_in_partition/stmt8 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a26db45 commit e471e45

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

internal/explain/statements.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,15 @@ func explainAlterCommand(sb *strings.Builder, cmd *ast.AlterCommand, indent stri
18851885
// PARTITION ALL is shown as Partition_ID (empty) in EXPLAIN AST
18861886
if ident, ok := cmd.Partition.(*ast.Identifier); ok && strings.ToUpper(ident.Name()) == "ALL" {
18871887
fmt.Fprintf(sb, "%s Partition_ID \n", indent)
1888+
} else if cmd.PartitionIsID {
1889+
// PARTITION ID 'value' is shown as Partition_ID Literal_'value' (children 1)
1890+
if lit, ok := cmd.Partition.(*ast.Literal); ok {
1891+
fmt.Fprintf(sb, "%s Partition_ID Literal_\\'%s\\' (children 1)\n", indent, lit.Value)
1892+
Node(sb, cmd.Partition, depth+2)
1893+
} else {
1894+
fmt.Fprintf(sb, "%s Partition_ID (children 1)\n", indent)
1895+
Node(sb, cmd.Partition, depth+2)
1896+
}
18881897
} else {
18891898
fmt.Fprintf(sb, "%s Partition (children 1)\n", indent)
18901899
Node(sb, cmd.Partition, depth+2)

parser/parser.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6053,7 +6053,12 @@ func (p *Parser) parseAlterCommand() *ast.AlterCommand {
60536053
if ident, ok := inExpr.List[0].(*ast.Identifier); ok && strings.ToUpper(ident.Name()) == "PARTITION" {
60546054
// Fix the mis-parse: the actual assignment value is the left side of IN
60556055
lastAssign.Value = inExpr.Expr
6056-
// Current token should be the partition expression (e.g., ALL)
6056+
// Check for PARTITION ID 'value' syntax
6057+
if p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "ID" {
6058+
p.nextToken()
6059+
cmd.PartitionIsID = true
6060+
}
6061+
// Current token should be the partition expression (e.g., ALL or '1')
60576062
cmd.Partition = p.parseExpression(LOWEST)
60586063
}
60596064
}
@@ -6062,6 +6067,11 @@ func (p *Parser) parseAlterCommand() *ast.AlterCommand {
60626067
p.nextToken() // skip IN
60636068
if p.currentIs(token.PARTITION) {
60646069
p.nextToken() // skip PARTITION
6070+
// Check for PARTITION ID 'value' syntax
6071+
if p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "ID" {
6072+
p.nextToken()
6073+
cmd.PartitionIsID = true
6074+
}
60656075
cmd.Partition = p.parseExpression(LOWEST)
60666076
}
60676077
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt8": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)