You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/06/16 16:12:44 UTC

[GitHub] [arrow] nealrichardson commented on a change in pull request #7451: ARROW-8769: [C++][R] Add convenience accessor for StructScalar fields

nealrichardson commented on a change in pull request #7451:
URL: https://github.com/apache/arrow/pull/7451#discussion_r440971906



##########
File path: r/R/compute.R
##########
@@ -42,26 +42,32 @@ mean.ChunkedArray <- mean.Array
 #' @export
 mean.Scalar <- mean.Array
 
+#' @export
 min.Array <- function(..., na.rm = FALSE) {
-  extrema <- scalar_aggregate("minmax", ..., na.rm = na.rm)
-  # TODO: StructScalar needs field accessor methods in C++: ARROW-9070
-  Scalar$create(as.vector(extrema)$min)
+  scalar_aggregate("minmax", ..., na.rm = na.rm)$GetFieldByName("min")
+}
+
+#' @export
+max.Array <- function(..., na.rm = FALSE) {
+  scalar_aggregate("minmax", ..., na.rm = na.rm)$GetFieldByName("max")
 }
 
 scalar_aggregate <- function(FUN, ..., na.rm = FALSE) {
   a <- collect_arrays_from_dots(list(...))
   if (!na.rm && a$null_count > 0) {
-    # Arrow sum/mean function always drops NAs so handle that here
-    # https://issues.apache.org/jira/browse/ARROW-9054
-    Scalar$create(NA_integer_, type = a$type)
-  } else {
-    if (inherits(a$type, "Boolean")) {
-      # Bool sum/mean not implemented so cast to int
-      # https://issues.apache.org/jira/browse/ARROW-9055
-      a <- a$cast(int8())
+    if (FUN == 'mean' || FUN == 'sum') {

Review comment:
       ```suggestion
       if (FUN %in% c("mean", "sum")) {
   ```




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

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