github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/plan/function/operator/is.go (about) 1 // Copyright 2022 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 operator 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/common/moerr" 19 "github.com/matrixorigin/matrixone/pkg/container/nulls" 20 "github.com/matrixorigin/matrixone/pkg/container/types" 21 "github.com/matrixorigin/matrixone/pkg/container/vector" 22 "github.com/matrixorigin/matrixone/pkg/vm/process" 23 ) 24 25 func Is(vectors []*vector.Vector, proc *process.Process) (*vector.Vector, error) { 26 lv := vectors[0] 27 rv := vectors[1] 28 retType := types.T_bool.ToType() 29 30 lefts := vector.MustTCols[bool](lv) 31 if !rv.IsScalar() || rv.IsScalarNull() { 32 return nil, moerr.NewInternalError(proc.Ctx, "second parameter of IS must be TRUE or FALSE") 33 } 34 right := vector.MustTCols[bool](rv)[0] 35 36 if lv.IsScalar() { 37 vec := proc.AllocScalarVector(retType) 38 if lv.IsScalarNull() { 39 vector.SetCol(vec, []bool{false}) 40 } else { 41 vector.SetCol(vec, []bool{lefts[0] == right}) 42 } 43 return vec, nil 44 } else { 45 l := int64(len(lefts)) 46 col := make([]bool, l) 47 vec, err := proc.AllocVector(lv.Typ, l*1) 48 if err != nil { 49 return nil, err 50 } 51 for i := range lefts { 52 if nulls.Contains(lv.Nsp, uint64(i)) { 53 col[i] = false 54 } else { 55 col[i] = (lefts[i] == right) 56 } 57 } 58 vector.SetCol(vec, col) 59 return vec, nil 60 } 61 }