github.com/matrixorigin/matrixone@v0.7.0/pkg/vectorize/space/space.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 // for input value greater than 8000, function space will output NULL, 16 // for input value less than 0, function space will output empty string "" 17 // for positive float inputs, function space will round(away from zero) 18 19 package space 20 21 import ( 22 "strings" 23 24 "github.com/matrixorigin/matrixone/pkg/common/moerr" 25 26 "github.com/matrixorigin/matrixone/pkg/container/types" 27 ) 28 29 const ( 30 MaxAllowedValue = 8000 31 ) 32 33 func FillSpacesNumber[T types.BuiltinNumber](originalVecCol []T, rs []string) ([]string, error) { 34 for i, length := range originalVecCol { 35 var ilen int 36 if length < 0 { 37 ilen = 0 38 } else { 39 ilen = int(length) 40 if ilen > MaxAllowedValue || ilen < 0 { 41 return nil, moerr.NewInvalidInputNoCtx("the space count is greater than max allowed value %d", MaxAllowedValue) 42 } 43 } 44 rs[i] = strings.Repeat(" ", int(ilen)) 45 } 46 return rs, nil 47 }