Skip to content

Commit 0855448

Browse files
kyleconroyclaude
andcommitted
Parse dictionary SETTINGS clause and output as Dictionary settings
Add proper parsing for SETTINGS clause in CREATE DICTIONARY statements. Handle SETTINGS as a keyword token (not IDENT). Changes: - Add SETTINGS keyword handling in dictionary definition parsing - Parse settings with or without parentheses - Output as "Dictionary settings" (not "Set") in explain - Update condition to include Settings in dictionary definition check - Fixes 01268_dictionary_direct_layout stmt25, stmt26 - Also fixes: 01259_dictionary_custom_settings_ddl stmt6, 01676_range_hashed_dictionary stmt5, 01681_cache_dictionary_simple_key stmt7, 01760_polygon_dictionaries stmt17, 01765_hashed_dictionary_simple_key stmt7 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 28717df commit 0855448

File tree

8 files changed

+28
-36
lines changed

8 files changed

+28
-36
lines changed

internal/explain/dictionary.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func explainDictionaryDefinition(sb *strings.Builder, n *ast.DictionaryDefinitio
9292

9393
// SETTINGS
9494
if len(n.Settings) > 0 {
95-
fmt.Fprintf(sb, "%s Set\n", indent)
95+
fmt.Fprintf(sb, "%s Dictionary settings\n", indent)
9696
}
9797
}
9898

parser/parser.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3850,6 +3850,19 @@ func (p *Parser) parseCreateDictionary(create *ast.CreateQuery) {
38503850
}
38513851
continue
38523852
}
3853+
// Handle SETTINGS as a keyword token
3854+
if p.currentIs(token.SETTINGS) {
3855+
p.nextToken() // skip SETTINGS
3856+
// Parse dictionary settings: SETTINGS(key=value, ...) or SETTINGS key=value, ...
3857+
if p.currentIs(token.LPAREN) {
3858+
p.nextToken() // skip (
3859+
dictDef.Settings = p.parseSettingsList()
3860+
p.expect(token.RPAREN)
3861+
} else {
3862+
dictDef.Settings = p.parseSettingsList()
3863+
}
3864+
continue
3865+
}
38533866
if p.currentIs(token.IDENT) {
38543867
upper := strings.ToUpper(p.current.Value)
38553868
switch upper {
@@ -3873,9 +3886,13 @@ func (p *Parser) parseCreateDictionary(create *ast.CreateQuery) {
38733886
dictDef.Range = p.parseDictionaryRange()
38743887
case "SETTINGS":
38753888
p.nextToken() // skip SETTINGS
3876-
// Skip settings for now
3877-
for !p.currentIs(token.EOF) && !p.currentIs(token.SEMICOLON) && !p.isDictionaryClauseKeyword() {
3878-
p.nextToken()
3889+
// Parse dictionary settings: SETTINGS(key=value, ...) or SETTINGS key=value, ...
3890+
if p.currentIs(token.LPAREN) {
3891+
p.nextToken() // skip (
3892+
dictDef.Settings = p.parseSettingsList()
3893+
p.expect(token.RPAREN)
3894+
} else {
3895+
dictDef.Settings = p.parseSettingsList()
38793896
}
38803897
case "COMMENT":
38813898
p.nextToken() // skip COMMENT
@@ -3892,7 +3909,7 @@ func (p *Parser) parseCreateDictionary(create *ast.CreateQuery) {
38923909
}
38933910

38943911
// Only set dictionary definition if it has any content
3895-
if len(dictDef.PrimaryKey) > 0 || dictDef.Source != nil || dictDef.Lifetime != nil || dictDef.Layout != nil || dictDef.Range != nil {
3912+
if len(dictDef.PrimaryKey) > 0 || dictDef.Source != nil || dictDef.Lifetime != nil || dictDef.Layout != nil || dictDef.Range != nil || len(dictDef.Settings) > 0 {
38963913
create.DictionaryDef = dictDef
38973914
}
38983915
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt6": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt25": true,
4-
"stmt26": true
5-
}
6-
}
1+
{}
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+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt7": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt17": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt7": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)