Skip to content

Commit 0102363

Browse files
committed
ceil_fix_tests
1 parent 28dc07c commit 0102363

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

datafusion/spark/src/function/math/ceil.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,11 @@ use std::any::Any;
2929
use 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)]
4238
pub 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.
10196
pub 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;

datafusion/spark/src/function/math/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
// under the License.
1717

1818
pub mod abs;
19-
pub mod ceil;
2019
pub mod bin;
20+
pub mod ceil;
2121
pub mod expm1;
2222
pub mod factorial;
2323
pub mod hex;
@@ -44,7 +44,7 @@ make_udf_function!(width_bucket::SparkWidthBucket, width_bucket);
4444
make_udf_function!(trigonometry::SparkCsc, csc);
4545
make_udf_function!(trigonometry::SparkSec, sec);
4646
make_udf_function!(negative::SparkNegative, negative);
47-
make_udf_function!(bin::SparkBin, bin, ceil::SparkCeil, ceil);
47+
make_udf_function!(bin::SparkBin, bin, ceil);
4848

4949
pub mod expr_fn {
5050
use datafusion_functions::export_functions;

0 commit comments

Comments
 (0)