github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/plan/function/builtin/multi/ceil.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 multi 16 17 import ( 18 "strconv" 19 20 "github.com/matrixorigin/matrixone/pkg/container/types" 21 "github.com/matrixorigin/matrixone/pkg/container/vector" 22 "github.com/matrixorigin/matrixone/pkg/vectorize/ceil" 23 "github.com/matrixorigin/matrixone/pkg/vm/process" 24 ) 25 26 func CeilUint64(vecs []*vector.Vector, proc *process.Process) (*vector.Vector, error) { 27 return generalMathMulti("ceil", vecs, proc, ceil.CeilUint64) 28 } 29 30 func CeilInt64(vecs []*vector.Vector, proc *process.Process) (*vector.Vector, error) { 31 return generalMathMulti("ceil", vecs, proc, ceil.CeilInt64) 32 } 33 34 // Parse string to float instead of int. 35 func CeilStr(vecs []*vector.Vector, proc *process.Process) (*vector.Vector, error) { 36 values := vector.MustStrCols(vecs[0]) 37 floatvector, err := proc.AllocVectorOfRows(types.T_float64.ToType(), 0, nil) 38 if err != nil { 39 return nil, err 40 } 41 for _, v := range values { 42 float, err := strconv.ParseFloat(v, 64) 43 if err != nil { 44 return nil, err 45 } 46 if err := floatvector.Append(float, false, proc.Mp()); err != nil { 47 floatvector.Free(proc.Mp()) 48 return nil, err 49 } 50 } 51 newvecs := make([]*vector.Vector, 0) 52 newvecs = append(newvecs, floatvector) 53 return CeilFloat64(newvecs, proc) 54 } 55 56 func CeilFloat64(vecs []*vector.Vector, proc *process.Process) (*vector.Vector, error) { 57 return generalMathMulti("ceil", vecs, proc, ceil.CeilFloat64) 58 } 59 60 func CeilDecimal128(vecs []*vector.Vector, proc *process.Process) (*vector.Vector, error) { 61 scale := vecs[0].Typ.Scale 62 cb := func(vs []types.Decimal128, rs []types.Decimal128, digits int64) []types.Decimal128 { 63 return ceil.CeilDecimal128(scale, vs, rs, digits) 64 } 65 return generalMathMulti("ceil", vecs, proc, cb) 66 }