github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/colexec/table_function/table_function.go (about) 1 // Copyright 2022 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 table_function 16 17 import ( 18 "bytes" 19 "fmt" 20 21 "github.com/matrixorigin/matrixone/pkg/common/moerr" 22 "github.com/matrixorigin/matrixone/pkg/container/types" 23 "github.com/matrixorigin/matrixone/pkg/pb/plan" 24 "github.com/matrixorigin/matrixone/pkg/vm/process" 25 ) 26 27 func Call(idx int, proc *process.Process, arg any, isFirst bool, isLast bool) (bool, error) { 28 tblArg := arg.(*Argument) 29 switch tblArg.Name { 30 case "unnest": 31 return unnestCall(idx, proc, tblArg) 32 case "generate_series": 33 return generateSeriesCall(idx, proc, tblArg) 34 case "meta_scan": 35 return metaScanCall(idx, proc, tblArg) 36 case "current_account": 37 return currentAccountCall(idx, proc, tblArg) 38 default: 39 return true, moerr.NewNotSupported(proc.Ctx, fmt.Sprintf("table function %s is not supported", tblArg.Name)) 40 } 41 } 42 43 func String(arg any, buf *bytes.Buffer) { 44 buf.WriteString(arg.(*Argument).Name) 45 } 46 47 func Prepare(proc *process.Process, arg any) error { 48 tblArg := arg.(*Argument) 49 switch tblArg.Name { 50 case "unnest": 51 return unnestPrepare(proc, tblArg) 52 case "generate_series": 53 return generateSeriesPrepare(proc, tblArg) 54 case "meta_scan": 55 return metaScanPrepare(proc, tblArg) 56 case "current_account": 57 return currentAccountPrepare(proc, tblArg) 58 default: 59 return moerr.NewNotSupported(proc.Ctx, fmt.Sprintf("table function %s is not supported", tblArg.Name)) 60 } 61 } 62 63 func dupType(typ *plan.Type) types.Type { 64 return types.New(types.T(typ.Id), typ.Width, typ.Scale, typ.Precision) 65 }