-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-6439: [R] Implement S3 file-system interface in R #6901
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
Changes from all commits
dd7e72e
8667d12
cce3bc5
124b502
5e899f5
5c04d42
3a40da4
c794511
9e5282d
3f49da9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -166,6 +166,18 @@ FileSelector$create <- function(base_dir, allow_not_found = FALSE, recursive = F | |
| #' @export | ||
| FileSystem <- R6Class("FileSystem", inherit = ArrowObject, | ||
| public = list( | ||
| ..dispatch = function() { | ||
| type_name <- self$type_name | ||
| if (type_name == "local") { | ||
| shared_ptr(LocalFileSystem, self$pointer()) | ||
| } else if (type_name == "s3") { | ||
| shared_ptr(S3FileSystem, self$pointer()) | ||
| } else if (type_name == "subtree") { | ||
| shared_ptr(SubTreeFileSystem, self$pointer()) | ||
| } else { | ||
| self | ||
| } | ||
| }, | ||
| GetFileInfo = function(x) { | ||
| if (inherits(x, "FileSelector")) { | ||
| map( | ||
|
|
@@ -224,8 +236,16 @@ FileSystem <- R6Class("FileSystem", inherit = ArrowObject, | |
| OpenAppendStream = function(path) { | ||
| shared_ptr(OutputStream, fs___FileSystem__OpenAppendStream(self, clean_path_rel(path))) | ||
| } | ||
| ), | ||
| active = list( | ||
| type_name = function() fs___FileSystem__type_name(self) | ||
| ) | ||
| ) | ||
| FileSystem$from_uri <- function(uri) { | ||
| out <- fs___FileSystemFromUri(uri) | ||
| out$fs <- shared_ptr(FileSystem, out$fs)$..dispatch() | ||
| out | ||
| } | ||
|
|
||
| #' @usage NULL | ||
| #' @format NULL | ||
|
|
@@ -236,6 +256,19 @@ LocalFileSystem$create <- function() { | |
| shared_ptr(LocalFileSystem, fs___LocalFileSystem__create()) | ||
| } | ||
|
|
||
| #' @usage NULL | ||
| #' @format NULL | ||
| #' @rdname FileSystem | ||
| #' @export | ||
| S3FileSystem <- R6Class("S3FileSystem", inherit = FileSystem) | ||
| S3FileSystem$create <- function() { | ||
| fs___EnsureS3Initialized() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should you just hide this in
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could, sure. Wasn't sure how many functions I would need to write and whether they'd all need it. |
||
| shared_ptr(S3FileSystem, fs___S3FileSystem__create()) | ||
| } | ||
|
|
||
| arrow_with_s3 <- function() { | ||
| .Call(`_s3_available`) | ||
| } | ||
|
|
||
| #' @usage NULL | ||
| #' @format NULL | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,16 +48,19 @@ if (packageVersion("decor") < '0.0.0.9001') { | |
| stop("more recent version of `decor` needed, please install with `remotes::install_github('romainfrancois/decor')`") | ||
| } | ||
|
|
||
| decorations <- cpp_decorations() %>% | ||
| filter(decoration == "arrow::export") %>% | ||
| # the three lines below can be expressed with rap() | ||
| # more concisely | ||
| # rap( ~ decor:::parse_cpp_function(context)) | ||
| mutate(functions = map(context, decor:::parse_cpp_function)) %>% | ||
| { vec_cbind(., vec_rbind(!!!pull(., functions))) } %>% | ||
| select(-functions) | ||
|
|
||
| message(glue("*** > {n} functions decorated with [[arrow::export]]", n = nrow(decorations))) | ||
| get_exported_functions <- function(decorations, export_tag) { | ||
| out <- decorations %>% | ||
| filter(decoration %in% paste0(export_tag, "::export")) %>% | ||
| # the three lines below can be expressed with rap() | ||
| # more concisely | ||
| # rap( ~ decor:::parse_cpp_function(context)) | ||
| mutate(functions = map(context, decor:::parse_cpp_function)) %>% | ||
| { vec_cbind(., vec_rbind(!!!pull(., functions))) } %>% | ||
| select(-functions) %>% | ||
| mutate(decoration = sub("::export", "", decoration)) | ||
| message(glue("*** > {n} functions decorated with [[{tags}::export]]", n = nrow(out), tags = paste0(export_tag, collapse = "|"))) | ||
| out | ||
| } | ||
|
|
||
| glue_collapse_data <- function(data, ..., sep = ", ", last = "") { | ||
| res <- glue_collapse(glue_data(data, ...), sep = sep, last = last) | ||
|
|
@@ -73,12 +76,16 @@ wrap_call <- function(name, return_type, args) { | |
| glue::glue("\treturn Rcpp::wrap({call});") | ||
| } | ||
| } | ||
| cpp_functions_definitions <- decorations %>% | ||
| select(name, return_type, args, file, line) %>% | ||
| pmap_chr(function(name, return_type, args, file, line){ | ||
|
|
||
| all_decorations <- cpp_decorations() | ||
| arrow_exports <- get_exported_functions(all_decorations, c("arrow", "s3")) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WIll you want to do this for other component, e.g. json, csv, parquet, dataset...
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this change we could if we wanted to enable building slimmer versions of the package, but I'm not planning on doing that unless there's a compelling reason to. |
||
|
|
||
| cpp_functions_definitions <- arrow_exports %>% | ||
| select(name, return_type, args, file, line, decoration) %>% | ||
| pmap_chr(function(name, return_type, args, file, line, decoration){ | ||
| glue::glue(' | ||
| // {basename(file)} | ||
| #if defined(ARROW_R_WITH_ARROW) | ||
| #if defined(ARROW_R_WITH_{toupper(decoration)}) | ||
| {return_type} {name}({real_params}); | ||
| RcppExport SEXP _arrow_{name}({sexp_params}){{ | ||
| BEGIN_RCPP | ||
|
|
@@ -101,7 +108,7 @@ cpp_functions_definitions <- decorations %>% | |
| }) %>% | ||
| glue_collapse(sep = "\n") | ||
|
|
||
| cpp_functions_registration <- decorations %>% | ||
| cpp_functions_registration <- arrow_exports %>% | ||
| select(name, return_type, args) %>% | ||
| pmap_chr(function(name, return_type, args){ | ||
| glue('\t\t{{ "_arrow_{name}", (DL_FUNC) &_arrow_{name}, {nrow(args)}}}, ') | ||
|
|
@@ -127,8 +134,19 @@ return Rf_ScalarLogical( | |
| ); | ||
| }} | ||
|
|
||
| extern "C" SEXP _s3_available() {{ | ||
| return Rf_ScalarLogical( | ||
| #if defined(ARROW_R_WITH_S3) | ||
| TRUE | ||
| #else | ||
| FALSE | ||
| #endif | ||
| ); | ||
| }} | ||
|
|
||
| static const R_CallMethodDef CallEntries[] = {{ | ||
| \t\t{{ "_arrow_available", (DL_FUNC)& _arrow_available, 0 }}, | ||
| \t\t{{ "_s3_available", (DL_FUNC)& _s3_available, 0 }}, | ||
| {cpp_functions_registration} | ||
| \t\t{{NULL, NULL, 0}} | ||
| }}; | ||
|
|
@@ -142,7 +160,7 @@ RcppExport void R_init_arrow(DllInfo* dll){{ | |
|
|
||
| message("*** > generated file `src/arrowExports.cpp`") | ||
|
|
||
| r_functions <- decorations %>% | ||
| r_functions <- arrow_exports %>% | ||
| select(name, return_type, args) %>% | ||
| pmap_chr(function(name, return_type, args) { | ||
| params <- if (nrow(args)) { | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.