Skip to content

Commit 353708c

Browse files
kyleconroyclaude
andcommitted
Parse and output COMMENT clause for CREATE DICTIONARY
COMMENT was being parsed as token.COMMENT but the dictionary parsing loop only handled PRIMARY and SETTINGS as keyword tokens. Added handling for token.COMMENT in the loop and output the comment as a Literal in the EXPLAIN AST. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d7b6e81 commit 353708c

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

internal/explain/statements.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func explainCreateQuery(sb *strings.Builder, n *ast.CreateQuery, indent string,
156156
return
157157
}
158158
if n.CreateDictionary {
159-
// Dictionary: count children = database identifier (if any) + table identifier + attributes (if any) + definition (if any)
159+
// Dictionary: count children = database identifier (if any) + table identifier + attributes (if any) + definition (if any) + comment (if any)
160160
children := 1 // table identifier
161161
hasDatabase := n.Database != ""
162162
if hasDatabase {
@@ -168,6 +168,9 @@ func explainCreateQuery(sb *strings.Builder, n *ast.CreateQuery, indent string,
168168
if n.DictionaryDef != nil {
169169
children++
170170
}
171+
if n.Comment != "" {
172+
children++
173+
}
171174
// Format: "CreateQuery [database] [table] (children N)"
172175
if hasDatabase {
173176
fmt.Fprintf(sb, "%sCreateQuery %s %s (children %d)\n", indent, n.Database, n.Table, children)
@@ -187,6 +190,10 @@ func explainCreateQuery(sb *strings.Builder, n *ast.CreateQuery, indent string,
187190
if n.DictionaryDef != nil {
188191
explainDictionaryDefinition(sb, n.DictionaryDef, indent+" ", depth+1)
189192
}
193+
// Dictionary COMMENT
194+
if n.Comment != "" {
195+
fmt.Fprintf(sb, "%s Literal \\'%s\\'\n", indent, n.Comment)
196+
}
190197
return
191198
}
192199

parser/parser.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3890,6 +3890,15 @@ func (p *Parser) parseCreateDictionary(create *ast.CreateQuery) {
38903890
}
38913891
continue
38923892
}
3893+
// Handle COMMENT as a keyword token
3894+
if p.currentIs(token.COMMENT) {
3895+
p.nextToken() // skip COMMENT
3896+
if p.currentIs(token.STRING) {
3897+
create.Comment = p.current.Value
3898+
p.nextToken()
3899+
}
3900+
continue
3901+
}
38933902
if p.currentIs(token.IDENT) {
38943903
upper := strings.ToUpper(p.current.Value)
38953904
switch upper {
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt5": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)