File tree Expand file tree Collapse file tree
datafusion/spark/src/function/conversion Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -60,7 +60,13 @@ fn float_secs_to_micros(val: f64, enable_ansi_mode: bool) -> Result<Option<i64>>
6060 return Ok ( None ) ;
6161 }
6262 let micros = val * MICROS_PER_SECOND as f64 ;
63- if micros. floor ( ) <= i64:: MAX as f64 && micros. ceil ( ) >= i64:: MIN as f64 {
63+
64+ // Bounds check for i64 range.
65+ // Note on precision: i64::MIN (-2^63) is exactly representable in f64,
66+ // but i64::MAX (2^63 - 1) is not - it rounds up to 2^63 (i64::MAX + 1).
67+ // We use strict `<` for the upper bound to reject values >= 2^63,
68+ // which correctly handles the precision loss edge case.
69+ if micros >= i64:: MIN as f64 && micros < i64:: MAX as f64 {
6470 Ok ( Some ( micros as i64 ) )
6571 } else {
6672 if enable_ansi_mode {
@@ -250,12 +256,11 @@ impl ScalarUDFImpl for SparkCast {
250256 }
251257
252258 fn return_field_from_args ( & self , args : ReturnFieldArgs ) -> Result < FieldRef > {
253- let nullable = args. arg_fields . iter ( ) . any ( |f| f. is_nullable ( ) ) ;
254259 let return_type = get_target_type_from_scalar_args (
255260 args. scalar_arguments ,
256261 self . timezone . clone ( ) ,
257262 ) ?;
258- Ok ( Arc :: new ( Field :: new ( self . name ( ) , return_type, nullable ) ) )
263+ Ok ( Arc :: new ( Field :: new ( self . name ( ) , return_type, true ) ) )
259264 }
260265
261266 fn invoke_with_args ( & self , args : ScalarFunctionArgs ) -> Result < ColumnarValue > {
You can’t perform that action at this time.
0 commit comments