dragosmg commented on code in PR #13541:
URL: https://github.com/apache/arrow/pull/13541#discussion_r919949383


##########
r/R/dplyr.R:
##########
@@ -219,6 +219,31 @@ tail.arrow_dplyr_query <- function(x, n = 6L, ...) {
   x
 }
 
+#' Show the details of an Arrow Execution Plan
+#'
+#' This is a function which gives more details about the Execution Plan 
(`ExecPlan`)
+#' of an `arrow_dplyr_query` object. It is similar to `dplyr::explain()`.
+#'
+#' @param x an `arrow_dplyr_query` to print the `ExecPlan` for.
+#'
+#' @return The argument, invisibly.
+#' @export
+#'
+#' @examplesIf arrow_with_dataset() & requireNamespace("dplyr", quietly = TRUE)
+#' library(dplyr)
+#' mtcars %>%
+#'   arrow_table() %>%
+#'   filter(mpg > 20) %>%
+#'   mutate(x = gear/carb) %>%
+#'   show_exec_plan()
+show_exec_plan <- function(x) {
+  adq <- as_adq(x)
+  plan <- ExecPlan$create()
+  final_node <- plan$Build(x)
+  cat(plan$ToString())

Review Comment:
   You are right, if the pipeline includes calls to `arrange()` and / or 
`head()` they are not captured by `show_exec_plan()`.  Moreover, the filter 
node gets lost when we use `head()`.
   
   ``` r
     mtcars %>% 
       arrow_table() %>% 
       filter(mpg > 20) %>% 
       arrange(desc(wt)) %>% 
       head(3) %>% 
       show_exec_plan()
   #> ExecPlan with 2 nodes:
   #> 1:ProjectNode{projection=[mpg, cyl, disp, hp, drat, wt, qsec, vs, am, 
gear, carb]}
   #>  0:SourceNode{}
   
   mtcars %>% 
       arrow_table() %>% 
       filter(mpg > 20) %>% 
       arrange(desc(wt)) %>%
       show_exec_plan()
   #> ExecPlan with 3 nodes:
   #> 2:ProjectNode{projection=[mpg, cyl, disp, hp, drat, wt, qsec, vs, am, 
gear, carb]}
   #>   1:FilterNode{filter=(mpg > 20)}
   #>     0:TableSourceNode{}
   ```
   
   <sup>Created on 2022-07-13 by the [reprex 
package](https://reprex.tidyverse.org) (v2.0.1)</sup>
   
   Let me do some research / reading and will get back on this. It might be 
beyond my C++ skillset.



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