github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/plan/function/builtin/multi/regular_instr.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 multi
    16  
    17  import (
    18  	"github.com/matrixorigin/matrixone/pkg/container/types"
    19  	"github.com/matrixorigin/matrixone/pkg/container/vector"
    20  	"github.com/matrixorigin/matrixone/pkg/vectorize/regular"
    21  	"github.com/matrixorigin/matrixone/pkg/vm/process"
    22  )
    23  
    24  func RegularInstr(vectors []*vector.Vector, proc *process.Process) (*vector.Vector, error) {
    25  	firstVector := vectors[0]
    26  	secondVector := vectors[1]
    27  	firstValues := vector.MustStrCols(firstVector)
    28  	secondValues := vector.MustStrCols(secondVector)
    29  	resultType := types.T_int64.ToType()
    30  
    31  	//maxLen
    32  	maxLen := vector.Length(vectors[0])
    33  	for i := range vectors {
    34  		val := vector.Length(vectors[i])
    35  		if val > maxLen {
    36  			maxLen = val
    37  		}
    38  	}
    39  
    40  	//optional arguments
    41  	var pos []int64
    42  	var occ []int64
    43  	var opt []uint8
    44  	var match_type []string
    45  
    46  	//different parameter length conditions
    47  	switch len(vectors) {
    48  	case 2:
    49  		pos = []int64{1}
    50  		occ = []int64{1}
    51  		opt = []uint8{0}
    52  		match_type = []string{"c"}
    53  
    54  	case 3:
    55  		pos = vector.MustTCols[int64](vectors[2])
    56  		occ = []int64{1}
    57  		opt = []uint8{0}
    58  		match_type = []string{"c"}
    59  	case 4:
    60  		pos = vector.MustTCols[int64](vectors[2])
    61  		occ = vector.MustTCols[int64](vectors[3])
    62  		opt = []uint8{0}
    63  		match_type = []string{"c"}
    64  	case 5:
    65  		pos = vector.MustTCols[int64](vectors[2])
    66  		occ = vector.MustTCols[int64](vectors[3])
    67  		opt = vector.MustTCols[uint8](vectors[4])
    68  		match_type = []string{"c"}
    69  	}
    70  
    71  	if firstVector.IsScalarNull() || secondVector.IsScalarNull() {
    72  		return proc.AllocScalarNullVector(resultType), nil
    73  	}
    74  
    75  	resultVector, err := proc.AllocVectorOfRows(resultType, int64(maxLen), nil)
    76  	if err != nil {
    77  		return nil, err
    78  	}
    79  	resultValues := vector.MustTCols[int64](resultVector)
    80  	err = regular.RegularInstrWithArrays(firstValues, secondValues, pos, occ, opt, match_type, firstVector.Nsp, secondVector.Nsp, resultVector.Nsp, resultValues, maxLen)
    81  	if err != nil {
    82  		return nil, err
    83  	}
    84  	return resultVector, nil
    85  
    86  }