View source: R/presto_unnest.R
| presto_unnest | R Documentation |
Expands array columns into rows using Presto's CROSS JOIN UNNEST syntax.
This is similar to tidyr::unnest() but works with Presto database tables.
presto_unnest(
data,
cols,
...,
values_to = NULL,
with_ordinality = FALSE,
ordinality_to = NULL
)
## S3 method for class 'tbl_presto'
presto_unnest(
data,
cols,
...,
values_to = NULL,
with_ordinality = FALSE,
ordinality_to = NULL
)
data |
A |
cols |
Column(s) to unnest. Currently only supports a single column. |
... |
Additional arguments (currently unused) |
values_to |
Name of column to store unnested values. If |
with_ordinality |
If |
ordinality_to |
Name of ordinality column when |
A tbl_presto object with the array column unnested into rows.
## Not run:
# Connect to Presto
con <- DBI::dbConnect(RPresto::Presto(), ...)
# Create a table with an array column
DBI::dbExecute(con, "CREATE TABLE test (id BIGINT, arr ARRAY(BIGINT))")
DBI::dbExecute(con, "INSERT INTO test VALUES (1, ARRAY[10, 20, 30])")
# Unnest the array column
tbl(con, "test") %>%
presto_unnest(arr) %>%
collect()
# Without values_to, the unnested column is named "arr_elem"
# Or specify a custom name
tbl(con, "test") %>%
presto_unnest(arr, values_to = "elem") %>%
collect()
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.