Skip to content

Commit e65fcd7

Browse files
committed
Fix more parser and explain output issues
- Always expand DataType parameters as children in explain output - Add HasSettings field to InsertQuery for SETTINGS clause tracking - Output Set child in InsertQuery explain when settings are present Test count: 5505 passing (up from 5488)
1 parent 55ed562 commit e65fcd7

3 files changed

Lines changed: 20 additions & 33 deletions

File tree

ast/ast.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,14 @@ func (s *SettingExpr) End() token.Position { return s.Position }
202202

203203
// InsertQuery represents an INSERT statement.
204204
type InsertQuery struct {
205-
Position token.Position `json:"-"`
206-
Database string `json:"database,omitempty"`
207-
Table string `json:"table,omitempty"`
208-
Function *FunctionCall `json:"function,omitempty"` // For INSERT INTO FUNCTION syntax
209-
Columns []*Identifier `json:"columns,omitempty"`
210-
Select Statement `json:"select,omitempty"`
211-
Format *Identifier `json:"format,omitempty"`
205+
Position token.Position `json:"-"`
206+
Database string `json:"database,omitempty"`
207+
Table string `json:"table,omitempty"`
208+
Function *FunctionCall `json:"function,omitempty"` // For INSERT INTO FUNCTION syntax
209+
Columns []*Identifier `json:"columns,omitempty"`
210+
Select Statement `json:"select,omitempty"`
211+
Format *Identifier `json:"format,omitempty"`
212+
HasSettings bool `json:"has_settings,omitempty"` // For SETTINGS clause
212213
}
213214

214215
func (i *InsertQuery) Pos() token.Position { return i.Position }

internal/explain/statements.go

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ func explainInsertQuery(sb *strings.Builder, n *ast.InsertQuery, indent string,
1818
if n.Select != nil {
1919
children++
2020
}
21+
if n.HasSettings {
22+
children++
23+
}
2124
// Note: InsertQuery uses 3 spaces after name in ClickHouse explain
2225
fmt.Fprintf(sb, "%sInsertQuery (children %d)\n", indent, children)
2326

@@ -34,6 +37,10 @@ func explainInsertQuery(sb *strings.Builder, n *ast.InsertQuery, indent string,
3437
if n.Select != nil {
3538
Node(sb, n.Select, depth+1)
3639
}
40+
41+
if n.HasSettings {
42+
fmt.Fprintf(sb, "%s Set\n", indent)
43+
}
3744
}
3845

3946
func explainCreateQuery(sb *strings.Builder, n *ast.CreateQuery, indent string, depth int) {
@@ -168,37 +175,15 @@ func explainDescribeQuery(sb *strings.Builder, n *ast.DescribeQuery, indent stri
168175
}
169176

170177
func explainDataType(sb *strings.Builder, n *ast.DataType, indent string, depth int) {
171-
// Check if type has nested DataType parameters that should be expanded
172-
hasNestedTypes := false
173-
for _, p := range n.Parameters {
174-
if _, ok := p.(*ast.DataType); ok {
175-
hasNestedTypes = true
176-
break
177-
}
178-
}
179-
180-
// Check if type has complex parameters (expressions, not just literals/types)
181-
hasComplexParams := false
182-
for _, p := range n.Parameters {
183-
if _, ok := p.(*ast.Literal); ok {
184-
continue
185-
}
186-
if _, ok := p.(*ast.DataType); ok {
187-
continue
188-
}
189-
hasComplexParams = true
190-
break
191-
}
192-
193-
if (hasNestedTypes || hasComplexParams) && len(n.Parameters) > 0 {
194-
// Nested types and complex parameters need to be output as children
178+
// If type has parameters, expand them as children
179+
if len(n.Parameters) > 0 {
195180
fmt.Fprintf(sb, "%sDataType %s (children %d)\n", indent, n.Name, 1)
196181
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, len(n.Parameters))
197182
for _, p := range n.Parameters {
198183
Node(sb, p, depth+2)
199184
}
200185
} else {
201-
fmt.Fprintf(sb, "%sDataType %s\n", indent, FormatDataType(n))
186+
fmt.Fprintf(sb, "%sDataType %s\n", indent, n.Name)
202187
}
203188
}
204189

parser/parser.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,8 +880,9 @@ func (p *Parser) parseInsert() *ast.InsertQuery {
880880
p.expect(token.RPAREN)
881881
}
882882

883-
// Parse SETTINGS before VALUES (skip for now as it's not in AST)
883+
// Parse SETTINGS before VALUES
884884
if p.currentIs(token.SETTINGS) {
885+
ins.HasSettings = true
885886
p.nextToken()
886887
// Just parse and skip the settings
887888
p.parseSettingsList()

0 commit comments

Comments
 (0)