Skip to content

Commit 77accb4

Browse files
committed
Fix NULL casing and Enum type parameter handling
- Change NULL literal output from 'Null' to 'NULL' (uppercase) - Fix DataType with complex parameters (like Enum) to output as children with ExpressionList instead of formatted string - Update Column function to use Node() for type output Tests passing: 5179 (up from 5128)
1 parent 9d774d2 commit 77accb4

3 files changed

Lines changed: 27 additions & 5 deletions

File tree

internal/explain/explain.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func Node(sb *strings.Builder, node interface{}, depth int) {
116116

117117
// Types
118118
case *ast.DataType:
119-
explainDataType(sb, n, indent)
119+
explainDataType(sb, n, indent, depth)
120120
case *ast.Parameter:
121121
explainParameter(sb, n, indent)
122122

@@ -165,7 +165,7 @@ func Column(sb *strings.Builder, col *ast.ColumnDeclaration, depth int) {
165165
}
166166
fmt.Fprintf(sb, "%sColumnDeclaration %s (children %d)\n", indent, col.Name, children)
167167
if col.Type != nil {
168-
fmt.Fprintf(sb, "%s DataType %s\n", indent, FormatDataType(col.Type))
168+
Node(sb, col.Type, depth+1)
169169
}
170170
if col.Default != nil {
171171
Node(sb, col.Default, depth+1)

internal/explain/format.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func FormatLiteral(lit *ast.Literal) string {
3030
}
3131
return "UInt8_0"
3232
case ast.LiteralNull:
33-
return "Null"
33+
return "NULL"
3434
case ast.LiteralArray:
3535
return formatArrayLiteral(lit.Value)
3636
case ast.LiteralTuple:

internal/explain/statements.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,30 @@ func explainDescribeQuery(sb *strings.Builder, n *ast.DescribeQuery, indent stri
138138
fmt.Fprintf(sb, "%sDescribe %s\n", indent, name)
139139
}
140140

141-
func explainDataType(sb *strings.Builder, n *ast.DataType, indent string) {
142-
fmt.Fprintf(sb, "%sDataType %s\n", indent, FormatDataType(n))
141+
func explainDataType(sb *strings.Builder, n *ast.DataType, indent string, depth int) {
142+
// Check if type has complex parameters (expressions, not just literals/types)
143+
hasComplexParams := false
144+
for _, p := range n.Parameters {
145+
if _, ok := p.(*ast.Literal); ok {
146+
continue
147+
}
148+
if _, ok := p.(*ast.DataType); ok {
149+
continue
150+
}
151+
hasComplexParams = true
152+
break
153+
}
154+
155+
if hasComplexParams && len(n.Parameters) > 0 {
156+
// Complex parameters need to be output as children
157+
fmt.Fprintf(sb, "%sDataType %s (children %d)\n", indent, n.Name, 1)
158+
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, len(n.Parameters))
159+
for _, p := range n.Parameters {
160+
Node(sb, p, depth+2)
161+
}
162+
} else {
163+
fmt.Fprintf(sb, "%sDataType %s\n", indent, FormatDataType(n))
164+
}
143165
}
144166

145167
func explainParameter(sb *strings.Builder, n *ast.Parameter, indent string) {

0 commit comments

Comments
 (0)