andygrove commented on code in PR #4940:
URL: https://github.com/apache/datafusion-comet/pull/4940#discussion_r3597076683


##########
native/spark-expr/src/conversion_funcs/numeric.rs:
##########
@@ -1287,6 +1292,48 @@ mod tests {
         assert!(casted.is_null(9));
     }
 
+    #[test]
+    #[cfg_attr(miri, ignore)]
+    fn test_cast_float_to_decimal_no_overflow_fast_path() {
+        // All values fit precision 10, scale 2, so the vectorized fast path 
is taken and the
+        // input null is preserved.
+        let a: ArrayRef = Arc::new(Float64Array::from(vec![
+            Some(42.0),
+            Some(-1.5),
+            None,
+            Some(0.0),
+        ]));
+        let b =
+            cast_floating_point_to_decimal128::<Float64Type>(&a, 10, 2, 
EvalMode::Legacy).unwrap();
+        let d = b.as_primitive::<Decimal128Type>();
+        assert_eq!(d.value(0), 4200); // 42.00
+        assert_eq!(d.value(1), -150); // -1.50
+        assert!(d.is_null(2));
+        assert_eq!(d.value(3), 0);
+        assert_eq!(d.data_type(), &DataType::Decimal128(10, 2));
+    }
+
+    #[test]
+    #[cfg_attr(miri, ignore)]
+    fn test_cast_float_to_decimal_ansi_no_overflow() {
+        let a: ArrayRef = Arc::new(Float64Array::from(vec![Some(42.0), None, 
Some(-1.5)]));
+        let b =
+            cast_floating_point_to_decimal128::<Float64Type>(&a, 10, 2, 
EvalMode::Ansi).unwrap();
+        let d = b.as_primitive::<Decimal128Type>();
+        assert_eq!(d.value(0), 4200);
+        assert!(d.is_null(1));
+        assert_eq!(d.value(2), -150);
+    }
+
+    #[test]
+    #[cfg_attr(miri, ignore)]
+    fn test_cast_float_to_decimal_ansi_overflow_errors() {

Review Comment:
   Extended `test_cast_float_to_decimal_ansi_nan_errors` covers both `f64::NAN` 
and `f64::INFINITY` under ANSI and asserts the reported `value` strings 
(`"NaN"`, `"inf"`) — d2862e18d.



##########
native/spark-expr/src/conversion_funcs/numeric.rs:
##########
@@ -1287,6 +1292,48 @@ mod tests {
         assert!(casted.is_null(9));
     }
 
+    #[test]
+    #[cfg_attr(miri, ignore)]
+    fn test_cast_float_to_decimal_no_overflow_fast_path() {
+        // All values fit precision 10, scale 2, so the vectorized fast path 
is taken and the
+        // input null is preserved.
+        let a: ArrayRef = Arc::new(Float64Array::from(vec![
+            Some(42.0),
+            Some(-1.5),
+            None,
+            Some(0.0),
+        ]));
+        let b =
+            cast_floating_point_to_decimal128::<Float64Type>(&a, 10, 2, 
EvalMode::Legacy).unwrap();
+        let d = b.as_primitive::<Decimal128Type>();
+        assert_eq!(d.value(0), 4200); // 42.00
+        assert_eq!(d.value(1), -150); // -1.50
+        assert!(d.is_null(2));
+        assert_eq!(d.value(3), 0);
+        assert_eq!(d.data_type(), &DataType::Decimal128(10, 2));
+    }
+
+    #[test]
+    #[cfg_attr(miri, ignore)]
+    fn test_cast_float_to_decimal_ansi_no_overflow() {
+        let a: ArrayRef = Arc::new(Float64Array::from(vec![Some(42.0), None, 
Some(-1.5)]));
+        let b =
+            cast_floating_point_to_decimal128::<Float64Type>(&a, 10, 2, 
EvalMode::Ansi).unwrap();
+        let d = b.as_primitive::<Decimal128Type>();
+        assert_eq!(d.value(0), 4200);
+        assert!(d.is_null(1));
+        assert_eq!(d.value(2), -150);
+    }
+
+    #[test]
+    #[cfg_attr(miri, ignore)]
+    fn test_cast_float_to_decimal_ansi_overflow_errors() {

Review Comment:
   Done — the test now matches on `SparkError::NumericValueOutOfRange { value, 
precision, scale }` and asserts every field. d2862e18d.



##########
native/spark-expr/src/conversion_funcs/numeric.rs:
##########
@@ -1287,6 +1292,48 @@ mod tests {
         assert!(casted.is_null(9));
     }
 
+    #[test]
+    #[cfg_attr(miri, ignore)]
+    fn test_cast_float_to_decimal_no_overflow_fast_path() {
+        // All values fit precision 10, scale 2, so the vectorized fast path 
is taken and the
+        // input null is preserved.
+        let a: ArrayRef = Arc::new(Float64Array::from(vec![
+            Some(42.0),
+            Some(-1.5),
+            None,
+            Some(0.0),
+        ]));
+        let b =
+            cast_floating_point_to_decimal128::<Float64Type>(&a, 10, 2, 
EvalMode::Legacy).unwrap();
+        let d = b.as_primitive::<Decimal128Type>();
+        assert_eq!(d.value(0), 4200); // 42.00
+        assert_eq!(d.value(1), -150); // -1.50
+        assert!(d.is_null(2));
+        assert_eq!(d.value(3), 0);
+        assert_eq!(d.data_type(), &DataType::Decimal128(10, 2));
+    }
+
+    #[test]
+    #[cfg_attr(miri, ignore)]
+    fn test_cast_float_to_decimal_ansi_no_overflow() {
+        let a: ArrayRef = Arc::new(Float64Array::from(vec![Some(42.0), None, 
Some(-1.5)]));
+        let b =
+            cast_floating_point_to_decimal128::<Float64Type>(&a, 10, 2, 
EvalMode::Ansi).unwrap();
+        let d = b.as_primitive::<Decimal128Type>();
+        assert_eq!(d.value(0), 4200);
+        assert!(d.is_null(1));
+        assert_eq!(d.value(2), -150);
+    }
+
+    #[test]
+    #[cfg_attr(miri, ignore)]
+    fn test_cast_float_to_decimal_ansi_overflow_errors() {
+        // 4242.42 * 10^2 = 424242 does not fit precision 4 -> ANSI error.
+        let a: ArrayRef = Arc::new(Float64Array::from(vec![Some(1.0), 
Some(4242.42)]));
+        let result = cast_floating_point_to_decimal128::<Float64Type>(&a, 4, 
2, EvalMode::Ansi);
+        assert!(result.is_err());
+    }
+

Review Comment:
   Done — added a second overflowing row (`9999.99`) after `4242.42` and 
asserted `value == "4242.42"`, which would fail if the rescan reported the last 
offender instead of the first. d2862e18d.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to