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

Function getStatementWithResultLimitInline

backend/plugin/db/starrocks/query.go:101–134  ·  view source on GitHub ↗
(statement string, limitCount int)

Source from the content-addressed store, hash-verified

99}
100
101func getStatementWithResultLimitInline(statement string, limitCount int) (string, error) {
102 if strings.TrimSpace(statement) == "" {
103 return "", errors.New("empty statement")
104 }
105
106 file, errs := parser.Parse(statement)
107 if len(errs) > 0 {
108 return "", errors.New(errs[0].Error())
109 }
110 if file == nil || len(file.Stmts) != 1 {
111 stmtCount := 0
112 if file != nil {
113 stmtCount = len(file.Stmts)
114 }
115 return "", errors.Errorf("expected exactly one statement, got %d", stmtCount)
116 }
117
118 switch stmt := file.Stmts[0].(type) {
119 case *ast.SelectStmt:
120 return rewriteSelectLimit(statement, stmt, limitCount)
121 case *ast.SetOpStmt:
122 return rewriteSetOpLimit(statement, stmt, limitCount)
123 case *ast.ParenSelect:
124 switch inner := stmt.Sel.(type) {
125 case *ast.SelectStmt:
126 return rewriteSelectLimit(statement, inner, limitCount)
127 case *ast.SetOpStmt:
128 return rewriteSetOpLimit(statement, inner, limitCount)
129 }
130 return statement, nil
131 default:
132 return statement, nil
133 }
134}
135
136func hasUnparsedTail(sql string, locEnd int) bool {
137 pos := locEnd

Callers 1

Calls 4

rewriteSetOpLimitFunction · 0.85
ErrorfMethod · 0.80
rewriteSelectLimitFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected