Skip to content

Commit 51a97d7

Browse files
committed
fix
1 parent 214009b commit 51a97d7

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

datafusion/functions/src/math/factorial.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ use arrow::datatypes::{DECIMAL256_MAX_PRECISION, DataType, Int64Type};
2323
use arrow_buffer::i256;
2424

2525
use datafusion_common::{
26-
DataFusionError, Result, ScalarValue, internal_err, utils::take_function_args,
26+
DataFusionError, Result, ScalarValue, exec_err, internal_err,
27+
utils::take_function_args,
2728
};
2829
use datafusion_expr::{
2930
ColumnarValue, Documentation, ScalarFunctionArgs, ScalarUDFImpl, Signature,
@@ -158,7 +159,7 @@ const FACTORIALS: [i64; 21] = [
158159

159160
fn compute_factorial(n: i64) -> Result<i256> {
160161
if n < 0 {
161-
return Ok(i256::from(1));
162+
return exec_err!("factorial of a negative number is undefined");
162163
}
163164

164165
if n < FACTORIALS.len() as i64 {
@@ -173,9 +174,7 @@ fn compute_factorial(n: i64) -> Result<i256> {
173174
}
174175

175176
if result.to_string().len() > DECIMAL256_MAX_PRECISION as usize {
176-
return Err(DataFusionError::Execution(format!(
177-
"Overflow happened on FACTORIAL({n})"
178-
)));
177+
return exec_err!("Overflow happened on FACTORIAL({n})");
179178
}
180179

181180
Ok(result)

0 commit comments

Comments
 (0)