paleolimbot commented on a change in pull request #11612:
URL: https://github.com/apache/arrow/pull/11612#discussion_r744634095



##########
File path: r/R/dplyr-summarize.R
##########
@@ -218,8 +218,16 @@ summarize_eval <- function(name, quosure, ctx, hash, 
recurse = FALSE) {
   } else if (all(inner_agg_exprs)) {
     # Something like: fun(agg(x), agg(y))
     # So based on the aggregations that have been extracted, mutate after
+    agg_field_refs <- make_field_refs(names(ctx$aggregations))
+    agg_field_types <- lapply(ctx$aggregations, function(x) x$data$type())

Review comment:
       Almost...it's more like `list(..temp0 = list(fun = "sum", data = 
Expression(...), options = list()))`
   
   <details>
   
   ``` r
   library(arrow, warn.conflicts = FALSE)
   library(dplyr, warn.conflicts = FALSE)
   
   x <- RecordBatch$create(x = c(0, 1, 1), y = c(2, 3, 5), z = c(8, 13, 21)) %>%
     mutate(new_col = x + 0.1) %>%
     group_by(x) %>%
     summarise(r = ifelse(n() > 1, mean(y), mean(z)))
   
   str(x$.data$aggregations)
   #> List of 3
   #>  $ ..temp0:List of 3
   #>   ..$ fun    : chr "sum"
   #>   ..$ data   :Classes 'Expression', 'ArrowObject', 'R6' <Expression>
   #>   Inherits from: <ArrowObject>
   #>   Public:
   #>     .:xp:.: externalptr
   #>     cast: function (to_type, safe = TRUE, ...) 
   #>     clone: function (deep = FALSE) 
   #>     Equals: function (other, ...) 
   #>     field_name: active binding
   #>     initialize: function (xp) 
   #>     invalidate: function () 
   #>     pointer: function () 
   #>     print: function (...) 
   #>     schema: Schema, ArrowObject, R6
   #>     set_pointer: function (xp) 
   #>     ToString: function () 
   #>     type: function (schema = self$schema) 
   #>     type_id: function (schema = self$schema)  
   #>   ..$ options: list()
   #>  $ ..temp1:List of 3
   #>   ..$ fun    : chr "mean"
   #>   ..$ data   :Classes 'Expression', 'ArrowObject', 'R6' <Expression>
   #>   Inherits from: <ArrowObject>
   #>   Public:
   #>     .:xp:.: externalptr
   #>     cast: function (to_type, safe = TRUE, ...) 
   #>     clone: function (deep = FALSE) 
   #>     Equals: function (other, ...) 
   #>     field_name: active binding
   #>     initialize: function (xp) 
   #>     invalidate: function () 
   #>     pointer: function () 
   #>     print: function (...) 
   #>     schema: Schema, ArrowObject, R6
   #>     set_pointer: function (xp) 
   #>     ToString: function () 
   #>     type: function (schema = self$schema) 
   #>     type_id: function (schema = self$schema)  
   #>   ..$ options:List of 2
   #>   .. ..$ skip_nulls: logi FALSE
   #>   .. ..$ min_count : int 0
   #>  $ ..temp2:List of 3
   #>   ..$ fun    : chr "mean"
   #>   ..$ data   :Classes 'Expression', 'ArrowObject', 'R6' <Expression>
   #>   Inherits from: <ArrowObject>
   #>   Public:
   #>     .:xp:.: externalptr
   #>     cast: function (to_type, safe = TRUE, ...) 
   #>     clone: function (deep = FALSE) 
   #>     Equals: function (other, ...) 
   #>     field_name: active binding
   #>     initialize: function (xp) 
   #>     invalidate: function () 
   #>     pointer: function () 
   #>     print: function (...) 
   #>     schema: Schema, ArrowObject, R6
   #>     set_pointer: function (xp) 
   #>     ToString: function () 
   #>     type: function (schema = self$schema) 
   #>     type_id: function (schema = self$schema)  
   #>   ..$ options:List of 2
   #>   .. ..$ skip_nulls: logi FALSE
   #>   .. ..$ min_count : int 0
   ```
   
   <sup>Created on 2021-11-08 by the [reprex 
package](https://reprex.tidyverse.org) (v2.0.1)</sup>
   
   </details>




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


Reply via email to