Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support LOCALITY GROUP statement #289

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
44 changes: 44 additions & 0 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ func (CreateSchema) isStatement() {}
func (DropSchema) isStatement() {}
func (CreateDatabase) isStatement() {}
func (AlterDatabase) isStatement() {}
func (CreateLocalityGroup) isStatement() {}
func (AlterLocalityGroup) isStatement() {}
func (DropLocalityGroup) isStatement() {}
func (CreatePlacement) isStatement() {}
func (CreateProtoBundle) isStatement() {}
func (AlterProtoBundle) isStatement() {}
Expand Down Expand Up @@ -369,6 +372,9 @@ func (CreateSchema) isDDL() {}
func (DropSchema) isDDL() {}
func (CreateDatabase) isDDL() {}
func (AlterDatabase) isDDL() {}
func (CreateLocalityGroup) isDDL() {}
func (AlterLocalityGroup) isDDL() {}
func (DropLocalityGroup) isDDL() {}
func (CreatePlacement) isDDL() {}
func (CreateProtoBundle) isDDL() {}
func (AlterProtoBundle) isDDL() {}
Expand Down Expand Up @@ -2276,6 +2282,44 @@ type AlterDatabase struct {
Options *Options
}

// CreateLocalityGroup is CREATE LOCALITY GROUP statement node.
//
// CREATE LOCALITY GROUP {{.Name | sql}} {{.Options | sqlOpt}}
type CreateLocalityGroup struct {
// pos = Create
// end = (Options ?? Name).end

Create token.Pos // position of "CREATE" keyword

Name *Ident
Options *Options // optional
}

// AlterLocalityGroup is ALTER LOCALITY GROUP statement node.
//
// ALTER LOCALITY GROUP {{.Name | sql}} SET {{.Options | sql}}
type AlterLocalityGroup struct {
// pos = Alter
// end = Options.end

Alter token.Pos // position of "ALTER" keyword

Name *Ident
Options *Options
}

// DropLocalityGroup is DROP LOCALITY GROUP statement node.
//
// DROP LOCALITY GROUP {{.Name | sql}}
type DropLocalityGroup struct {
// pos = Drop
// end = Name.end

Drop token.Pos // position of "DROP" keyword

Name *Ident
}

// CreatePlacement is CREATE PLACEMENT statement node.
//
// CREATE PLACEMENT {{.Name | sql}} {{.Options | sqlOpt}}
Expand Down
24 changes: 24 additions & 0 deletions ast/pos.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions ast/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,18 @@ func (c *CreateDatabase) SQL() string {
return "CREATE DATABASE " + c.Name.SQL()
}

func (c *CreateLocalityGroup) SQL() string {
return "CREATE LOCALITY GROUP " + c.Name.SQL() + sqlOpt(" ", c.Options, "")
}

func (a *AlterLocalityGroup) SQL() string {
return "ALTER LOCALITY GROUP " + a.Name.SQL() + " SET " + a.Options.SQL()
}

func (d *DropLocalityGroup) SQL() string {
return "DROP LOCALITY GROUP " + d.Name.SQL()
}

func (s *CreateSchema) SQL() string { return "CREATE SCHEMA " + s.Name.SQL() }

func (s *DropSchema) SQL() string { return "DROP SCHEMA " + s.Name.SQL() }
Expand Down
11 changes: 11 additions & 0 deletions ast/walk_internal.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2836,6 +2836,8 @@ func (p *Parser) parseDDL() (ddl ast.DDL) {
return p.parseCreateSchema(pos)
case p.Token.IsKeywordLike("DATABASE"):
return p.parseCreateDatabase(pos)
case p.Token.IsKeywordLike("LOCALITY"):
return p.parseCreateLocalityGroup(pos)
case p.Token.IsKeywordLike("PLACEMENT"):
return p.parseCreatePlacement(pos)
case p.Token.Kind == "PROTO":
Expand Down Expand Up @@ -2880,6 +2882,8 @@ func (p *Parser) parseDDL() (ddl ast.DDL) {
return p.parseAlterTable(pos)
case p.Token.IsKeywordLike("DATABASE"):
return p.parseAlterDatabase(pos)
case p.Token.IsKeywordLike("LOCALITY"):
return p.parseAlterLocalityGroup(pos)
case p.Token.Kind == "PROTO":
return p.parseAlterProtoBundle(pos)
case p.Token.IsKeywordLike("INDEX"):
Expand All @@ -2901,6 +2905,8 @@ func (p *Parser) parseDDL() (ddl ast.DDL) {
switch {
case p.Token.IsKeywordLike("SCHEMA"):
return p.parseDropSchema(pos)
case p.Token.IsKeywordLike("LOCALITY"):
return p.parseDropLocalityGroup(pos)
case p.Token.Kind == "PROTO":
return p.parseDropProtoBundle(pos)
case p.Token.IsKeywordLike("TABLE"):
Expand Down Expand Up @@ -2986,6 +2992,46 @@ func (p *Parser) parseAlterDatabase(pos token.Pos) *ast.AlterDatabase {
}
}

func (p *Parser) parseCreateLocalityGroup(pos token.Pos) *ast.CreateLocalityGroup {
p.expectKeywordLike("LOCALITY")
p.expect("GROUP")
name := p.parseIdent()

options := p.tryParseOptions()

return &ast.CreateLocalityGroup{
Create: pos,
Name: name,
Options: options,
}
}

func (p *Parser) parseAlterLocalityGroup(pos token.Pos) *ast.AlterLocalityGroup {
p.expectKeywordLike("LOCALITY")
p.expect("GROUP")
name := p.parseIdent()

p.expect("SET")
options := p.parseOptions()

return &ast.AlterLocalityGroup{
Alter: pos,
Name: name,
Options: options,
}
}

func (p *Parser) parseDropLocalityGroup(pos token.Pos) *ast.DropLocalityGroup {
p.expectKeywordLike("LOCALITY")
p.expect("GROUP")
name := p.parseIdent()

return &ast.DropLocalityGroup{
Drop: pos,
Name: name,
}
}

func (p *Parser) parseCreatePlacement(pos token.Pos) *ast.CreatePlacement {
p.expectKeywordLike("PLACEMENT")
name := p.parseIdent()
Expand Down
1 change: 1 addition & 0 deletions testdata/input/ddl/alter_locality_group.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER LOCALITY GROUP `default` SET OPTIONS (storage = 'ssd', ssd_to_hdd_spill_timespan = '10d')
2 changes: 2 additions & 0 deletions testdata/input/ddl/create_locality_group_options.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE LOCALITY GROUP spill_to_hdd
OPTIONS (storage = 'ssd', ssd_to_hdd_spill_timespan = '10d')
1 change: 1 addition & 0 deletions testdata/input/ddl/create_locality_group_simple.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE LOCALITY GROUP separate_storage
1 change: 1 addition & 0 deletions testdata/input/ddl/drop_locality_group.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP LOCALITY GROUP ssd_only
43 changes: 43 additions & 0 deletions testdata/result/ddl/alter_locality_group.sql.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
--- alter_locality_group.sql
ALTER LOCALITY GROUP `default` SET OPTIONS (storage = 'ssd', ssd_to_hdd_spill_timespan = '10d')
--- AST
&ast.AlterLocalityGroup{
Name: &ast.Ident{
NamePos: 21,
NameEnd: 30,
Name: "default",
},
Options: &ast.Options{
Options: 35,
Rparen: 94,
Records: []*ast.OptionsDef{
&ast.OptionsDef{
Name: &ast.Ident{
NamePos: 44,
NameEnd: 51,
Name: "storage",
},
Value: &ast.StringLiteral{
ValuePos: 54,
ValueEnd: 59,
Value: "ssd",
},
},
&ast.OptionsDef{
Name: &ast.Ident{
NamePos: 61,
NameEnd: 86,
Name: "ssd_to_hdd_spill_timespan",
},
Value: &ast.StringLiteral{
ValuePos: 89,
ValueEnd: 94,
Value: "10d",
},
},
},
},
}

--- SQL
ALTER LOCALITY GROUP `default` SET OPTIONS (storage = "ssd", ssd_to_hdd_spill_timespan = "10d")
44 changes: 44 additions & 0 deletions testdata/result/ddl/create_locality_group_options.sql.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
--- create_locality_group_options.sql
CREATE LOCALITY GROUP spill_to_hdd
OPTIONS (storage = 'ssd', ssd_to_hdd_spill_timespan = '10d')
--- AST
&ast.CreateLocalityGroup{
Name: &ast.Ident{
NamePos: 22,
NameEnd: 34,
Name: "spill_to_hdd",
},
Options: &ast.Options{
Options: 35,
Rparen: 94,
Records: []*ast.OptionsDef{
&ast.OptionsDef{
Name: &ast.Ident{
NamePos: 44,
NameEnd: 51,
Name: "storage",
},
Value: &ast.StringLiteral{
ValuePos: 54,
ValueEnd: 59,
Value: "ssd",
},
},
&ast.OptionsDef{
Name: &ast.Ident{
NamePos: 61,
NameEnd: 86,
Name: "ssd_to_hdd_spill_timespan",
},
Value: &ast.StringLiteral{
ValuePos: 89,
ValueEnd: 94,
Value: "10d",
},
},
},
},
}

--- SQL
CREATE LOCALITY GROUP spill_to_hdd OPTIONS (storage = "ssd", ssd_to_hdd_spill_timespan = "10d")
13 changes: 13 additions & 0 deletions testdata/result/ddl/create_locality_group_simple.sql.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- create_locality_group_simple.sql
CREATE LOCALITY GROUP separate_storage
--- AST
&ast.CreateLocalityGroup{
Name: &ast.Ident{
NamePos: 22,
NameEnd: 38,
Name: "separate_storage",
},
}

--- SQL
CREATE LOCALITY GROUP separate_storage
13 changes: 13 additions & 0 deletions testdata/result/ddl/drop_locality_group.sql.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- drop_locality_group.sql
DROP LOCALITY GROUP ssd_only
--- AST
&ast.DropLocalityGroup{
Name: &ast.Ident{
NamePos: 20,
NameEnd: 28,
Name: "ssd_only",
},
}

--- SQL
DROP LOCALITY GROUP ssd_only
43 changes: 43 additions & 0 deletions testdata/result/statement/alter_locality_group.sql.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
--- alter_locality_group.sql
ALTER LOCALITY GROUP `default` SET OPTIONS (storage = 'ssd', ssd_to_hdd_spill_timespan = '10d')
--- AST
&ast.AlterLocalityGroup{
Name: &ast.Ident{
NamePos: 21,
NameEnd: 30,
Name: "default",
},
Options: &ast.Options{
Options: 35,
Rparen: 94,
Records: []*ast.OptionsDef{
&ast.OptionsDef{
Name: &ast.Ident{
NamePos: 44,
NameEnd: 51,
Name: "storage",
},
Value: &ast.StringLiteral{
ValuePos: 54,
ValueEnd: 59,
Value: "ssd",
},
},
&ast.OptionsDef{
Name: &ast.Ident{
NamePos: 61,
NameEnd: 86,
Name: "ssd_to_hdd_spill_timespan",
},
Value: &ast.StringLiteral{
ValuePos: 89,
ValueEnd: 94,
Value: "10d",
},
},
},
},
}

--- SQL
ALTER LOCALITY GROUP `default` SET OPTIONS (storage = "ssd", ssd_to_hdd_spill_timespan = "10d")
Loading
Loading