Skip to content

Commit

Permalink
Merge pull request #7242 from GuptaManan100/rename-truncate-flush
Browse files Browse the repository at this point in the history
Adds Planning and Parsing Support for Truncate, Rename, Drop Index and Flush
  • Loading branch information
systay authored Jan 11, 2021
2 parents b771bdf + ec0aa0c commit a489616
Show file tree
Hide file tree
Showing 30 changed files with 6,474 additions and 5,540 deletions.
9 changes: 9 additions & 0 deletions go/test/endtoend/vtgate/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,15 @@ func TestCreateView(t *testing.T) {
assertMatches(t, conn, "select * from v1", `[[INT64(1) INT64(1)] [INT64(2) INT64(2)] [INT64(3) INT64(3)] [INT64(4) INT64(4)] [INT64(5) INT64(5)]]`)
}

func TestFlush(t *testing.T) {
defer cluster.PanicHandler(t)
ctx := context.Background()
conn, err := mysql.Connect(ctx, &vtParams)
require.NoError(t, err)
defer conn.Close()
exec(t, conn, "flush local tables t1, t2")
}

func assertMatches(t *testing.T, conn *mysql.Conn, query, expected string) {
t.Helper()
qr := exec(t, conn, query)
Expand Down
9 changes: 8 additions & 1 deletion go/vt/sqlparser/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const (
StmtVStream
StmtLockTables
StmtUnlockTables
StmtFlush
)

//ASTToStatementType returns a StatementType from an AST stmt
Expand Down Expand Up @@ -100,6 +101,8 @@ func ASTToStatementType(stmt Statement) StatementType {
return StmtLockTables
case *UnlockTables:
return StmtUnlockTables
case *Flush:
return StmtFlush
default:
return StmtUnknown
}
Expand Down Expand Up @@ -187,8 +190,10 @@ func Preview(sql string) StatementType {
return StmtRollback
}
switch loweredFirstWord {
case "create", "alter", "rename", "drop", "truncate", "flush":
case "create", "alter", "rename", "drop", "truncate":
return StmtDDL
case "flush":
return StmtFlush
case "set":
return StmtSet
case "show":
Expand Down Expand Up @@ -255,6 +260,8 @@ func (s StatementType) String() string {
return "LOCK_TABLES"
case StmtUnlockTables:
return "UNLOCK_TABLES"
case StmtFlush:
return "FLUSH"
default:
return "UNKNOWN"
}
Expand Down
1 change: 1 addition & 0 deletions go/vt/sqlparser/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func TestPreview(t *testing.T) {
{"grant", StmtPriv},
{"revoke", StmtPriv},
{"truncate", StmtDDL},
{"flush", StmtFlush},
{"unknown", StmtUnknown},

{"/* leading comment */ select ...", StmtSelect},
Expand Down
Loading

0 comments on commit a489616

Please sign in to comment.