github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/colexec/connector/connector.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 connector 16 17 import ( 18 "bytes" 19 20 "github.com/matrixorigin/matrixone/pkg/container/batch" 21 "github.com/matrixorigin/matrixone/pkg/vm" 22 "github.com/matrixorigin/matrixone/pkg/vm/process" 23 ) 24 25 const argName = "connector" 26 27 func (arg *Argument) String(buf *bytes.Buffer) { 28 buf.WriteString(argName) 29 buf.WriteString(": pipe connector") 30 } 31 32 func (arg *Argument) Prepare(_ *process.Process) error { 33 return nil 34 } 35 36 func (arg *Argument) Call(proc *process.Process) (vm.CallResult, error) { 37 if err, isCancel := vm.CancelCheck(proc); isCancel { 38 return vm.CancelResult, err 39 } 40 41 reg := arg.Reg 42 43 result, err := arg.Children[0].Call(proc) 44 if err != nil { 45 return result, err 46 } 47 48 if result.Batch == nil { 49 result.Status = vm.ExecStop 50 return result, nil 51 } 52 53 bat := result.Batch 54 if bat.IsEmpty() { 55 result.Batch = batch.EmptyBatch 56 return result, nil 57 } 58 bat.AddCnt(1) 59 60 // there is no need to log anything here. 61 // because the context is already canceled means the pipeline closed normally. 62 select { 63 case <-proc.Ctx.Done(): 64 proc.PutBatch(bat) 65 result.Status = vm.ExecStop 66 return result, nil 67 68 case <-reg.Ctx.Done(): 69 proc.PutBatch(bat) 70 result.Status = vm.ExecStop 71 return result, nil 72 73 case reg.Ch <- bat: 74 return result, nil 75 } 76 }