github.com/matrixorigin/matrixone@v0.7.0/pkg/vectorize/month/month.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 month 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/container/nulls" 19 "github.com/matrixorigin/matrixone/pkg/container/types" 20 ) 21 22 func DateToMonth(xs []types.Date, rs []uint8) []uint8 { 23 for i, x := range xs { 24 rs[i] = x.Month() 25 } 26 return rs 27 } 28 29 func DatetimeToMonth(xs []types.Datetime, rs []uint8) []uint8 { 30 for i, x := range xs { 31 rs[i] = x.Month() 32 } 33 return rs 34 } 35 36 func DateStringToMonth(xs []string, ns *nulls.Nulls, rs []uint8) []uint8 { 37 for i, str := range xs { 38 d, e := types.ParseDateCast(str) 39 if e != nil { 40 // XXX FUBAR should raise instead of intruducting nulls. 41 // set null 42 nulls.Add(ns, uint64(i)) 43 rs[i] = 0 44 continue 45 } 46 rs[i] = d.Month() 47 } 48 return rs 49 }