Skip to content

Commit a960bd7

Browse files
committed
Add MOVE PARTITION and fix OPTIMIZE TABLE database name
- Added MOVE PARTITION ... TO TABLE parsing in ALTER statements - Added ToDatabase and ToTable fields to AlterCommand for destination - Fixed OPTIMIZE TABLE to output database identifier for qualified names
1 parent b1cea52 commit a960bd7

File tree

13 files changed

+50
-50
lines changed

13 files changed

+50
-50
lines changed

ast/ast.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,9 @@ type AlterCommand struct {
578578
Partition Expression `json:"partition,omitempty"`
579579
PartitionIsID bool `json:"partition_is_id,omitempty"` // True when using PARTITION ID 'value' syntax
580580
FromTable string `json:"from_table,omitempty"`
581-
FromPath string `json:"from_path,omitempty"` // For FETCH PARTITION FROM
581+
ToDatabase string `json:"to_database,omitempty"` // For MOVE PARTITION TO TABLE
582+
ToTable string `json:"to_table,omitempty"` // For MOVE PARTITION TO TABLE
583+
FromPath string `json:"from_path,omitempty"` // For FETCH PARTITION FROM
582584
TTL *TTLClause `json:"ttl,omitempty"`
583585
Settings []*SettingExpr `json:"settings,omitempty"`
584586
Where Expression `json:"where,omitempty"` // For DELETE WHERE

internal/explain/statements.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1610,15 +1610,26 @@ func explainOptimizeQuery(sb *strings.Builder, n *ast.OptimizeQuery, indent stri
16101610
}
16111611

16121612
children := 1 // identifier
1613+
if n.Database != "" {
1614+
children++ // extra identifier for database
1615+
}
16131616
if n.Partition != nil {
16141617
children++
16151618
}
16161619

1617-
fmt.Fprintf(sb, "%sOptimizeQuery %s (children %d)\n", indent, name, children)
1620+
if n.Database != "" {
1621+
// Database-qualified: OptimizeQuery db table (children N)
1622+
fmt.Fprintf(sb, "%sOptimizeQuery %s %s (children %d)\n", indent, n.Database, name, children)
1623+
} else {
1624+
fmt.Fprintf(sb, "%sOptimizeQuery %s (children %d)\n", indent, name, children)
1625+
}
16181626
if n.Partition != nil {
16191627
fmt.Fprintf(sb, "%s Partition (children 1)\n", indent)
16201628
Node(sb, n.Partition, depth+2)
16211629
}
1630+
if n.Database != "" {
1631+
fmt.Fprintf(sb, "%s Identifier %s\n", indent, n.Database)
1632+
}
16221633
fmt.Fprintf(sb, "%s Identifier %s\n", indent, n.Table)
16231634
}
16241635

parser/parser.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4712,6 +4712,34 @@ func (p *Parser) parseAlterCommand() *ast.AlterCommand {
47124712
cmd.Type = ast.AlterMaterializeTTL
47134713
p.nextToken()
47144714
}
4715+
} else if upper == "MOVE" {
4716+
p.nextToken()
4717+
if p.currentIs(token.PARTITION) {
4718+
cmd.Type = ast.AlterMovePartition
4719+
p.nextToken()
4720+
// Check for PARTITION ID 'value' syntax
4721+
if p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "ID" {
4722+
p.nextToken()
4723+
cmd.PartitionIsID = true
4724+
}
4725+
cmd.Partition = p.parseExpression(LOWEST)
4726+
// Parse TO TABLE destination
4727+
if p.currentIs(token.TO) {
4728+
p.nextToken()
4729+
if p.currentIs(token.TABLE) {
4730+
p.nextToken()
4731+
}
4732+
// Parse destination table (can be qualified: database.table)
4733+
destName := p.parseIdentifierName()
4734+
if p.currentIs(token.DOT) {
4735+
p.nextToken()
4736+
cmd.ToDatabase = destName
4737+
cmd.ToTable = p.parseIdentifierName()
4738+
} else {
4739+
cmd.ToTable = destName
4740+
}
4741+
}
4742+
}
47154743
} else {
47164744
return nil
47174745
}

parser/testdata/00753_alter_attach/metadata.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"explain_todo": {
3-
"stmt52": true,
43
"stmt53": true,
54
"stmt54": true,
65
"stmt55": true,
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt11": 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-
"stmt16": 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-
"stmt11": true
4-
}
5-
}
1+
{}

parser/testdata/02486_truncate_and_unexpected_parts/metadata.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"explain_todo": {
33
"stmt24": true,
4-
"stmt26": true,
54
"stmt43": true,
65
"stmt44": true
76
}
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt22": true,
4-
"stmt23": true,
5-
"stmt24": true,
6-
"stmt25": true,
7-
"stmt26": true,
8-
"stmt27": true,
9-
"stmt28": true
10-
}
11-
}
1+
{}
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt19": true,
4-
"stmt22": true,
5-
"stmt23": true
6-
}
7-
}
1+
{}

0 commit comments

Comments
 (0)