Skip to content

Commit 4b241a1

Browse files
kyleconroyclaude
andcommitted
Add SETTINGS clause support for SYSTEM queries
Parse and explain SETTINGS for SYSTEM commands like "SYSTEM FLUSH DISTRIBUTED ... SETTINGS ...". Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent cc208ea commit 4b241a1

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

ast/ast.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,7 @@ type SystemQuery struct {
959959
Table string `json:"table,omitempty"`
960960
OnCluster string `json:"on_cluster,omitempty"`
961961
DuplicateTableOutput bool `json:"duplicate_table_output,omitempty"` // True for commands that need database/table output twice
962+
Settings []*SettingExpr `json:"settings,omitempty"`
962963
}
963964

964965
func (s *SystemQuery) Pos() token.Position { return s.Position }

internal/explain/statements.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,10 @@ func explainSystemQuery(sb *strings.Builder, n *ast.SystemQuery, indent string)
837837
children *= 2
838838
}
839839
}
840+
// Settings adds a child
841+
if len(n.Settings) > 0 {
842+
children++
843+
}
840844
if children > 0 {
841845
fmt.Fprintf(sb, "%sSYSTEM query (children %d)\n", indent, children)
842846
if n.Database != "" {
@@ -854,6 +858,10 @@ func explainSystemQuery(sb *strings.Builder, n *ast.SystemQuery, indent string)
854858
fmt.Fprintf(sb, "%s Identifier %s\n", indent, n.Table)
855859
}
856860
}
861+
// Output Set for settings
862+
if len(n.Settings) > 0 {
863+
fmt.Fprintf(sb, "%s Set\n", indent)
864+
}
857865
} else {
858866
fmt.Fprintf(sb, "%sSYSTEM query\n", indent)
859867
}

parser/parser.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7026,6 +7026,12 @@ func (p *Parser) parseSystem() *ast.SystemQuery {
70267026
}
70277027
}
70287028

7029+
// Parse optional SETTINGS clause
7030+
if p.currentIs(token.SETTINGS) {
7031+
p.nextToken() // skip SETTINGS
7032+
sys.Settings = p.parseSettingsList()
7033+
}
7034+
70297035
return sys
70307036
}
70317037

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+
{}

0 commit comments

Comments
 (0)