Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions parser/parser_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,9 @@ func (p *Parser) parseSelectItems() ([]*SelectItem, error) {
if p.tryConsumeTokenKind(TokenKindComma) == nil {
break
}
if p.isSelectItemTerminatorKeyword() {
break
}
}
return selectItems, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ AS
(SELECT
timestamp,
field_1,
field_2,
FROM AS event_table
field_2
FROM
event_table
WHERE
toStartOfHour(timestamp) = toStartOfHour(now() - toIntervalHour(1)))
COMMENT 'Test comment';
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ AS
SELECT
`field_1`,
`field_2`,
`field_3`,
FROM AS table_v5;
`field_3`
FROM
table_v5;
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ COMMENT 'Test comment'


-- Format SQL:
CREATE MATERIALIZED VIEW fresh_mv REFRESH EVERY 1 HOUR OFFSET 10 MINUTE APPEND TO events_export (`timestamp` DateTime64(9), `field_1` String, `field_2` String) DEFINER = default SQL SECURITY DEFINER AS (SELECT timestamp, field_1, field_2, FROM AS event_table WHERE toStartOfHour(timestamp) = toStartOfHour(now() - toIntervalHour(1))) COMMENT 'Test comment';
CREATE MATERIALIZED VIEW fresh_mv REFRESH EVERY 1 HOUR OFFSET 10 MINUTE APPEND TO events_export (`timestamp` DateTime64(9), `field_1` String, `field_2` String) DEFINER = default SQL SECURITY DEFINER AS (SELECT timestamp, field_1, field_2 FROM event_table WHERE toStartOfHour(timestamp) = toStartOfHour(now() - toIntervalHour(1))) COMMENT 'Test comment';
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ AS SELECT
FROM table_v5

-- Format SQL:
CREATE MATERIALIZED VIEW fresh_mv REFRESH EVERY 1 HOUR OFFSET 10 MINUTE RANDOMIZE FOR 1 SECOND DEPENDS ON table_v5 SETTINGS randomize_for=1, randomize_offset=10, randomize_period=1 APPEND TO target_table_name EMPTY AS SELECT `field_1`, `field_2`, `field_3`, FROM AS table_v5;
CREATE MATERIALIZED VIEW fresh_mv REFRESH EVERY 1 HOUR OFFSET 10 MINUTE RANDOMIZE FOR 1 SECOND DEPENDS ON table_v5 SETTINGS randomize_for=1, randomize_offset=10, randomize_period=1 APPEND TO target_table_name EMPTY AS SELECT `field_1`, `field_2`, `field_3` FROM table_v5;
Original file line number Diff line number Diff line change
Expand Up @@ -212,24 +212,31 @@
},
"Modifiers": [],
"Alias": null
},
{
"Expr": {
"Name": "FROM",
"QuoteType": 1,
"NamePos": 266,
"NameEnd": 270
},
"Modifiers": [],
"Alias": {
"Name": "event_table",
"QuoteType": 1,
"NamePos": 271,
"NameEnd": 282
}
}
],
"From": null,
"From": {
"FromPos": 266,
"Expr": {
"Table": {
"TablePos": 271,
"TableEnd": 282,
"Alias": null,
"Expr": {
"Database": null,
"Table": {
"Name": "event_table",
"QuoteType": 1,
"NamePos": 271,
"NameEnd": 282
}
},
"HasFinal": false
},
"StatementEnd": 282,
"SampleRatio": null,
"HasFinal": false
}
},
"Window": null,
"Prewhere": null,
"Where": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,24 +179,31 @@
},
"Modifiers": [],
"Alias": null
},
{
"Expr": {
"Name": "FROM",
"QuoteType": 1,
"NamePos": 289,
"NameEnd": 293
},
"Modifiers": [],
"Alias": {
"Name": "table_v5",
"QuoteType": 1,
"NamePos": 294,
"NameEnd": 302
}
}
],
"From": null,
"From": {
"FromPos": 289,
"Expr": {
"Table": {
"TablePos": 294,
"TableEnd": 302,
"Alias": null,
"Expr": {
"Database": null,
"Table": {
"Name": "table_v5",
"QuoteType": 1,
"NamePos": 294,
"NameEnd": 302
}
},
"HasFinal": false
},
"StatementEnd": 302,
"SampleRatio": null,
"HasFinal": false
}
},
"Window": null,
"Prewhere": null,
"Where": null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- Origin SQL:
SELECT count(x), --name
FROM cloud_assets


-- Beautify SQL:
SELECT
count(x)
FROM
cloud_assets;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Origin SQL:
SELECT count(x), --name
FROM cloud_assets


-- Format SQL:
SELECT count(x) FROM cloud_assets;
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
[
{
"SelectPos": 0,
"StatementEnd": 41,
"With": null,
"Top": null,
"HasDistinct": false,
"DistinctOn": null,
"SelectItems": [
{
"Expr": {
"Name": {
"Name": "count",
"QuoteType": 1,
"NamePos": 7,
"NameEnd": 12
},
"Params": {
"LeftParenPos": 12,
"RightParenPos": 14,
"Items": {
"ListPos": 13,
"ListEnd": 14,
"HasDistinct": false,
"Items": [
{
"Expr": {
"Name": "x",
"QuoteType": 1,
"NamePos": 13,
"NameEnd": 14
},
"Alias": null
}
]
},
"ColumnArgList": null
}
},
"Modifiers": [],
"Alias": null
}
],
"From": {
"FromPos": 24,
"Expr": {
"Table": {
"TablePos": 29,
"TableEnd": 41,
"Alias": null,
"Expr": {
"Database": null,
"Table": {
"Name": "cloud_assets",
"QuoteType": 1,
"NamePos": 29,
"NameEnd": 41
}
},
"HasFinal": false
},
"StatementEnd": 41,
"SampleRatio": null,
"HasFinal": false
}
},
"Window": null,
"Prewhere": null,
"Where": null,
"GroupBy": null,
"WithTotal": false,
"Having": null,
"OrderBy": null,
"LimitBy": null,
"Limit": null,
"Settings": null,
"Format": null,
"UnionAll": null,
"UnionDistinct": null,
"Except": null
}
]
2 changes: 2 additions & 0 deletions parser/testdata/query/select_trailing_comma_before_from.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT count(x), --name
FROM cloud_assets
Loading