github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/vm.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 vm 16 17 import ( 18 "bytes" 19 20 "github.com/matrixorigin/matrixone/pkg/common/moerr" 21 "github.com/matrixorigin/matrixone/pkg/vm/process" 22 ) 23 24 func (ins Instruction) MarshalBinary() ([]byte, error) { 25 return nil, nil 26 } 27 28 func (ins Instruction) UnmarshalBinary(_ []byte) error { 29 return nil 30 } 31 32 // String range instructions and call each operator's string function to show a query plan 33 func String(ins Instructions, buf *bytes.Buffer) { 34 for i, in := range ins { 35 if i > 0 { 36 buf.WriteString(" -> ") 37 } 38 stringFunc[in.Op](in.Arg, buf) 39 } 40 } 41 42 // Prepare range instructions and do init work for each operator's argument by calling its prepare function 43 func Prepare(ins Instructions, proc *process.Process) error { 44 for _, in := range ins { 45 if err := prepareFunc[in.Op](proc, in.Arg); err != nil { 46 return err 47 } 48 } 49 return nil 50 } 51 52 func Run(ins Instructions, proc *process.Process) (end bool, err error) { 53 var ok bool 54 55 defer func() { 56 if e := recover(); e != nil { 57 err = moerr.ConvertPanicError(proc.Ctx, e) 58 } 59 }() 60 for _, in := range ins { 61 if ok, err = execFunc[in.Op](in.Idx, proc, in.Arg, in.IsFirst, in.IsLast); err != nil { 62 return ok || end, err 63 } 64 if ok { // ok is true shows that at least one operator has done its work 65 end = true 66 } 67 } 68 return end, err 69 }