github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/plan/function/func_get_admin.go (about) 1 // Copyright 2024 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package function 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/common/moerr" 19 "github.com/matrixorigin/matrixone/pkg/common/runtime" 20 "github.com/matrixorigin/matrixone/pkg/container/types" 21 "github.com/matrixorigin/matrixone/pkg/container/vector" 22 "github.com/matrixorigin/matrixone/pkg/sql/plan/function/functionUtil" 23 "github.com/matrixorigin/matrixone/pkg/util/executor" 24 "github.com/matrixorigin/matrixone/pkg/vm/process" 25 ) 26 27 func builtInInternalGetAdminName(parameters []*vector.Vector, result vector.FunctionResultWrapper, proc *process.Process, length int) error { 28 p1 := vector.GenerateFunctionFixedTypeParameter[int64](parameters[0]) 29 rs := vector.MustFunctionResult[types.Varlena](result) 30 31 for i := uint64(0); i < uint64(length); i++ { 32 accountId, null1 := p1.GetValue(i) 33 if null1 { 34 return moerr.NewInvalidInput(proc.Ctx, "unsupported parameter `null` for getAdminName") 35 } 36 37 v, ok := runtime.ProcessLevelRuntime().GetGlobalVariables(runtime.InternalSQLExecutor) 38 if !ok { 39 return moerr.NewNotSupported(proc.Ctx, "no implement sqlExecutor") 40 } 41 42 exec := v.(executor.SQLExecutor) 43 opts := executor.Options{}.WithAccountID(uint32(accountId)). 44 WithTxn(proc.TxnOperator). 45 WithTimeZone(proc.SessionInfo.TimeZone) 46 if proc.TxnOperator != nil { 47 opts = opts.WithDisableIncrStatement() // this option always with WithTxn() 48 } 49 res, err := exec.Exec(proc.Ctx, "SELECT user_name FROM mo_catalog.mo_user ORDER BY user_id ASC LIMIT 1", opts) 50 if err != nil { 51 return err 52 } 53 defer res.Close() 54 55 var adminNme string 56 res.ReadRows(func(rows int, cols []*vector.Vector) bool { 57 adminNme = cols[0].GetStringAt(0) 58 return true 59 }) 60 if err = rs.AppendBytes(functionUtil.QuickStrToBytes(adminNme), false); err != nil { 61 return err 62 } 63 } 64 return nil 65 }