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


##########
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:
   Ah, yes, that documentation is indeed outdated (wasn't aware it's described 
in such detail there, so we didn't update that when updating the kernel in 
https://github.com/apache/arrow/pull/14495)



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