-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Forward compatibility with dplyr 2.5.0 #338
Conversation
Hmmmm, maybe I misinterpreted what's going on here because it looks like you are suppling a custom translation via So the problem is likely due to tidyverse/dbplyr#1430 — because dbplyr translates all the arguments to a function before passing it to the function. But in this case, you want the arguments to the function to be regular R objects because your function is going to do the translation. Hmmmmmmmmmmmmmmm. |
Yeah, so a better fix for (e.g.) bcdc_query_geodata("bc-airports") %>%
filter(WITHIN(local(local))) %>%
collect() And unfortunately So the problem here is not declaring additional translations but declaring that But I think this means I'm being too aggressive at erroring on unknown types in |
Partially reverts #1368. See bcgov/bcdata#338 for details. If we do this again in the future, I think we have to do argument checking in individual translations. That's a lot of work but allows a whole suite of potentially useful translations for more complex R objects.
Thanks @hadley for taking a look at this. Yeah, those uppercase predicates ( We have precedent for asking users to use It is a shame that Your idea of being able to register a function as expecting a local object would be really nice. Putting this here mostly for my edification: library(bcdata)
library(sf)
x <- bcdc_query_geodata('d1aff64e-dbfe-45a6-af97-582b7f6418b9') |>
filter(ADMIN_AREA_NAME == "Cariboo Regional District") |>
collect()
airports <- '76b1b7a3-2112-4444-857a-afccf7b20da8'
# original behaviour, no longer works with dev dbplyr 2.5.0
res <- bcdc_query_geodata(airports) |>
filter(WITHIN(x)) |>
collect()
#> Error:
#> ! Cannot translate a data.frame to SQL.
#> ℹ Do you want to force evaluation in R with (e.g.) `!!x$x` or `local(x$x)`?
# works with dev dbplyr 2.5.0
res <- bcdc_query_geodata(airports) |>
filter(!!WITHIN(x)) |>
collect()
# works with dev dbplyr 2.5.0
res <- bcdc_query_geodata(airports) |>
filter(local(WITHIN(x))) |>
collect()
# works with dev dbplyr 2.5.0
res <- bcdc_query_geodata(airports) |>
filter(WITHIN(local(x))) |>
collect()
# does not work with dev dbplyr 2.5.0
res <- bcdc_query_geodata(airports) |>
filter(WITHIN(!!x)) |>
collect()
#> Error in `FUN()`:
#> ! Unknown input type: list
# !! does work with an atomic vector:
x_bbox <- st_bbox(x)
res <- bcdc_query_geodata(airports) |>
filter(WITHIN(!!x_bbox)) |>
collect() Created on 2024-02-22 with reprex v2.1.0 |
Just looking at the testthat failures here, there is something funny going on with how messages are emitted when using library(bcdata)
library(testthat)
x <- bcdc_query_geodata('d1aff64e-dbfe-45a6-af97-582b7f6418b9') %>%
filter(ADMIN_AREA_NAME == "Cariboo Regional District") %>%
collect()
airports <- '76b1b7a3-2112-4444-857a-afccf7b20da8'
# fine
expect_message(
bcdc_query_geodata(airports) %>%
filter(WITHIN(local(x))) %>%
collect()
)
# says no message produced
expect_message(
bcdc_query_geodata(airports) %>%
filter(!!WITHIN(x)) %>%
collect()
)
#> The object is too large to perform exact spatial operations using bcdata.
#> Object size: 697696 bytes
#> BC Data Threshold: 500000 bytes
#> Exceedance: 197696 bytes
#> See ?bcdc_check_geom_size for more details
#> A bounding box was drawn around the object passed to WITHIN and all features within the box will be returned.
#> Error: ``%>%`(...)` did not produce any messages. Created on 2024-02-22 with reprex v2.1.0 |
FWIW I'm going to back this change out of dbplyr so that bcdata doesn't break. (But mostly because it is a large, unanticipated, change to the semantics of dbplyr function translation) |
Closing this in favour of tidyverse/dbplyr#1466 Thanks for the feedback! |
Thanks @hadley! |
Revert to previous escaping method (i.e. reverts #1368). See bcgov/bcdata#338 for details. If we do this again in the future, I think we have to do argument checking in individual translations. That's a lot of work but allows a whole suite of potentially useful translations for more complex R objects.
This seems like a pretty uncompelling set of changes and I feel like it's likely to substantially negatively impact the usability of your package. Do you agree? If so, I'll see what I can change in dbplyr to make 2.5.0 more appealing.