liukun4515 commented on a change in pull request #1407:
URL: https://github.com/apache/arrow-datafusion/pull/1407#discussion_r766237247
##########
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;
+ let mut has_value = false;
+ for i in 0..array.len() {
+ if !has_value && array.is_valid(i) {
+ has_value = true;
+ result = array.value(i);
+ }
+ if array.is_valid(i) {
+ result = result.$OP(array.value(i));
+ }
+ }
+ ScalarValue::Decimal128(Some(result), *$PRECISION, *$SCALE)
+ }
+ }
+ }};
+}
+
// Statically-typed version of min/max(array) -> ScalarValue for non-string
types.
// this is a macro to support both operations (min and max).
macro_rules! min_max_batch {
($VALUES:expr, $OP:ident) => {{
match $VALUES.data_type() {
+ DataType::Decimal(precision, scale) => {
+ typed_min_max_batch_decimal128!($VALUES, precision, scale, $OP)
Review comment:
Yes, when I finish the task of aggregating with decimal data type, I
will begin to do basic operations in arrow-rs for decimal data type.
--
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]