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 update pump or drainer status #243

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c24bbdd
add the sql syntax that supports update pump or drainer status
aliiohs Mar 11, 2019
b47e4ce
change rule of change in parser.y and add test case for change stmt
aliiohs Mar 13, 2019
8b32d34
change goyacc rule of change stmt in parser.y
aliiohs Mar 13, 2019
926ac46
Merge pull request #1 from aliiohs/support_update_Pump_or_Drainer_status
aliiohs Mar 14, 2019
1fa3849
Support update Pump or Drainer's status
aliiohs Mar 14, 2019
c5a7fac
add test case for Changing Pump or drainer status sql parser
aliiohs Mar 14, 2019
1ecfbab
add the sql syntax that supports update pump or drainer status
aliiohs Mar 11, 2019
4813668
change rule of change in parser.y and add test case for change stmt
aliiohs Mar 13, 2019
75be2fa
change goyacc rule of change stmt in parser.y
aliiohs Mar 13, 2019
2aa3cf4
Merge remote-tracking branch 'origin/master'
aliiohs Mar 14, 2019
8a85abb
Merge remote-tracking branch 'remotes/origin/master' into support_upd…
aliiohs Mar 14, 2019
8259561
add test case for Changing Pump or drainer status sql parser
aliiohs Mar 15, 2019
99ef150
fix
aliiohs Mar 15, 2019
649d26d
change the syntax of change stmt
aliiohs Mar 15, 2019
a62e3d4
fix
aliiohs Mar 15, 2019
917e051
fix
aliiohs Mar 15, 2019
ff61ecf
fix
aliiohs Mar 15, 2019
bb6c631
fix
aliiohs Mar 15, 2019
2f6d8fd
fix
aliiohs Mar 15, 2019
fe8ea62
fix
aliiohs Mar 15, 2019
b79b05a
fix
aliiohs Mar 15, 2019
6b4fe10
fix
aliiohs Mar 15, 2019
8407365
change NodeId to node_id
aliiohs Mar 15, 2019
6079ff7
change NodeId to node_id
aliiohs Mar 15, 2019
9037246
change NodeId to node_id
aliiohs Mar 15, 2019
bb81da0
Split keywords into single words
aliiohs Mar 16, 2019
af95768
fix
aliiohs Mar 16, 2019
4a70d9b
fix
aliiohs Mar 18, 2019
e446d5f
fix
aliiohs Mar 18, 2019
da5a789
add a test case for Restore method of changeStmt
aliiohs Mar 18, 2019
accfb77
fix
aliiohs Mar 18, 2019
a18a18e
add the sql syntax that supports update pump or drainer status
aliiohs Mar 11, 2019
25a5c9a
change rule of change in parser.y and add test case for change stmt
aliiohs Mar 13, 2019
5808af3
change goyacc rule of change stmt in parser.y
aliiohs Mar 13, 2019
507f15a
change rule of change in parser.y and add test case for change stmt
aliiohs Mar 13, 2019
b150798
change goyacc rule of change stmt in parser.y
aliiohs Mar 13, 2019
01e28aa
Merge remote-tracking branch 'origin/master'
aliiohs Mar 18, 2019
a291d3c
Merge branch 'master' into support_update_Pump_or_Drainer_status_2019…
aliiohs Mar 18, 2019
4bb7b8a
Merge branch 'master' into support_update_Pump_or_Drainer_status_2019…
aliiohs Mar 18, 2019
18704f6
Merge remote-tracking branch 'origin/master'
aliiohs Mar 18, 2019
2946eb6
Merge remote-tracking branch 'remotes/origin/master' into support_upd…
aliiohs Mar 18, 2019
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
37 changes: 37 additions & 0 deletions ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ const (
// Valid formats for explain statement.
ExplainFormatROW = "row"
ExplainFormatDOT = "dot"
PumpType = "PUMP"
DrainerType = "DRAINER"
)

var (
Expand Down Expand Up @@ -721,6 +723,41 @@ func (n *SetPwdStmt) Accept(v Visitor) (Node, bool) {
return v.Leave(n)
}

type ChangeStmt struct {
stmtNode

NodeType string
State string
NodeID string
}

// Restore implements Node interface.
func (n *ChangeStmt) Restore(ctx *RestoreCtx) error {
ctx.WriteKeyWord("CHANGE ")
ctx.WriteKeyWord(n.NodeType)
ctx.WriteKeyWord(" TO NODE_STATE ")
ctx.WritePlain("=")
ctx.WriteString(n.State)
ctx.WriteKeyWord(" FOR NODE_ID ")
ctx.WriteString(n.NodeID)
return nil
}

// SecureText implements SensitiveStatement interface.
func (n *ChangeStmt) SecureText() string {
return fmt.Sprintf("change %s to node_state='%s' for node_id '%s'", strings.ToLower(n.NodeType), n.State, n.NodeID)
}

// Accept implements Node Accept interface.
func (n *ChangeStmt) Accept(v Visitor) (Node, bool) {
newNode, skipChildren := v.Enter(n)
if skipChildren {
return v.Leave(newNode)
}
n = newNode.(*ChangeStmt)
return v.Leave(n)
}

// UserSpec is used for parsing create user statement.
type UserSpec struct {
User *auth.UserIdentity
Expand Down
24 changes: 24 additions & 0 deletions ast/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@ load data infile '/tmp/t.csv' into table t fields terminated by 'ab' enclosed by
}
}

// test Change Pump or drainer status sql parser
func (ts *testMiscSuite) TestChangeStmt(c *C) {
sql := `change pump to node_state='paused' for node_id '127.0.0.1:8249';
kennytm marked this conversation as resolved.
Show resolved Hide resolved
change drainer to node_state='paused' for node_id '127.0.0.1:8249';`

p := parser.New()
stmts, _, err := p.Parse(sql, "", "")
c.Assert(err, IsNil)
for _, stmt := range stmts {
stmt.Accept(visitor{})
stmt.Accept(visitor1{})
}
}

func (ts *testMiscSuite) TestSensitiveStatement(c *C) {
positive := []StmtNode{
&SetPwdStmt{},
Expand Down Expand Up @@ -203,3 +217,13 @@ func (ts *testMiscSuite) TestTableOptimizerHintRestore(c *C) {
}
RunNodeRestoreTest(c, testCases, "select /*+ %s */ * from t1 join t2", extractNodeFunc)
}
func (ts *testMiscSuite) TestChangeStmtRestore(c *C) {
testCases := []NodeRestoreTestCase{
{"CHANGE PUMP TO NODE_STATE ='paused' FOR NODE_ID '127.0.0.1:9090'", "CHANGE PUMP TO NODE_STATE ='paused' FOR NODE_ID '127.0.0.1:9090'"},
{"CHANGE DRAINER TO NODE_STATE ='paused' FOR NODE_ID '127.0.0.1:9090'", "CHANGE DRAINER TO NODE_STATE ='paused' FOR NODE_ID '127.0.0.1:9090'"},
}
extractNodeFunc := func(node Node) Node {
return node.(*ChangeStmt)
}
RunNodeRestoreTest(c, testCases, "%s", extractNodeFunc)
}
2 changes: 2 additions & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ var tokenMap = map[string]int{
"NEXT_ROW_ID": next_row_id,
"NO": no,
"NO_WRITE_TO_BINLOG": noWriteToBinLog,
"NODE_ID": node_id,
"NODE_STATE": node_state,
"NONE": none,
"NOT": not,
"NOW": now,
Expand Down
Loading