Skip to content

Commit da36378

Browse files
committed
Add FETCH PARTITION support and fix PARTITION ALL child count
- Add AlterFetchPartition and AlterMovePartition types to AST - Add FromPath field to AlterCommand for FETCH PARTITION FROM - Implement FETCH PARTITION parsing in parseAlterCommand - Fix children count for PARTITION ALL (now counts as 1 child) - Add explain support for FETCH_PARTITION and MOVE_PARTITION Fixes stmt42 in 00753_alter_attach and other FETCH PARTITION tests.
1 parent 4f3870c commit da36378

9 files changed

Lines changed: 25 additions & 38 deletions

File tree

ast/ast.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ type AlterCommand struct {
529529
ConstraintName string `json:"constraint_name,omitempty"`
530530
Partition Expression `json:"partition,omitempty"`
531531
FromTable string `json:"from_table,omitempty"`
532+
FromPath string `json:"from_path,omitempty"` // For FETCH PARTITION FROM
532533
TTL *TTLClause `json:"ttl,omitempty"`
533534
Settings []*SettingExpr `json:"settings,omitempty"`
534535
Where Expression `json:"where,omitempty"` // For DELETE WHERE
@@ -593,6 +594,8 @@ const (
593594
AlterDetachPartition AlterCommandType = "DETACH_PARTITION"
594595
AlterAttachPartition AlterCommandType = "ATTACH_PARTITION"
595596
AlterReplacePartition AlterCommandType = "REPLACE_PARTITION"
597+
AlterFetchPartition AlterCommandType = "FETCH_PARTITION"
598+
AlterMovePartition AlterCommandType = "MOVE_PARTITION"
596599
AlterFreezePartition AlterCommandType = "FREEZE_PARTITION"
597600
AlterFreeze AlterCommandType = "FREEZE"
598601
AlterDeleteWhere AlterCommandType = "DELETE_WHERE"

internal/explain/statements.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ func explainAlterCommand(sb *strings.Builder, cmd *ast.AlterCommand, indent stri
10911091
case ast.AlterModifySetting:
10921092
fmt.Fprintf(sb, "%s Set\n", indent)
10931093
case ast.AlterDropPartition, ast.AlterDetachPartition, ast.AlterAttachPartition,
1094-
ast.AlterReplacePartition, ast.AlterFreezePartition:
1094+
ast.AlterReplacePartition, ast.AlterFetchPartition, ast.AlterMovePartition, ast.AlterFreezePartition:
10951095
if cmd.Partition != nil {
10961096
// PARTITION ALL is shown as Partition_ID (empty) in EXPLAIN AST
10971097
if ident, ok := cmd.Partition.(*ast.Identifier); ok && strings.ToUpper(ident.Name()) == "ALL" {
@@ -1284,12 +1284,9 @@ func countAlterCommandChildren(cmd *ast.AlterCommand) int {
12841284
case ast.AlterModifySetting:
12851285
children = 1
12861286
case ast.AlterDropPartition, ast.AlterDetachPartition, ast.AlterAttachPartition,
1287-
ast.AlterReplacePartition, ast.AlterFreezePartition:
1287+
ast.AlterReplacePartition, ast.AlterFetchPartition, ast.AlterMovePartition, ast.AlterFreezePartition:
12881288
if cmd.Partition != nil {
1289-
// PARTITION ALL doesn't count as a child (shown as Partition_ID empty)
1290-
if ident, ok := cmd.Partition.(*ast.Identifier); !ok || strings.ToUpper(ident.Name()) != "ALL" {
1291-
children++
1292-
}
1289+
children++
12931290
}
12941291
case ast.AlterFreeze:
12951292
// No children

parser/parser.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4179,6 +4179,21 @@ func (p *Parser) parseAlterCommand() *ast.AlterCommand {
41794179
}
41804180
}
41814181
}
4182+
case token.FETCH:
4183+
p.nextToken()
4184+
if p.currentIs(token.PARTITION) {
4185+
cmd.Type = ast.AlterFetchPartition
4186+
p.nextToken()
4187+
cmd.Partition = p.parseExpression(LOWEST)
4188+
// FROM path
4189+
if p.currentIs(token.FROM) {
4190+
p.nextToken()
4191+
if p.currentIs(token.STRING) {
4192+
cmd.FromPath = p.current.Value
4193+
p.nextToken()
4194+
}
4195+
}
4196+
}
41824197
case token.DELETE:
41834198
// DELETE WHERE condition - mutation to delete rows
41844199
cmd.Type = ast.AlterDeleteWhere
Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,9 @@
11
{
22
"explain_todo": {
3-
"stmt14": true,
4-
"stmt22": true,
5-
"stmt34": true,
6-
"stmt42": true,
7-
"stmt51": true,
83
"stmt52": true,
94
"stmt53": true,
105
"stmt54": true,
116
"stmt55": true,
12-
"stmt56": true,
13-
"stmt58": true,
14-
"stmt63": true,
15-
"stmt65": true,
16-
"stmt69": true,
17-
"stmt71": true,
18-
"stmt73": true,
19-
"stmt77": true,
20-
"stmt79": true,
21-
"stmt83": true,
22-
"stmt85": true,
23-
"stmt87": true
7+
"stmt58": true
248
}
259
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"explain_todo": {
33
"stmt5": true,
4-
"stmt7": true,
5-
"stmt9": true
4+
"stmt7": true
65
}
76
}

parser/testdata/01166_truncate_multiple_partitions/metadata.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
"stmt10": true,
44
"stmt11": true,
55
"stmt17": true,
6-
"stmt20": true,
76
"stmt22": true,
87
"stmt23": true,
98
"stmt24": true,
109
"stmt25": true,
1110
"stmt3": true,
12-
"stmt6": true,
1311
"stmt8": true,
1412
"stmt9": true
1513
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt6": true
4-
}
5-
}
1+
{}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"explain_todo": {
3-
"stmt5": true,
43
"stmt7": true
54
}
65
}
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)