parthchandra commented on code in PR #2490:
URL: https://github.com/apache/datafusion-comet/pull/2490#discussion_r2393054549


##########
native/spark-expr/src/conversion_funcs/cast.rs:
##########
@@ -1528,6 +1529,32 @@ where
     Ok(Arc::new(output_array))
 }
 
+fn spark_cast_decimal_to_boolean(
+    array: &dyn Array,
+    from_type: &DataType,
+    to_type: &DataType,
+) -> SparkResult<ArrayRef> {
+    match (from_type, to_type) {
+        (DataType::Decimal128(_p, _s), DataType::Boolean) => {
+            let decimal_array = array.as_primitive::<Decimal128Type>();
+            let mut result = 
BooleanBuilder::with_capacity(decimal_array.len());
+            for i in 0..decimal_array.len() {
+                if decimal_array.is_null(i) {
+                    result.append_null()
+                } else if decimal_array.value(i).is_zero() {
+                    result.append_value(false);
+                } else {
+                    result.append_value(true);
+                }
+            }
+            Ok(Arc::new(result.finish()))
+        }
+        _ => panic!(
+            "{}",

Review Comment:
   >  wanted to implement it in a similar fashion as `unreachable!` macro 
   Since this already returns a Result, maybe you can just return an Err. 
   ```
           return { Err(SparkError::Internal(msg)) }
   ```
   



-- 
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