@@ -19,12 +19,14 @@ use std::any::Any;
1919use std:: sync:: Arc ;
2020
2121use crate :: datetime:: common:: * ;
22+ use arrow:: array:: Float64Array ;
2223use arrow:: datatypes:: DataType :: * ;
2324use arrow:: datatypes:: TimeUnit :: { Microsecond , Millisecond , Nanosecond , Second } ;
2425use arrow:: datatypes:: {
2526 ArrowTimestampType , DataType , TimeUnit , TimestampMicrosecondType ,
2627 TimestampMillisecondType , TimestampNanosecondType , TimestampSecondType ,
2728} ;
29+ use datafusion_common:: format:: DEFAULT_CAST_OPTIONS ;
2830use datafusion_common:: { exec_err, Result , ScalarType , ScalarValue } ;
2931use datafusion_expr:: {
3032 ColumnarValue , Documentation , ScalarUDFImpl , Signature , Volatility ,
@@ -319,9 +321,22 @@ impl ScalarUDFImpl for ToTimestampFunc {
319321 Int32 | Int64 => args[ 0 ]
320322 . cast_to ( & Timestamp ( Second , None ) , None ) ?
321323 . cast_to ( & Timestamp ( Nanosecond , None ) , None ) ,
322- Null | Float64 | Timestamp ( _, None ) => {
324+ Null | Timestamp ( _, None ) => {
323325 args[ 0 ] . cast_to ( & Timestamp ( Nanosecond , None ) , None )
324326 }
327+ Float64 => {
328+ let rescaled = arrow:: compute:: kernels:: numeric:: mul (
329+ & args[ 0 ] . to_array ( 1 ) ?,
330+ & arrow:: array:: Scalar :: new ( Float64Array :: from ( vec ! [
331+ 1_000_000_000f64 ,
332+ ] ) ) ,
333+ ) ?;
334+ Ok ( ColumnarValue :: Array ( arrow:: compute:: cast_with_options (
335+ & rescaled,
336+ & Timestamp ( Nanosecond , None ) ,
337+ & DEFAULT_CAST_OPTIONS ,
338+ ) ?) )
339+ }
325340 Timestamp ( _, Some ( tz) ) => {
326341 args[ 0 ] . cast_to ( & Timestamp ( Nanosecond , Some ( tz) ) , None )
327342 }
0 commit comments