Skip to content

Commit 5bf1341

Browse files
committed
Add support for ALTER TABLE MODIFY SAMPLE BY
- Add AlterModifySampleBy type in ast/ast.go - Add SampleByExpr field to AlterCommand struct - Add parsing for MODIFY SAMPLE BY in parseAlterCommand - Add EXPLAIN output for MODIFY_SAMPLE_BY Fixes 5 statements in 01430_modify_sample_by_zookeeper_long plus 1 bonus test (02096_sample_by_tuple).
1 parent 55eba98 commit 5bf1341

5 files changed

Lines changed: 22 additions & 14 deletions

File tree

ast/ast.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ type AlterCommand struct {
599599
StatisticsTypes []*FunctionCall `json:"statistics_types,omitempty"` // For ADD/MODIFY STATISTICS TYPE
600600
Comment string `json:"comment,omitempty"` // For COMMENT COLUMN
601601
OrderByExpr []Expression `json:"order_by_expr,omitempty"` // For MODIFY ORDER BY
602+
SampleByExpr Expression `json:"sample_by_expr,omitempty"` // For MODIFY SAMPLE BY
602603
ResetSettings []string `json:"reset_settings,omitempty"` // For MODIFY COLUMN ... RESET SETTING
603604
}
604605

@@ -675,6 +676,7 @@ const (
675676
AlterMaterializeStatistics AlterCommandType = "MATERIALIZE_STATISTICS"
676677
AlterModifyComment AlterCommandType = "MODIFY_COMMENT"
677678
AlterModifyOrderBy AlterCommandType = "MODIFY_ORDER_BY"
679+
AlterModifySampleBy AlterCommandType = "MODIFY_SAMPLE_BY"
678680
AlterRemoveSampleBy AlterCommandType = "REMOVE_SAMPLE_BY"
679681
)
680682

internal/explain/statements.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,11 @@ func explainAlterCommand(sb *strings.Builder, cmd *ast.AlterCommand, indent stri
15161516
Node(sb, expr, depth+1)
15171517
}
15181518
}
1519+
case ast.AlterModifySampleBy:
1520+
// Single expression - output directly
1521+
if cmd.SampleByExpr != nil {
1522+
Node(sb, cmd.SampleByExpr, depth+1)
1523+
}
15191524
default:
15201525
if cmd.Partition != nil {
15211526
Node(sb, cmd.Partition, depth+1)
@@ -1747,6 +1752,11 @@ func countAlterCommandChildren(cmd *ast.AlterCommand) int {
17471752
if len(cmd.OrderByExpr) > 0 {
17481753
children = 1
17491754
}
1755+
case ast.AlterModifySampleBy:
1756+
// MODIFY SAMPLE BY: single expression (1 child)
1757+
if cmd.SampleByExpr != nil {
1758+
children = 1
1759+
}
17501760
default:
17511761
if cmd.Partition != nil {
17521762
children++

parser/parser.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5023,6 +5023,14 @@ func (p *Parser) parseAlterCommand() *ast.AlterCommand {
50235023
// Single expression without parentheses
50245024
cmd.OrderByExpr = []ast.Expression{p.parseExpression(LOWEST)}
50255025
}
5026+
} else if p.currentIs(token.SAMPLE) {
5027+
// MODIFY SAMPLE BY expr
5028+
cmd.Type = ast.AlterModifySampleBy
5029+
p.nextToken() // skip SAMPLE
5030+
if p.currentIs(token.BY) {
5031+
p.nextToken() // skip BY
5032+
}
5033+
cmd.SampleByExpr = p.parseExpression(LOWEST)
50265034
}
50275035
case token.RENAME:
50285036
p.nextToken()
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt12": true,
4-
"stmt17": true,
5-
"stmt18": true,
6-
"stmt25": true,
7-
"stmt7": true
8-
}
9-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt4": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)