You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "mustafasrepo (via GitHub)" <gi...@apache.org> on 2023/04/14 11:33:12 UTC

[GitHub] [arrow-datafusion] mustafasrepo commented on a diff in pull request #6003: Row accumulator support update Scalar values

mustafasrepo commented on code in PR #6003:
URL: https://github.com/apache/arrow-datafusion/pull/6003#discussion_r1166722648


##########
datafusion/core/src/physical_plan/aggregates/row_hash.rs:
##########
@@ -793,3 +865,232 @@ fn slice_and_maybe_filter(
     };
     Ok(filtered_arrays)
 }
+
+macro_rules! typed_cast_to_scalar {
+    ($array:expr, $index:expr, $ARRAYTYPE:ident, $SCALAR:ident) => {{
+        let array = $array.as_any().downcast_ref::<$ARRAYTYPE>().unwrap();
+        Ok(ScalarValue::$SCALAR(Some(array.value($index).into())))
+    }};
+}
+
+macro_rules! typed_cast_tz_to_scalar {
+    ($array:expr, $index:expr, $ARRAYTYPE:ident, $SCALAR:ident, $TZ:expr) => {{
+        let array = $array.as_any().downcast_ref::<$ARRAYTYPE>().unwrap();
+        Ok(ScalarValue::$SCALAR(
+            Some(array.value($index).into()),
+            $TZ.clone(),
+        ))
+    }};
+}
+
+/// This method is similar to Scalar::try_from_array except for the Null handling.
+/// This method returns [ScalarValue::Null] instead of [ScalarValue::Type(None)]
+fn col_to_scalar(

Review Comment:
   I think you can replace this function with
   ```rust
   /// This method is similar to Scalar::try_from_array except for the Null handling.
   /// This method returns [ScalarValue::Null] instead of [ScalarValue::Type(None)]
   fn col_to_scalar(
       array: &ArrayRef,
       filter: &Option<&BooleanArray>,
       row_index: usize,
   ) -> Result<ScalarValue> {
       if array.is_null(row_index) {
           return Ok(ScalarValue::Null);
       }
       if let Some(filter) = filter {
           if !filter.value(row_index) {
               return Ok(ScalarValue::Null);
           }
       }
       let mut res = ScalarValue::try_from_array(array, row_index)?;
       if res.is_null() {
           res = ScalarValue::Null;
       }
       Ok(res)
   }
   ```
   `ScalarValue::is_null` matches both `[ScalarValue::Null]` and `[ScalarValue::Type(None)]`. 



-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org