github.com/matrixorigin/matrixone@v0.7.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/vector" 21 "github.com/matrixorigin/matrixone/pkg/vm/process" 22 ) 23 24 func String(arg any, buf *bytes.Buffer) { 25 buf.WriteString("pipe connector") 26 } 27 28 func Prepare(_ *process.Process, _ any) error { 29 return nil 30 } 31 32 func Call(_ int, proc *process.Process, arg any, _ bool, _ bool) (bool, error) { 33 ap := arg.(*Argument) 34 reg := ap.Reg 35 bat := proc.InputBatch() 36 if bat == nil { 37 return true, nil 38 } 39 if bat.Length() == 0 { 40 return false, nil 41 } 42 43 // do not send the source batch to remote node. 44 for i := range bat.Vecs { 45 if bat.Vecs[i].IsOriginal() { 46 vec, err := vector.Dup(bat.Vecs[i], proc.Mp()) 47 if err != nil { 48 return false, err 49 } 50 bat.Vecs[i].Free(proc.Mp()) 51 bat.Vecs[i] = vec 52 } 53 } 54 55 select { 56 case <-reg.Ctx.Done(): 57 bat.Clean(proc.Mp()) 58 return true, nil 59 case reg.Ch <- bat: 60 proc.SetInputBatch(nil) 61 return false, nil 62 } 63 }