nealrichardson commented on code in PR #19706:
URL: https://github.com/apache/arrow/pull/19706#discussion_r1072593608


##########
r/R/expression.R:
##########
@@ -89,6 +92,56 @@ Expression$create <- function(function_name,
   expr
 }
 
+
+#' @export
+`[[.Expression` <- function(x, i, ...) {
+  # TODO: integer (positional) field refs are supported in C++
+  assert_that(is.string(i))
+  get_nested_field(x, i)
+}
+
+#' @export
+`$.Expression` <- function(x, name, ...) {
+  assert_that(is.string(name))
+  if (name %in% ls(x)) {
+    get(name, x)
+  } else {
+    get_nested_field(x, name)
+  }
+}
+
+get_nested_field <- function(expr, name) {
+  if (expr$is_field_ref()) {
+    # Make a nested field ref
+    out <- compute___expr__nested_field_ref(expr, name)
+  } else {
+    # Use the struct_field kernel, but that only works if:
+    # * expr has a knowable type (has a schema set)
+    # * that type is struct
+    # * `name` exists in the struct (bc we have to map to an integer position)

Review Comment:
   Good to know, I can update to use that. Seems that 
https://arrow.apache.org/docs/dev/cpp/compute.html#cpp-compute-vector-structural-transforms
 is outdated and should be updated to reflect that.



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

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

Reply via email to