Skip to content

Commit 26617b8

Browse files
committed
Add APPLY DELETED MASK alter command support
Parse and explain ALTER TABLE ... APPLY DELETED MASK command, including optional IN PARTITION clause. Fixes stmt13 and stmt21 in 02932_apply_deleted_mask and additional tests in 02932_lwd_and_mutations and 03404_json_tables.
1 parent f3ddb56 commit 26617b8

6 files changed

Lines changed: 20 additions & 18 deletions

File tree

ast/ast.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ const (
700700
AlterModifyOrderBy AlterCommandType = "MODIFY_ORDER_BY"
701701
AlterModifySampleBy AlterCommandType = "MODIFY_SAMPLE_BY"
702702
AlterRemoveSampleBy AlterCommandType = "REMOVE_SAMPLE_BY"
703+
AlterApplyDeletedMask AlterCommandType = "APPLY_DELETED_MASK"
703704
)
704705

705706
// TruncateQuery represents a TRUNCATE statement.

internal/explain/statements.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,7 @@ func explainAlterCommand(sb *strings.Builder, cmd *ast.AlterCommand, indent stri
18021802
case ast.AlterModifySetting:
18031803
fmt.Fprintf(sb, "%s Set\n", indent)
18041804
case ast.AlterDropPartition, ast.AlterDetachPartition, ast.AlterAttachPartition,
1805-
ast.AlterReplacePartition, ast.AlterFetchPartition, ast.AlterMovePartition, ast.AlterFreezePartition, ast.AlterApplyPatches:
1805+
ast.AlterReplacePartition, ast.AlterFetchPartition, ast.AlterMovePartition, ast.AlterFreezePartition, ast.AlterApplyPatches, ast.AlterApplyDeletedMask:
18061806
if cmd.Partition != nil {
18071807
// PARTITION ALL is shown as Partition_ID (empty) in EXPLAIN AST
18081808
if ident, ok := cmd.Partition.(*ast.Identifier); ok && strings.ToUpper(ident.Name()) == "ALL" {
@@ -2085,7 +2085,7 @@ func countAlterCommandChildren(cmd *ast.AlterCommand) int {
20852085
case ast.AlterModifySetting:
20862086
children = 1
20872087
case ast.AlterDropPartition, ast.AlterDetachPartition, ast.AlterAttachPartition,
2088-
ast.AlterReplacePartition, ast.AlterFetchPartition, ast.AlterMovePartition, ast.AlterFreezePartition, ast.AlterApplyPatches:
2088+
ast.AlterReplacePartition, ast.AlterFetchPartition, ast.AlterMovePartition, ast.AlterFreezePartition, ast.AlterApplyPatches, ast.AlterApplyDeletedMask:
20892089
if cmd.Partition != nil {
20902090
children++
20912091
}

parser/parser.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5879,6 +5879,7 @@ func (p *Parser) parseAlterCommand() *ast.AlterCommand {
58795879
}
58805880
case token.APPLY:
58815881
// APPLY PATCHES IN PARTITION expr
5882+
// APPLY DELETED MASK [IN PARTITION expr]
58825883
p.nextToken() // skip APPLY
58835884
if p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "PATCHES" {
58845885
p.nextToken() // skip PATCHES
@@ -5890,6 +5891,19 @@ func (p *Parser) parseAlterCommand() *ast.AlterCommand {
58905891
cmd.Partition = p.parseExpression(LOWEST)
58915892
}
58925893
}
5894+
} else if p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "DELETED" {
5895+
p.nextToken() // skip DELETED
5896+
if p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "MASK" {
5897+
p.nextToken() // skip MASK
5898+
cmd.Type = ast.AlterApplyDeletedMask
5899+
if p.currentIs(token.IN) {
5900+
p.nextToken() // skip IN
5901+
if p.currentIs(token.PARTITION) {
5902+
p.nextToken() // skip PARTITION
5903+
cmd.Partition = p.parseExpression(LOWEST)
5904+
}
5905+
}
5906+
}
58935907
}
58945908
case token.DELETE:
58955909
// DELETE WHERE condition - mutation to delete rows
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt13": true,
4-
"stmt21": 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-
"stmt23": 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+
{}

0 commit comments

Comments
 (0)