liukun4515 commented on a change in pull request #1407: URL: https://github.com/apache/arrow-datafusion/pull/1407#discussion_r766246972
########## File path: datafusion/src/physical_plan/expressions/min_max.rs ########## @@ -129,11 +131,49 @@ macro_rules! typed_min_max_batch { }}; } +// TODO implement this in arrow-rs with simd +// https://github.com/apache/arrow-rs/issues/1010 +// Statically-typed version of min/max(array) -> ScalarValue for decimal types. +macro_rules! typed_min_max_batch_decimal128 { + ($VALUES:expr, $PRECISION:ident, $SCALE:ident, $OP:ident) => {{ + let null_count = $VALUES.null_count(); + if null_count == $VALUES.len() { + ScalarValue::Decimal128(None, *$PRECISION, *$SCALE) + } else { + let array = $VALUES.as_any().downcast_ref::<DecimalArray>().unwrap(); + if null_count == 0 { + // there is no null value + let mut result = array.value(0); + for i in 1..array.len() { + result = result.$OP(array.value(i)); + } + ScalarValue::Decimal128(Some(result), *$PRECISION, *$SCALE) + } else { + let mut result = 0_i128; Review comment: I recheck your suggestion and find some bugs. For example, if all value in the array is less than zero, it may be [-1,-3,-3] and we want to get the max value of them. initially, we set the result as `Some(0)` and follow your suggestion code, we will get the `0` as the max value for the result. I think we should can just change to that ``` let mut result = 0_i128; ->>> let mut result : i128 = 0; ``` In addition the `unwrap_or` is ``` pub fn unwrap_or(self, default: T) -> T { match self { Some(x) => x, None => default, } } ``` -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org