Skip to content
Closed
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
1 change: 1 addition & 0 deletions parser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,7 @@ type CreateMaterializedView struct {
Settings *SettingsClause
HasAppend bool
Engine *EngineExpr
TableSchema *TableSchemaClause // column list for ENGINE-based MVs (no TO clause)
HasEmpty bool
Destination *DestinationClause
SubQuery *SubQuery
Expand Down
4 changes: 4 additions & 0 deletions parser/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,10 @@ func (c *CreateMaterializedView) FormatSQL(formatter *Formatter) {
formatter.Break()
formatter.WriteString("APPEND")
}
if c.TableSchema != nil {
formatter.Break()
formatter.WriteExpr(c.TableSchema)
}
if c.Engine != nil {
formatter.Break()
formatter.WriteExpr(c.Engine)
Expand Down
16 changes: 16 additions & 0 deletions parser/parser_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ func (p *Parser) parseCreateMaterializedView(pos Pos) (*CreateMaterializedView,
}
createMaterializedView.Destination.TableSchema = tableSchema
}
case p.matchTokenKind(TokenKindLParen):
// Column list before ENGINE (e.g. SHOW CREATE TABLE output for RMVs with ENGINE = Memory)
tableSchema, err := p.parseTableSchemaClause(p.Pos())
if err != nil {
return nil, err
}
createMaterializedView.TableSchema = tableSchema
if !p.matchKeyword(KeywordEngine) {
return nil, fmt.Errorf("unexpected token: %q, expected ENGINE after column list", p.lastTokenKind())
}
engineExpr, err := p.parseEngineExpr(p.Pos())
if err != nil {
return nil, err
}
createMaterializedView.Engine = engineExpr
createMaterializedView.StatementEnd = engineExpr.End()
case p.matchKeyword(KeywordEngine):
engineExpr, err := p.parseEngineExpr(p.Pos())
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
CREATE MATERIALIZED VIEW db1.config_memory_v0
REFRESH EVERY 1 SECOND
(
`schedule_id` String,
`sample_rate` Int8,
`start_at` DateTime64(9),
`end_at` DateTime64(9),
`created_at` DateTime64(9),
`created_by` String,
`properties` Map(String, String),
`cluster_percentage` Float64,
`schedule_filters` String
)
ENGINE = Memory
SETTINGS min_rows_to_keep = 250000, max_rows_to_keep = 500000
DEFINER = default SQL SECURITY DEFINER
COMMENT 'test comment'
AS SELECT
schedule_id,
sample_rate,
start_at,
end_at,
created_at,
created_by,
properties,
cluster_percentage,
schedule_filters
FROM
(
SELECT
*,
row_number() OVER (PARTITION BY schedule_filters ORDER BY created_at DESC) AS rn
FROM db1.config_v0
WHERE schedule_filters != '{}'
)
WHERE rn = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
-- Origin SQL:
CREATE MATERIALIZED VIEW db1.config_memory_v0
REFRESH EVERY 1 SECOND
(
`schedule_id` String,
`sample_rate` Int8,
`start_at` DateTime64(9),
`end_at` DateTime64(9),
`created_at` DateTime64(9),
`created_by` String,
`properties` Map(String, String),
`cluster_percentage` Float64,
`schedule_filters` String
)
ENGINE = Memory
SETTINGS min_rows_to_keep = 250000, max_rows_to_keep = 500000
DEFINER = default SQL SECURITY DEFINER
COMMENT 'test comment'
AS SELECT
schedule_id,
sample_rate,
start_at,
end_at,
created_at,
created_by,
properties,
cluster_percentage,
schedule_filters
FROM
(
SELECT
*,
row_number() OVER (PARTITION BY schedule_filters ORDER BY created_at DESC) AS rn
FROM db1.config_v0
WHERE schedule_filters != '{}'
)
WHERE rn = 1


-- Beautify SQL:
CREATE MATERIALIZED VIEW db1.config_memory_v0
REFRESH EVERY 1 SECOND
(
`schedule_id` String,
`sample_rate` Int8,
`start_at` DateTime64(9),
`end_at` DateTime64(9),
`created_at` DateTime64(9),
`created_by` String,
`properties` Map(String, String),
`cluster_percentage` Float64,
`schedule_filters` String
)
ENGINE = Memory
SETTINGS
min_rows_to_keep=250000,
max_rows_to_keep=500000
DEFINER = default
SQL SECURITY DEFINER
AS
SELECT
schedule_id,
sample_rate,
start_at,
end_at,
created_at,
created_by,
properties,
cluster_percentage,
schedule_filters
FROM
(SELECT
*,
row_number() OVER (PARTITION BY schedule_filters ORDER BY
created_at DESC) AS rn
FROM
db1.config_v0
WHERE
schedule_filters != '{}')
WHERE
rn = 1
COMMENT 'test comment';
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
-- Origin SQL:
CREATE MATERIALIZED VIEW db1.config_memory_v0
REFRESH EVERY 1 SECOND
(
`schedule_id` String,
`sample_rate` Int8,
`start_at` DateTime64(9),
`end_at` DateTime64(9),
`created_at` DateTime64(9),
`created_by` String,
`properties` Map(String, String),
`cluster_percentage` Float64,
`schedule_filters` String
)
ENGINE = Memory
SETTINGS min_rows_to_keep = 250000, max_rows_to_keep = 500000
DEFINER = default SQL SECURITY DEFINER
COMMENT 'test comment'
AS SELECT
schedule_id,
sample_rate,
start_at,
end_at,
created_at,
created_by,
properties,
cluster_percentage,
schedule_filters
FROM
(
SELECT
*,
row_number() OVER (PARTITION BY schedule_filters ORDER BY created_at DESC) AS rn
FROM db1.config_v0
WHERE schedule_filters != '{}'
)
WHERE rn = 1


-- Format SQL:
CREATE MATERIALIZED VIEW db1.config_memory_v0 REFRESH EVERY 1 SECOND (`schedule_id` String, `sample_rate` Int8, `start_at` DateTime64(9), `end_at` DateTime64(9), `created_at` DateTime64(9), `created_by` String, `properties` Map(String, String), `cluster_percentage` Float64, `schedule_filters` String) ENGINE = Memory SETTINGS min_rows_to_keep=250000, max_rows_to_keep=500000 DEFINER = default SQL SECURITY DEFINER AS SELECT schedule_id, sample_rate, start_at, end_at, created_at, created_by, properties, cluster_percentage, schedule_filters FROM (SELECT *, row_number() OVER (PARTITION BY schedule_filters ORDER BY created_at DESC) AS rn FROM db1.config_v0 WHERE schedule_filters != '{}') WHERE rn = 1 COMMENT 'test comment';
1 change: 1 addition & 0 deletions parser/testdata/ddl/output/bug_001.sql.golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"Settings": null,
"HasAppend": false,
"Engine": null,
"TableSchema": null,
"HasEmpty": false,
"Destination": {
"ToPos": 89,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"Settings": null,
"HasAppend": false,
"Engine": null,
"TableSchema": null,
"HasEmpty": false,
"Destination": {
"ToPos": 78,
Expand Down
Loading
Loading