github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/colexec/mergeblock/mergeblock.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 package mergeblock 15 16 import ( 17 "bytes" 18 19 "github.com/matrixorigin/matrixone/pkg/container/batch" 20 "github.com/matrixorigin/matrixone/pkg/vm/process" 21 ) 22 23 func String(_ any, buf *bytes.Buffer) { 24 buf.WriteString(" MergeS3BlocksMetaLoc ") 25 } 26 27 func Prepare(proc *process.Process, arg any) error { 28 ap := arg.(*Argument) 29 ap.container = new(Container) 30 ap.container.mp = make(map[int]*batch.Batch) 31 return nil 32 } 33 34 func Call(idx int, proc *process.Process, arg any, isFirst bool, isLast bool) (bool, error) { 35 var err error 36 ap := arg.(*Argument) 37 bat := proc.Reg.InputBatch 38 if bat == nil { 39 return true, nil 40 } 41 if len(bat.Zs) == 0 { 42 return false, nil 43 } 44 if err := ap.Split(proc, bat); err != nil { 45 return false, err 46 } 47 if !ap.notFreeBatch { 48 defer func() { 49 for k := range ap.container.mp { 50 ap.container.mp[k].Clean(proc.GetMPool()) 51 } 52 }() 53 } 54 for i := range ap.Unique_tbls { 55 if err = ap.Unique_tbls[i].Write(proc.Ctx, ap.container.mp[i+1]); err != nil { 56 return false, err 57 } 58 } 59 if err = ap.Tbl.Write(proc.Ctx, ap.container.mp[0]); err != nil { 60 return false, err 61 } 62 return false, nil 63 }