Skip to content

Commit a812844

Browse files
committed
Improve the CREATE DIRECTORY format
1 parent bf5be12 commit a812844

4 files changed

Lines changed: 26 additions & 24 deletions

File tree

parser/format.go

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -756,17 +756,17 @@ func (c *CreateDictionary) FormatSQL(formatter *Formatter) {
756756
formatter.WriteExpr(c.Name)
757757

758758
if c.UUID != nil {
759-
formatter.WriteByte(whitespace)
759+
formatter.Break()
760760
formatter.WriteExpr(c.UUID)
761761
}
762762

763763
if c.OnCluster != nil {
764-
formatter.WriteByte(whitespace)
764+
formatter.Break()
765765
formatter.WriteExpr(c.OnCluster)
766766
}
767767

768768
if c.Schema != nil {
769-
formatter.WriteByte(whitespace)
769+
formatter.Break()
770770
formatter.WriteExpr(c.Schema)
771771
}
772772

@@ -1183,35 +1183,32 @@ func (d *DictionaryAttribute) FormatSQL(formatter *Formatter) {
11831183
}
11841184

11851185
func (d *DictionaryEngineClause) FormatSQL(formatter *Formatter) {
1186+
needsBreak := false
1187+
breakAndWrite := func(expr Expr) {
1188+
if needsBreak {
1189+
formatter.Break()
1190+
}
1191+
formatter.WriteExpr(expr)
1192+
needsBreak = true
1193+
}
1194+
11861195
if d.PrimaryKey != nil {
1187-
formatter.WriteExpr(d.PrimaryKey)
1196+
breakAndWrite(d.PrimaryKey)
11881197
}
11891198
if d.Source != nil {
1190-
if d.PrimaryKey != nil {
1191-
formatter.Break()
1192-
}
1193-
formatter.WriteExpr(d.Source)
1199+
breakAndWrite(d.Source)
11941200
}
11951201
if d.Lifetime != nil {
1196-
if d.PrimaryKey != nil || d.Source != nil {
1197-
formatter.Break()
1198-
}
1199-
formatter.WriteExpr(d.Lifetime)
1202+
breakAndWrite(d.Lifetime)
12001203
}
12011204
if d.Layout != nil {
1202-
if d.PrimaryKey != nil || d.Source != nil || d.Lifetime != nil {
1203-
formatter.Break()
1204-
}
1205-
formatter.WriteExpr(d.Layout)
1205+
breakAndWrite(d.Layout)
12061206
}
12071207
if d.Range != nil {
1208-
if d.PrimaryKey != nil || d.Source != nil || d.Lifetime != nil || d.Layout != nil {
1209-
formatter.Break()
1210-
}
1211-
formatter.WriteExpr(d.Range)
1208+
breakAndWrite(d.Range)
12121209
}
12131210
if d.Settings != nil {
1214-
if d.PrimaryKey != nil || d.Source != nil || d.Lifetime != nil || d.Layout != nil || d.Range != nil {
1211+
if needsBreak {
12151212
formatter.Break()
12161213
}
12171214
formatter.WriteString("SETTINGS(")

parser/testdata/ddl/format/beautify/create_dictionary_basic.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ LAYOUT(HASHED())
2121
SETTINGS(max_block_size = 8192);
2222

2323
-- Beautify SQL:
24-
CREATE DICTIONARY test.my_dict (
24+
CREATE DICTIONARY test.my_dict
25+
(
2526
id UInt64,
2627
name String DEFAULT '',
2728
value Float64 EXPRESSION toFloat64OrZero(name),

parser/testdata/ddl/format/beautify/create_dictionary_comprehensive.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ LAYOUT(HASHED())
2424
SETTINGS(max_block_size = 8192, max_insert_block_size = 1048576);
2525

2626
-- Beautify SQL:
27-
CREATE OR REPLACE DICTIONARY test.comprehensive_dict UUID '12345678-1234-1234-1234-123456789012' ON CLUSTER production_cluster (
27+
CREATE OR REPLACE DICTIONARY test.comprehensive_dict
28+
UUID '12345678-1234-1234-1234-123456789012'
29+
ON CLUSTER production_cluster
30+
(
2831
id UInt64,
2932
name String DEFAULT '',
3033
value Float64 EXPRESSION toFloat64OrZero(name),

parser/testdata/ddl/format/beautify/create_dictionary_with_comment.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ COMMENT 'This is a test dictionary with comment';
2323

2424

2525
-- Beautify SQL:
26-
CREATE DICTIONARY test.my_dict (
26+
CREATE DICTIONARY test.my_dict
27+
(
2728
id UInt64,
2829
name String DEFAULT '',
2930
value Float64 EXPRESSION toFloat64OrZero(name),

0 commit comments

Comments
 (0)