github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/plan/function/operator/isnot.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 IsNot(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  	if !rv.IsScalar() || rv.IsScalarNull() {
    31  		return nil, moerr.NewInternalError(proc.Ctx, "second parameter of IS must be TRUE or FALSE")
    32  	}
    33  	right := vector.MustTCols[bool](rv)[0]
    34  
    35  	if lv.IsScalar() {
    36  		vec := proc.AllocScalarVector(retType)
    37  		if lv.IsScalarNull() {
    38  			vector.SetCol(vec, []bool{false})
    39  		} else {
    40  			lefts := vector.MustTCols[bool](lv)
    41  			vector.SetCol(vec, []bool{lefts[0] != right})
    42  		}
    43  		return vec, nil
    44  	} else {
    45  		lefts := vector.MustTCols[bool](lv)
    46  		l := int64(len(lefts))
    47  		col := make([]bool, l)
    48  		vec, err := proc.AllocVector(lv.Typ, l*1)
    49  		if err != nil {
    50  			return nil, err
    51  		}
    52  		for i := range lefts {
    53  			if nulls.Contains(lv.Nsp, uint64(i)) {
    54  				col[i] = false
    55  			} else {
    56  				col[i] = (lefts[i] != right)
    57  			}
    58  		}
    59  		vector.SetCol(vec, col)
    60  		return vec, nil
    61  	}
    62  }