Skip to content

Commit 3e051af

Browse files
committed
add SEM SQL command for all statements
Signed-off-by: Yang Keao <yangkeao@chunibyo.icu>
1 parent 7b104b7 commit 3e051af

File tree

10 files changed

+1383
-52
lines changed

10 files changed

+1383
-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
"stats_test.go",
5052
"util_test.go",
5153
],

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{}
@@ -1396,41 +1397,6 @@ func (n *SetPwdStmt) Accept(v Visitor) (Node, bool) {
13961397
return v.Leave(n)
13971398
}
13981399

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

@@ -2571,6 +2537,8 @@ const (
25712537
AdminUnsetBDRRole
25722538
AdminAlterDDLJob
25732539
AdminWorkloadRepoCreate
2540+
// adminTpCount is the total number of admin statement types.
2541+
adminTpCount
25742542
)
25752543

25762544
// HandleRange represents a range where handle value >= Begin and < End.
@@ -3505,6 +3473,8 @@ const (
35053473
BRIEKindShowJob
35063474
BRIEKindShowQuery
35073475
BRIEKindShowBackupMeta
3476+
// brieKindCount is the total number of BRIE kinds.
3477+
brieKindCount
35083478
// common BRIE options
35093479
BRIEOptionRateLimit BRIEOptionType = iota + 1
35103480
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)