-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Labels
Description
Is there any interest in adding a dplyr-like function that implements CROSS JOIN UNNEST
? I use the below frequently and am curious if it could be useful in RPresto.
cross_join_unnest <- function(x, ..., values_to = "value") {
conn <- x$src$con
qry <- dbplyr::build_sql(
"SELECT a.*, ",
dbplyr::ident(values_to),
" FROM (",
dbplyr::sql_render(x),
") a ",
"\nCROSS JOIN UNNEST (",
dbplyr::ident(rlang::as_name(...)),
") AS t(",
dbplyr::ident(values_to),
")",
con = conn
)
dplyr::tbl(conn, dbplyr::sql(qry))
}
This allows a workflow like
conn <- dbConnect(RPresto::Presto(), ...)
my_tbl <- dplyr::tbl(conn, "my_tbl")
my_tbl |>
cross_join_unnest("my_array_col") |>
select(-my_array_col) |>
collect()
If yes, I'd be happy to create a PR.
baslat