Skip to content

Commit 02baf18

Browse files
Test ANSI negation across integer widths
Cover overflow behavior for Int8, Int16, Int32, and Int64 in the native checked-negation unit test. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2308f6a commit 02baf18

1 file changed

Lines changed: 27 additions & 8 deletions

File tree

native-engine/datafusion-ext-exprs/src/spark_negative.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ mod test {
194194
use std::{error::Error, sync::Arc};
195195

196196
use arrow::{
197-
array::{ArrayRef, Float64Array, Int32Array, Int64Array},
197+
array::{ArrayRef, Float64Array, Int8Array, Int16Array, Int32Array, Int64Array},
198198
datatypes::{DataType, Field, Schema},
199199
record_batch::RecordBatch,
200200
};
@@ -204,13 +204,32 @@ mod test {
204204

205205
#[test]
206206
fn test_ansi_checked_negation() -> Result<(), Box<dyn Error>> {
207-
let batch = batch(
208-
DataType::Int64,
209-
Arc::new(Int64Array::from(vec![Some(i64::MIN)])),
210-
)?;
211-
let expr = expression(true);
212-
let err = expr.evaluate(&batch).expect_err("expected overflow");
213-
assert!(err.to_string().contains("[ARITHMETIC_OVERFLOW]"));
207+
let cases: Vec<(DataType, ArrayRef)> = vec![
208+
(
209+
DataType::Int8,
210+
Arc::new(Int8Array::from(vec![Some(i8::MIN)])),
211+
),
212+
(
213+
DataType::Int16,
214+
Arc::new(Int16Array::from(vec![Some(i16::MIN)])),
215+
),
216+
(
217+
DataType::Int32,
218+
Arc::new(Int32Array::from(vec![Some(i32::MIN)])),
219+
),
220+
(
221+
DataType::Int64,
222+
Arc::new(Int64Array::from(vec![Some(i64::MIN)])),
223+
),
224+
];
225+
226+
for (data_type, array) in cases {
227+
let batch = batch(data_type, array)?;
228+
let err = expression(true)
229+
.evaluate(&batch)
230+
.expect_err("expected overflow");
231+
assert!(err.to_string().contains("[ARITHMETIC_OVERFLOW]"));
232+
}
214233
Ok(())
215234
}
216235

0 commit comments

Comments
 (0)