@@ -29,15 +29,11 @@ use std::any::Any;
2929use std:: sync:: Arc ;
3030
3131/// Spark-compatible `ceil` function.
32- ///
33- /// Returns the smallest integer greater than or equal to the input.
34- /// Unlike standard DataFusion ceil, this returns Int64 for float/integer
35- /// inputs (matching Spark behavior).
36- ///
37- /// # Supported types
38- /// - Float32, Float64: returns Int64
39- /// - Int8, Int16, Int32, Int64: returns Int64
40- /// - Decimal128(p, s): returns Decimal128(p, s) (preserves precision and scale)
32+ /// Unlike standard DataFusion ceil, this returns Int64 for float/integer (per Spark spec)
33+ /// Supported types
34+ /// Float32, Float64 -> Int64
35+ /// Int8, Int16, Int32, Int64 -> Int64
36+ /// Decimal128(p, s): -> Decimal128(p, s) (preserves precision and scale)
4137#[ derive( Debug , PartialEq , Eq , Hash ) ]
4238pub struct SparkCeil {
4339 signature : Signature ,
@@ -97,7 +93,6 @@ impl ScalarUDFImpl for SparkCeil {
9793 }
9894}
9995
100- /// Computes the Spark-compatible ceiling of the input.
10196pub fn spark_ceil ( args : & [ ColumnarValue ] ) -> Result < ColumnarValue , DataFusionError > {
10297 let value = & args[ 0 ] ;
10398 match value {
@@ -132,7 +127,7 @@ pub fn spark_ceil(args: &[ColumnarValue]) -> Result<ColumnarValue, DataFusionErr
132127 if * scale <= 0 {
133128 Ok ( ColumnarValue :: Array ( Arc :: clone ( array) ) )
134129 } else {
135- let f = decimal_ceil_f ( * scale) ;
130+ let f = decimal_ceil_helper ( * scale) ;
136131 let input = array. as_primitive :: < Decimal128Type > ( ) ;
137132 let result: Decimal128Array = unary ( input, & f) ;
138133 let result =
@@ -167,7 +162,7 @@ pub fn spark_ceil(args: &[ColumnarValue]) -> Result<ColumnarValue, DataFusionErr
167162 * v, * precision, * scale,
168163 ) ) )
169164 } else {
170- let f = decimal_ceil_f ( * scale) ;
165+ let f = decimal_ceil_helper ( * scale) ;
171166 let result = v. map ( f) ;
172167 Ok ( ColumnarValue :: Scalar ( ScalarValue :: Decimal128 (
173168 result, * precision, * scale,
@@ -184,9 +179,8 @@ pub fn spark_ceil(args: &[ColumnarValue]) -> Result<ColumnarValue, DataFusionErr
184179 }
185180}
186181
187- /// Returns a closure that computes ceil for decimal values.
188182#[ inline]
189- fn decimal_ceil_f ( scale : i8 ) -> impl Fn ( i128 ) -> i128 {
183+ fn decimal_ceil_helper ( scale : i8 ) -> impl Fn ( i128 ) -> i128 {
190184 let divisor = 10_i128 . pow ( scale as u32 ) ;
191185 move |x : i128 | {
192186 let quotient = x / divisor;
0 commit comments