MCPcopy Create free account
hub / github.com/bytebase/bytebase / isReadOnlyAST

Function isReadOnlyAST

backend/plugin/parser/doris/query.go:53–78  ·  view source on GitHub ↗

isReadOnlyAST returns true when the given top-level AST node represents a read-only Doris statement (SELECT family, SHOW, DESCRIBE, EXPLAIN, HELP). Omni's parser currently has stub-shaped acceptance for some shapes — bare `SHOW`, `DESCRIBE`, `EXPLAIN` all produce a corresponding AST node with empty

(node ast.Node)

Source from the content-addressed store, hash-verified

51// produced no concrete statement, which shouldn't happen for valid read-only
52// SQL after parseDorisSQL succeeds.
53func isReadOnlyAST(node ast.Node) bool {
54 switch n := node.(type) {
55 case *ast.SelectStmt, *ast.SetOpStmt:
56 return true
57 case *ast.ShowStmt:
58 // Reject bare `SHOW` (Type is empty when the parser took the stub path
59 // without seeing a recognised variant keyword).
60 return n.Type != ""
61 case *ast.ShowRoutineLoadStmt, *ast.ShowRoutineLoadTaskStmt,
62 *ast.ShowJobStmt, *ast.ShowJobTaskStmt,
63 *ast.ShowConstraintsStmt, *ast.ShowAnalyzeStmt, *ast.ShowStatsStmt:
64 return true
65 case *ast.DescribeStmt:
66 // Reject bare `DESCRIBE` / `DESC` (Target nil means no table named).
67 return n.Target != nil
68 case *ast.ExplainStmt:
69 // EXPLAIN requires an inner query; the inner query must itself be a
70 // shape EXPLAIN is meaningful for (SELECT/DML/Show). This blocks
71 // inputs like `EXPLAIN`, `EXPLAIN DROP TABLE t`, etc.
72 return n.Query != nil && isExplainableInner(n.Query)
73 case *ast.HelpStmt:
74 return true
75 default:
76 return false
77 }
78}
79
80// isExplainableInner reports whether `node` is a shape that EXPLAIN can
81// legitimately wrap (SELECT family or DML). DDL inside EXPLAIN is rejected:

Callers 1

validateQueryFunction · 0.70

Calls 1

isExplainableInnerFunction · 0.70

Tested by

no test coverage detected