Skip to content

Commit 6d0175c

Browse files
Copilotgit-hulk
andauthored
Add line break and indentation to FROM clause formatting (#244)
--------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: git-hulk <4987594+git-hulk@users.noreply.github.com>
1 parent 50c0046 commit 6d0175c

62 files changed

Lines changed: 241 additions & 153 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

parser/format.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ func (f *Formatter) WriteExpr(expr Expr) {
7171
expr.FormatSQL(f)
7272
}
7373

74-
7574
func (f *Formatter) NewLine() {
7675
if f.mode != FormatModeBeautify {
7776
return
@@ -1436,8 +1435,11 @@ func (f *FormatClause) FormatSQL(formatter *Formatter) {
14361435
}
14371436

14381437
func (f *FromClause) FormatSQL(formatter *Formatter) {
1439-
formatter.WriteString("FROM ")
1438+
formatter.WriteString("FROM")
1439+
formatter.Indent()
1440+
formatter.Break()
14401441
formatter.WriteExpr(f.Expr)
1442+
formatter.Dedent()
14411443
}
14421444

14431445
func (f *FunctionExpr) FormatSQL(formatter *Formatter) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS db.table ON CLUSTER 'default_cluster' TO
3030
visitParamExtractString(properties, 'd') AS d,
3131
visitParamExtractInt(properties, 'e') AS e,
3232
visitParamExtractInt(properties, 'f') AS f
33-
FROM db.table
33+
FROM
34+
db.table
3435
WHERE
3536
db.table.event = 'hello';

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ CREATE LIVE VIEW my_live_view WITH TIMEOUT 10 TO my_destination (
99
id String
1010
) AS SELECT
1111
id
12-
FROM my_table;
12+
FROM
13+
my_table;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ CREATE MATERIALIZED VIEW infra_bm.view_name ON CLUSTER 'default_cluster' TO infr
3737
visitParamExtractString(properties, 'f4') AS f4,
3838
visitParamExtractString(properties, 'f5') AS f5,
3939
visitParamExtractInt(properties, 'f6') AS f6
40-
FROM infra_bm.table_name1
40+
FROM
41+
infra_bm.table_name1
4142
WHERE
4243
infra_bm.table_name1.event = 'test-event' COMMENT 'Comment for table';

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,18 @@ PARTITION BY toYYYYMM(f0) POPULATE AS SELECT
2525
f1,
2626
f2,
2727
coalesce(f0, f1) AS f333
28-
FROM (SELECT
29-
f0,
30-
f1,
31-
f2,
32-
ROW_NUMBER() OVER (PARTITION BY f0 ORDER BY
33-
coalesce(f1, f2)) AS rn
34-
FROM test.t
35-
WHERE
36-
f3 IN ('foo', 'bar', 'test')
37-
AND
38-
env = 'test') AS tmp
28+
FROM
29+
(SELECT
30+
f0,
31+
f1,
32+
f2,
33+
ROW_NUMBER() OVER (PARTITION BY f0 ORDER BY
34+
coalesce(f1, f2)) AS rn
35+
FROM
36+
test.t
37+
WHERE
38+
f3 IN ('foo', 'bar', 'test')
39+
AND
40+
env = 'test') AS tmp
3941
WHERE
4042
rn = 1;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ CREATE MATERIALIZED VIEW database_name.view_name
66
-- Beautify SQL:
77
CREATE MATERIALIZED VIEW database_name.view_name REFRESH EVERY 5 MINUTE TO database_name.table_name AS SELECT
88
*
9-
FROM gcs(gcs_creds, url='https://storage.googleapis.com/some-bucket/some-path/');
9+
FROM
10+
gcs(gcs_creds, url='https://storage.googleapis.com/some-bucket/some-path/');

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ CREATE MATERIALIZED VIEW infra_bm.view_name ON CLUSTER 'default_cluster' TO infr
3434
visitParamExtractString(properties, 'f4') AS f4,
3535
visitParamExtractString(properties, 'f5') AS f5,
3636
visitParamExtractInt(properties, 'f6') AS f6
37-
FROM infra_bm.table_name1
37+
FROM
38+
infra_bm.table_name1
3839
WHERE
3940
infra_bm.table_name1.event = 'test-event'
4041
AND

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ ORDER BY
1919
(id)
2020
PRIMARY KEY (id) AS SELECT
2121
*
22-
FROM test_table;
22+
FROM
23+
test_table;
2324
CREATE MATERIALIZED VIEW IF NOT EXISTS test_mv
2425
ENGINE = ReplacingMergeTree()
2526
PRIMARY KEY (id) AS SELECT
2627
*
27-
FROM test_table;
28+
FROM
29+
test_table;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ CREATE OR REPLACE VIEW IF NOT EXISTS my_view (
4545
) AS SELECT
4646
id,
4747
name
48-
FROM my_table;
48+
FROM
49+
my_table;
4950
CREATE OR REPLACE FUNCTION IF NOT EXISTS my_function AS (x, y) -> x + y;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ CREATE VIEW IF NOT EXISTS my_view (
1414
) AS SELECT
1515
id,
1616
name
17-
FROM my_table;
17+
FROM
18+
my_table;

0 commit comments

Comments
 (0)