github.com/matrixorigin/matrixone@v0.7.0/pkg/compare/strcompare.go (about)

     1  // Copyright 2021 - 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 compare
    16  
    17  import (
    18  	"bytes"
    19  
    20  	"github.com/matrixorigin/matrixone/pkg/container/nulls"
    21  	"github.com/matrixorigin/matrixone/pkg/container/vector"
    22  	"github.com/matrixorigin/matrixone/pkg/vm/process"
    23  )
    24  
    25  func (c *strCompare) Vector() *vector.Vector {
    26  	return c.vs[0]
    27  }
    28  
    29  func (c *strCompare) Set(idx int, v *vector.Vector) {
    30  	c.vs[idx] = v
    31  }
    32  
    33  func (c *strCompare) Copy(vecSrc, vecDst int, src, dst int64, proc *process.Process) error {
    34  	if nulls.Contains(c.vs[vecSrc].Nsp, uint64(src)) {
    35  		nulls.Add(c.vs[vecDst].Nsp, uint64(dst))
    36  		return nil
    37  	}
    38  	nulls.Del(c.vs[vecDst].Nsp, uint64(dst))
    39  	return vector.Copy(c.vs[vecDst], c.vs[vecSrc], dst, src, proc.Mp())
    40  }
    41  
    42  func (c *strCompare) Compare(veci, vecj int, vi, vj int64) int {
    43  	cmp := nullsCompare(c.vs[veci].Nsp, c.vs[vecj].Nsp, vi, vj, c.nullsLast)
    44  	if cmp != 0 {
    45  		return cmp
    46  	}
    47  	if nulls.Contains(c.vs[veci].Nsp, uint64(vi)) && nulls.Contains(c.vs[veci].Nsp, uint64(vj)) {
    48  		return 0
    49  	}
    50  	x := c.vs[veci].GetBytes(vi)
    51  	y := c.vs[vecj].GetBytes(vj)
    52  	if c.desc {
    53  		return bytes.Compare(y, x)
    54  	}
    55  	return bytes.Compare(x, y)
    56  }