github.com/matrixorigin/matrixone@v0.7.0/pkg/vectorize/timestamp/timestamp.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 timestamp 16 17 import ( 18 "time" 19 20 "github.com/matrixorigin/matrixone/pkg/container/nulls" 21 "github.com/matrixorigin/matrixone/pkg/container/types" 22 ) 23 24 var ( 25 DateToTimestamp = dateToTimestamp 26 DatetimeToTimestamp = datetimeToTimestamp 27 DateStringToTimestamp = dateStringToTimestamp 28 ) 29 30 func dateToTimestamp(loc *time.Location, xs []types.Date, ns *nulls.Nulls, rs []types.Timestamp) []types.Timestamp { 31 for i, x := range xs { 32 rs[i] = x.ToTimestamp(loc) 33 if !types.ValidTimestamp(rs[i]) { 34 rs[i] = 0 35 nulls.Add(ns, uint64(i)) 36 } 37 } 38 return rs 39 } 40 41 func datetimeToTimestamp(loc *time.Location, xs []types.Datetime, ns *nulls.Nulls, rs []types.Timestamp) []types.Timestamp { 42 for i, x := range xs { 43 rs[i] = x.ToTimestamp(loc) 44 if !types.ValidTimestamp(rs[i]) { 45 rs[i] = 0 46 nulls.Add(ns, uint64(i)) 47 } 48 } 49 return rs 50 } 51 52 func dateStringToTimestamp(loc *time.Location, xs []string, ns *nulls.Nulls, rs []types.Timestamp) []types.Timestamp { 53 for i, str := range xs { 54 t, err := types.ParseTimestamp(loc, str, 6) 55 if err != nil { 56 rs[i] = 0 57 nulls.Add(ns, uint64(i)) 58 continue 59 } 60 rs[i] = t 61 //for issue5305, do not do this check 62 //according to mysql, timestamp function actually return a datetime value 63 /* 64 if !types.ValidTimestamp(rs[i]) { 65 rs[i] = 0 66 nulls.Add(ns, uint64(i)) 67 } 68 */ 69 } 70 return rs 71 }