coderfender commented on code in PR #2490:
URL: https://github.com/apache/datafusion-comet/pull/2490#discussion_r2389321434
##########
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:
I think so . I want to make sure there are no bad calls for this function
with input types other than decimal and boolean types and panic early. Please
advice if you think there is a better alternative
--
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]