Skip to content

Commit 4416f66

Browse files
committed
add SEM SQL command for all statements
Signed-off-by: Yang Keao <[email protected]>
1 parent eeccd2e commit 4416f66

File tree

10 files changed

+1376
-52
lines changed

10 files changed

+1376
-52
lines changed

pkg/parser/ast/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ go_library(
1313
"misc.go",
1414
"model.go",
1515
"procedure.go",
16+
"sem.go",
1617
"stats.go",
1718
"util.go",
1819
],
@@ -46,6 +47,7 @@ go_test(
4647
"misc_test.go",
4748
"model_test.go",
4849
"procedure_test.go",
50+
"sem_test.go",
4951
"util_test.go",
5052
],
5153
embed = [":ast"],

pkg/parser/ast/ast.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ type FuncNode interface {
106106
type StmtNode interface {
107107
Node
108108
statement()
109+
// SEMCommand generates a string that represents the command type of the statement.
110+
// It's only used for Security Enforcement Mode (SEM) for now. If it's going to be
111+
// re-used for other purposes, we may need to rename and give it a clearer definition.
112+
//
113+
// The function of this method is similar to `GetStmtLabel`, but it returns more detail.
114+
SEMCommand() string
109115
}
110116

111117
// DDLNode represents DDL statement node.
@@ -158,8 +164,6 @@ func GetStmtLabel(stmtNode StmtNode) string {
158164
return "AnalyzeTable"
159165
case *BeginStmt:
160166
return "Begin"
161-
case *ChangeStmt:
162-
return "Change"
163167
case *CommitStmt:
164168
return "Commit"
165169
case *CompactTableStmt:

pkg/parser/ast/dml.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3054,6 +3054,8 @@ const (
30543054
ShowDistributions
30553055
ShowPlanForSQL
30563056
ShowDistributionJobs
3057+
// showTpCount is the count of all kinds of `SHOW` statements.
3058+
showTpCount
30573059
)
30583060

30593061
const (

pkg/parser/ast/misc.go

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ var (
6161
_ StmtNode = &CompactTableStmt{}
6262
_ StmtNode = &SetResourceGroupStmt{}
6363
_ StmtNode = &TrafficStmt{}
64+
_ StmtNode = &RecommendIndexStmt{}
6465

6566
_ Node = &PrivElem{}
6667
_ Node = &VariableAssignment{}
@@ -1391,41 +1392,6 @@ func (n *SetPwdStmt) Accept(v Visitor) (Node, bool) {
13911392
return v.Leave(n)
13921393
}
13931394

1394-
type ChangeStmt struct {
1395-
stmtNode
1396-
1397-
NodeType string
1398-
State string
1399-
NodeID string
1400-
}
1401-
1402-
// Restore implements Node interface.
1403-
func (n *ChangeStmt) Restore(ctx *format.RestoreCtx) error {
1404-
ctx.WriteKeyWord("CHANGE ")
1405-
ctx.WriteKeyWord(n.NodeType)
1406-
ctx.WriteKeyWord(" TO NODE_STATE ")
1407-
ctx.WritePlain("=")
1408-
ctx.WriteString(n.State)
1409-
ctx.WriteKeyWord(" FOR NODE_ID ")
1410-
ctx.WriteString(n.NodeID)
1411-
return nil
1412-
}
1413-
1414-
// SecureText implements SensitiveStatement interface.
1415-
func (n *ChangeStmt) SecureText() string {
1416-
return fmt.Sprintf("change %s to node_state='%s' for node_id '%s'", strings.ToLower(n.NodeType), n.State, n.NodeID)
1417-
}
1418-
1419-
// Accept implements Node Accept interface.
1420-
func (n *ChangeStmt) Accept(v Visitor) (Node, bool) {
1421-
newNode, skipChildren := v.Enter(n)
1422-
if skipChildren {
1423-
return v.Leave(newNode)
1424-
}
1425-
n = newNode.(*ChangeStmt)
1426-
return v.Leave(n)
1427-
}
1428-
14291395
// SetRoleStmtType is the type for FLUSH statement.
14301396
type SetRoleStmtType int
14311397

@@ -2566,6 +2532,8 @@ const (
25662532
AdminUnsetBDRRole
25672533
AdminAlterDDLJob
25682534
AdminWorkloadRepoCreate
2535+
// adminTpCount is the total number of admin statement types.
2536+
adminTpCount
25692537
)
25702538

25712539
// HandleRange represents a range where handle value >= Begin and < End.
@@ -3500,6 +3468,8 @@ const (
35003468
BRIEKindShowJob
35013469
BRIEKindShowQuery
35023470
BRIEKindShowBackupMeta
3471+
// brieKindCount is the total number of BRIE kinds.
3472+
brieKindCount
35033473
// common BRIE options
35043474
BRIEOptionRateLimit BRIEOptionType = iota + 1
35053475
BRIEOptionConcurrency

pkg/parser/ast/procedure.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ var (
4646

4747
_ ErrNode = &ProcedureErrorCon{}
4848
_ ErrNode = &ProcedureErrorVal{}
49+
_ ErrNode = &ProcedureErrorState{}
4950
)
5051

5152
// procedure param type.

0 commit comments

Comments
 (0)