Skip to content

Commit 1b7808a

Browse files
committed
Handle ATTACH PARTITION ... FROM as REPLACE_PARTITION in EXPLAIN
Parse the FROM clause in ALTER TABLE ATTACH PARTITION statements and show it as REPLACE_PARTITION in EXPLAIN AST output to match ClickHouse's behavior. Fixes multiple tests across several test files.
1 parent 26617b8 commit 1b7808a

8 files changed

Lines changed: 17 additions & 28 deletions

File tree

internal/explain/statements.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,10 @@ func explainAlterCommand(sb *strings.Builder, cmd *ast.AlterCommand, indent stri
16201620
if cmdType == ast.AlterClearStatistics {
16211621
cmdType = ast.AlterDropStatistics
16221622
}
1623+
// ATTACH PARTITION ... FROM table is shown as REPLACE_PARTITION in EXPLAIN AST
1624+
if cmdType == ast.AlterAttachPartition && cmd.FromTable != "" {
1625+
cmdType = ast.AlterReplacePartition
1626+
}
16231627
// DETACH_PARTITION is shown as DROP_PARTITION in EXPLAIN AST
16241628
if cmdType == ast.AlterDetachPartition {
16251629
cmdType = ast.AlterDropPartition

parser/parser.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5817,6 +5817,14 @@ func (p *Parser) parseAlterCommand() *ast.AlterCommand {
58175817
cmd.PartitionIsID = true
58185818
}
58195819
cmd.Partition = p.parseExpression(LOWEST)
5820+
// Handle FROM table (ATTACH PARTITION ... FROM table)
5821+
if p.currentIs(token.FROM) {
5822+
p.nextToken()
5823+
if p.currentIs(token.IDENT) || p.current.Token.IsKeyword() {
5824+
cmd.FromTable = p.current.Value
5825+
p.nextToken()
5826+
}
5827+
}
58205828
} else if p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "PART" {
58215829
// ATTACH PART uses ATTACH_PARTITION type in ClickHouse EXPLAIN
58225830
cmd.Type = ast.AlterAttachPartition
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt44": true,
4-
"stmt46": 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-
"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-
"stmt20": true,
43
"stmt33": 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-
"stmt6": 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-
"stmt31": true,
4-
"stmt34": 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-
"stmt11": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)