Skip to content

Commit

Permalink
add parsing for create temporary table (#74)
Browse files Browse the repository at this point in the history
Adds parsing for CREATE TEMPORARY TABLE...
  • Loading branch information
Vinai Rachakonda authored May 24, 2021
1 parent 5801b11 commit 7b048c5
Show file tree
Hide file tree
Showing 5 changed files with 4,421 additions and 4,320 deletions.
16 changes: 13 additions & 3 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,9 @@ type DDL struct {

// ProcedureSpec is set for CREATE PROCEDURE operations
ProcedureSpec *ProcedureSpec

// Temporary is set for CREATE TEMPORARY TABLE operations.
Temporary bool
}

// ColumnOrder is used in some DDL statements to specify or change the order of a column in a schema.
Expand Down Expand Up @@ -1602,6 +1605,7 @@ const (
SpatialStr = "spatial"
FulltextStr = "fulltext"
SetStr = "set"
TemporaryStr = "temporary"
)

// Format formats the node.
Expand Down Expand Up @@ -1648,12 +1652,18 @@ func (node *DDL) Format(buf *TrackedBuffer) {
if node.IfNotExists {
notExists = " if not exists"
}

temporary := ""
if node.Temporary {
temporary = " " + TemporaryStr
}

if node.OptLike != nil {
buf.Myprintf("%s table%s %v %v", node.Action, notExists, node.Table, node.OptLike)
buf.Myprintf("%s%s table%s %v %v", node.Action, temporary, notExists, node.Table, node.OptLike)
} else if node.TableSpec != nil {
buf.Myprintf("%s table%s %v %v", node.Action, notExists, node.Table, node.TableSpec)
buf.Myprintf("%s%s table%s %v %v", node.Action, temporary, notExists, node.Table, node.TableSpec)
} else {
buf.Myprintf("%s table%s %v", node.Action, notExists, node.Table)
buf.Myprintf("%s%s table%s %v", node.Action, temporary, notExists, node.Table)
}
}
case DropStr:
Expand Down
6 changes: 6 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,12 @@ var (
}, {
input: "create table a (b1 bool not null primary key, b2 boolean not null)",
output: "create table a (\n\tb1 bool not null primary key,\n\tb2 boolean not null\n)",
}, {
input: "create temporary table a (b1 bool not null primary key, b2 boolean not null)",
output: "create temporary table a (\n\tb1 bool not null primary key,\n\tb2 boolean not null\n)",
}, {
input: "create temporary table if not exists a (\n\t`a` int\n)",
output: "create temporary table if not exists a (\n\ta int\n)",
}, {
input: "create index a on b (id)",
output: "alter table b add index a (id)",
Expand Down
Loading

0 comments on commit 7b048c5

Please sign in to comment.