github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/colexec/output/output.go (about) 1 // Copyright 2021 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 output 16 17 import ( 18 "bytes" 19 20 "github.com/matrixorigin/matrixone/pkg/vm" 21 "github.com/matrixorigin/matrixone/pkg/vm/process" 22 ) 23 24 const argName = "output" 25 26 func (arg *Argument) String(buf *bytes.Buffer) { 27 buf.WriteString(argName) 28 buf.WriteString(": sql output") 29 } 30 31 func (arg *Argument) Prepare(_ *process.Process) error { 32 return nil 33 } 34 35 func (arg *Argument) Call(proc *process.Process) (vm.CallResult, error) { 36 if err, isCancel := vm.CancelCheck(proc); isCancel { 37 return vm.CancelResult, err 38 } 39 40 ap := arg 41 result, err := arg.GetChildren(0).Call(proc) 42 if err != nil { 43 return result, err 44 } 45 46 anal := proc.GetAnalyze(arg.GetIdx(), arg.GetParallelIdx(), arg.GetParallelMajor()) 47 anal.Start() 48 defer anal.Stop() 49 50 if result.Batch == nil { 51 result.Status = vm.ExecStop 52 return result, nil 53 } 54 55 if result.Batch.IsEmpty() { 56 return result, nil 57 } 58 bat := result.Batch 59 60 if err := ap.Func(bat); err != nil { 61 result.Status = vm.ExecStop 62 return result, err 63 } 64 return result, nil 65 }