You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "thisisnic (via GitHub)" <gi...@apache.org> on 2026/09/10 17:25:26 UTC

[PR] GH-39688: [R] "Error: Filter expression not supported for Arrow Datasets" using "date" expression rigth hand side of a filter [arrow]

thisisnic opened a new pull request, #51291:
URL: https://github.com/apache/arrow/pull/51291

   ### Rationale for this change
   
   Error when user tries to use local variable in dplyr pipeline in Arrow
   
   ### What changes are included in this PR?
   
   Make sure we attach them to the mask
   
   ### Are these changes tested?
   
   Yup
   
   ### Are there any user-facing changes?
   
   Yep


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

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


Re: [PR] GH-39688: [R] "Error: Filter expression not supported for Arrow Datasets" using "date" expression rigth hand side of a filter [arrow]

Posted by "thisisnic (via GitHub)" <gi...@apache.org>.
thisisnic commented on code in PR #51291:
URL: https://github.com/apache/arrow/pull/51291#discussion_r4041488849


##########
r/R/dplyr-eval.R:
##########
@@ -128,6 +132,30 @@ add_user_functions_to_mask <- function(expr, mask) {
   invisible()
 }
 
+add_user_variables_to_mask <- function(expr, mask) {
+  # The function bindings environment sits between the columns and the user's
+  # environment in the mask, so a symbol like `date` in `filter(Date == date)`
+  # would resolve to the `date()` binding rather than the user's variable.
+  # dplyr would find the variable, so bind it into the mask so we do too.
+  if (is_quosure(expr)) {
+    function_env <- parent.env(parent.env(mask))
+    quo_env <- quo_get_env(expr)
+    # all.vars() returns symbols that aren't in function position
+    vars_in_expr <- all.vars(quo_get_expr(expr))
+    columns <- names(mask$.data)
+    shadowed <- setdiff(intersect(vars_in_expr, ls(function_env, all.names = TRUE)), columns)
+    for (var_name in shadowed) {
+      user_var <- get0(var_name, quo_env)
+      # Functions from the user's environment (like lubridate::day) shouldn't
+      # take precedence over the bindings
+      if (!is.null(user_var) && !is.function(user_var)) {

Review Comment:
   You're wrong Copilot



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

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


Re: [PR] GH-39688: [R] "Error: Filter expression not supported for Arrow Datasets" using "date" expression rigth hand side of a filter [arrow]

Posted by "thisisnic (via GitHub)" <gi...@apache.org>.
thisisnic commented on code in PR #51291:
URL: https://github.com/apache/arrow/pull/51291#discussion_r4041464009


##########
r/tests/testthat/test-dplyr-filter.R:
##########
@@ -547,3 +547,15 @@ test_that("More complex select/filter_out", {
     tbl
   )
 })
+
+test_that("filter() with a variable that shares a name with a function binding", {
+  # GH-39688: `date` and `day` are also function bindings

Review Comment:
   So anything which didn't have a collision worked fine before, it was only the collision ones which had the problem



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

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


Re: [PR] GH-39688: [R] "Error: Filter expression not supported for Arrow Datasets" using "date" expression rigth hand side of a filter [arrow]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #51291:
URL: https://github.com/apache/arrow/pull/51291#discussion_r3981796424


##########
r/R/dplyr-eval.R:
##########
@@ -128,6 +132,30 @@ add_user_functions_to_mask <- function(expr, mask) {
   invisible()
 }
 
+add_user_variables_to_mask <- function(expr, mask) {
+  # The function bindings environment sits between the columns and the user's
+  # environment in the mask, so a symbol like `date` in `filter(Date == date)`
+  # would resolve to the `date()` binding rather than the user's variable.
+  # dplyr would find the variable, so bind it into the mask so we do too.
+  if (is_quosure(expr)) {
+    function_env <- parent.env(parent.env(mask))
+    quo_env <- quo_get_env(expr)
+    # all.vars() returns symbols that aren't in function position
+    vars_in_expr <- all.vars(quo_get_expr(expr))
+    columns <- names(mask$.data)
+    shadowed <- setdiff(intersect(vars_in_expr, ls(function_env, all.names = TRUE)), columns)
+    for (var_name in shadowed) {
+      user_var <- get0(var_name, quo_env)
+      # Functions from the user's environment (like lubridate::day) shouldn't
+      # take precedence over the bindings
+      if (!is.null(user_var) && !is.function(user_var)) {

Review Comment:
   `get0(var_name, quo_env)` defaults to `inherits = FALSE`, so variables defined in parent environments of the quosure env (common with lexical scoping inside functions) won’t be found and therefore won’t shadow the function binding. This can still diverge from dplyr’s name resolution in those cases.



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

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


Re: [PR] GH-39688: [R] "Error: Filter expression not supported for Arrow Datasets" using "date" expression rigth hand side of a filter [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #51291:
URL: https://github.com/apache/arrow/pull/51291#issuecomment-5622726450

   :warning: GitHub issue #39688 **has been automatically assigned in GitHub** to PR creator.


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

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


Re: [PR] GH-39688: [R] "Error: Filter expression not supported for Arrow Datasets" using "date" expression rigth hand side of a filter [arrow]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #51291:
URL: https://github.com/apache/arrow/pull/51291#discussion_r4041578814


##########
r/R/dplyr-eval.R:
##########
@@ -128,6 +132,30 @@ add_user_functions_to_mask <- function(expr, mask) {
   invisible()
 }
 
+add_user_variables_to_mask <- function(expr, mask) {
+  # The function bindings environment sits between the columns and the user's
+  # environment in the mask, so a symbol like `date` in `filter(Date == date)`
+  # would resolve to the `date()` binding rather than the user's variable.
+  # dplyr would find the variable, so we bind it into the mask to match.
+  if (is_quosure(expr)) {
+    function_env <- parent.env(parent.env(mask))
+    quo_env <- quo_get_env(expr)
+    # all.vars() returns symbols that aren't in function position
+    vars_in_expr <- all.vars(quo_get_expr(expr))
+    columns <- names(mask$.data)
+    shadowed <- setdiff(intersect(vars_in_expr, ls(function_env, all.names = TRUE)), columns)

Review Comment:
   `shadowed` is computed by calling `ls(function_env, ...)` and intersecting, which scans the entire bindings environment for every evaluated expression. Since `vars_in_expr` is typically small, checking `exists()` per symbol avoids repeatedly enumerating all bindings and should reduce overhead in dplyr-heavy workloads.



##########
r/tests/testthat/test-dplyr-filter.R:
##########
@@ -564,3 +564,25 @@ test_that("filter() and filter_out() with across() warn about deprecation", {
     class = "lifecycle_warning_deprecated"
   )
 })
+
+test_that("filter() with a variable from the calling environment", {
+  my_constant <- "d"
+  compare_dplyr_binding(
+    .input |>
+      filter(chr == my_constant) |>

Review Comment:
   These new regression tests exercise the Table path via `compare_dplyr_binding()`, but GH-39688 reproduces on `open_dataset()` (Dataset filter planning) with a calling-env variable named like a function binding (e.g. `date`). Since the repo already has Dataset dplyr tests (e.g. `test-dataset-dplyr.R`), adding a Dataset-specific assertion for this scenario would better prevent regressions in the path users hit.



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

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


Re: [PR] GH-39688: [R] "Error: Filter expression not supported for Arrow Datasets" using "date" expression rigth hand side of a filter [arrow]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #51291:
URL: https://github.com/apache/arrow/pull/51291#discussion_r4067124095


##########
r/R/dplyr-eval.R:
##########
@@ -23,6 +23,10 @@ arrow_eval <- function(expr, mask) {
   # but it wouldn't have worked anyway!)
   # Note this is *not* true UDFs.
   add_user_functions_to_mask(expr, mask)
+  # Likewise, look for R variables referenced in expr that share a name with a
+  # function binding (like `date` or `day`) and add them to the mask, so that
+  # the user's variable is found rather than the binding, as dplyr would do.
+  add_user_variables_to_mask(expr, mask)

Review Comment:
   The new name-shadowing behavior is meant to fix a Dataset-only failure mode (Dataset can't fall back to in-memory dplyr evaluation), but the added regression tests only exercise the Table path via compare_dplyr_binding(). Consider adding a Dataset regression test (e.g., in test-dataset-dplyr.R) that reproduces GH-39688: open_dataset() |> filter(date_col == date) where `date` is a calling-environment variable that collides with a function binding.



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

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


Re: [PR] GH-39688: [R] "Error: Filter expression not supported for Arrow Datasets" using "date" expression rigth hand side of a filter [arrow]

Posted by "jonkeane (via GitHub)" <gi...@apache.org>.
jonkeane commented on code in PR #51291:
URL: https://github.com/apache/arrow/pull/51291#discussion_r4031389906


##########
r/tests/testthat/test-dplyr-filter.R:
##########
@@ -547,3 +547,15 @@ test_that("More complex select/filter_out", {
     tbl
   )
 })
+
+test_that("filter() with a variable that shares a name with a function binding", {
+  # GH-39688: `date` and `day` are also function bindings

Review Comment:
   This is a nice test and I want to keep it, but should we also have one that is more basic and shows off that `date` and `day` are edgecases here demonstrating the functionality of something like this:
   
   ```
   my_constant <- "three:
   compare_dplyr_binding(
       .input |>
         filter(chr == my_constant) |>
         collect(),
       tbl
     )
   ```
   
   Because ^^^ _also_ didn't work before, yeah? Or did it actually work we just didn't do the masking in the right order to let it work like dplyr does?



##########
r/R/dplyr-eval.R:
##########
@@ -128,6 +132,30 @@ add_user_functions_to_mask <- function(expr, mask) {
   invisible()
 }
 
+add_user_variables_to_mask <- function(expr, mask) {
+  # The function bindings environment sits between the columns and the user's
+  # environment in the mask, so a symbol like `date` in `filter(Date == date)`
+  # would resolve to the `date()` binding rather than the user's variable.
+  # dplyr would find the variable, so bind it into the mask so we do too.

Review Comment:
   the so ... so ... is a little awkward here



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

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


Re: [PR] GH-39688: [R] "Error: Filter expression not supported for Arrow Datasets" using "date" expression rigth hand side of a filter [arrow]

Posted by "thisisnic (via GitHub)" <gi...@apache.org>.
thisisnic merged PR #51291:
URL: https://github.com/apache/arrow/pull/51291


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

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