Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrove committed Jul 8, 2024
1 parent 9e08917 commit 2749114
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions native/spark-expr/src/abs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

//! Spark-compatible implementation of abs function
use std::{any::Any, sync::Arc};
use arrow::array::{Array, Int32Array, Int32Builder};
use std::{any::Any, sync::Arc};

use arrow::datatypes::DataType;
use arrow_schema::ArrowError;
Expand Down Expand Up @@ -92,20 +92,23 @@ impl ScalarUDFImpl for Abs {

#[cfg(test)]
mod test {
use std::sync::Arc;
use crate::abs::Abs;
use crate::EvalMode;
use arrow::array::Int32Array;
use datafusion::logical_expr::{ColumnarValue, ScalarUDFImpl};
use datafusion_common::Result;
use crate::abs::Abs;
use crate::EvalMode;
use std::sync::Arc;

#[test]
fn test_no_overflow() -> Result<()> {
let input_values: Arc<Int32Array> = Arc::new(vec![i32::MIN+1, i32::MAX, -10, 10].into());
let input_values: Arc<Int32Array> = Arc::new(vec![i32::MIN + 1, i32::MAX, -10, 10].into());
for mode in [EvalMode::Legacy, EvalMode::Ansi] {
let abs = Abs::new(mode, "Int32".to_string())?;
let result = abs.invoke(&[ColumnarValue::Array(input_values.clone())])?;
assert_eq!("Array(PrimitiveArray<Int32>\n[\n 2147483647,\n 2147483647,\n 10,\n 10,\n])", format!("{result:?}"));
assert_eq!(
"Array(PrimitiveArray<Int32>\n[\n 2147483647,\n 2147483647,\n 10,\n 10,\n])",
format!("{result:?}")
);
}
Ok(())
}
Expand All @@ -116,7 +119,10 @@ mod test {
let input_values: Int32Array = vec![i32::MIN, i32::MAX, -10, 10].into();
let abs = Abs::new(EvalMode::Legacy, "Int32".to_string())?;
let result = abs.invoke(&[ColumnarValue::Array(Arc::new(input_values))])?;
assert_eq!("Array(PrimitiveArray<Int32>\n[\n -2147483648,\n 2147483647,\n 10,\n 10,\n])", format!("{result:?}"));
assert_eq!(
"Array(PrimitiveArray<Int32>\n[\n -2147483648,\n 2147483647,\n 10,\n 10,\n])",
format!("{result:?}")
);
Ok(())
}

Expand Down

0 comments on commit 2749114

Please sign in to comment.