github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/plan/function/operator/not.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/container/nulls" 19 "github.com/matrixorigin/matrixone/pkg/container/vector" 20 "github.com/matrixorigin/matrixone/pkg/vm/process" 21 ) 22 23 func NotScalar(_, nsv *vector.Vector, col1, col2 []bool, proc *process.Process) (*vector.Vector, error) { 24 length := vector.Length(nsv) 25 vec := allocateBoolVector(length, proc) 26 vcols := vec.Col.([]bool) 27 value := col1[0] 28 for i := range vcols { 29 vcols[i] = value && col2[i] 30 } 31 nulls.Or(nsv.Nsp, nil, vec.Nsp) 32 return vec, nil 33 } 34 35 func Not(vs []*vector.Vector, proc *process.Process) (*vector.Vector, error) { 36 v1 := vs[0] 37 col1 := vector.MustTCols[bool](v1) 38 if v1.IsScalarNull() { 39 return proc.AllocScalarNullVector(boolType), nil 40 } 41 42 c1 := v1.IsScalar() 43 switch { 44 case c1: 45 vec := proc.AllocScalarVector(boolType) 46 vec.Col = make([]bool, 1) 47 vec.Col.([]bool)[0] = !col1[0] 48 return vec, nil 49 } 50 length := vector.Length(v1) 51 vec := allocateBoolVector(length, proc) 52 vcols := vec.Col.([]bool) 53 for i := range vcols { 54 vcols[i] = !col1[i] 55 } 56 nulls.Or(v1.Nsp, nil, vec.Nsp) 57 return vec, nil 58 }