diff --git a/r/DESCRIPTION b/r/DESCRIPTION index 7b68377d41f..71a891d3ea7 100644 --- a/r/DESCRIPTION +++ b/r/DESCRIPTION @@ -63,6 +63,7 @@ Collate: 'dictionary.R' 'feather.R' 'field.R' + 'filesystem.R' 'install-arrow.R' 'json.R' 'list.R' diff --git a/r/NAMESPACE b/r/NAMESPACE index 1060bddf8ea..9f210667f9e 100644 --- a/r/NAMESPACE +++ b/r/NAMESPACE @@ -52,7 +52,11 @@ export(FeatherTableWriter) export(Field) export(FileMode) export(FileOutputStream) +export(FileStats) +export(FileSystem) +export(FileType) export(FixedSizeBufferWriter) +export(LocalFileSystem) export(MemoryMappedFile) export(MessageReader) export(MessageType) @@ -66,7 +70,9 @@ export(RecordBatchFileWriter) export(RecordBatchStreamReader) export(RecordBatchStreamWriter) export(Schema) +export(Selector) export(StatusCode) +export(SubTreeFileSystem) export(Table) export(TimeUnit) export(Type) diff --git a/r/R/arrowExports.R b/r/R/arrowExports.R index d98a6b06c07..939f7aca30a 100644 --- a/r/R/arrowExports.R +++ b/r/R/arrowExports.R @@ -540,6 +540,122 @@ Field__type <- function(field){ .Call(`_arrow_Field__type` , field) } +fs___FileStats__type <- function(x){ + .Call(`_arrow_fs___FileStats__type` , x) +} + +fs___FileStats__set_type <- function(x, type){ + invisible(.Call(`_arrow_fs___FileStats__set_type` , x, type)) +} + +fs___FileStats__path <- function(x){ + .Call(`_arrow_fs___FileStats__path` , x) +} + +fs___FileStats__set_path <- function(x, path){ + invisible(.Call(`_arrow_fs___FileStats__set_path` , x, path)) +} + +fs___FileStats__size <- function(x){ + .Call(`_arrow_fs___FileStats__size` , x) +} + +fs___FileStats__set_size <- function(x, size){ + invisible(.Call(`_arrow_fs___FileStats__set_size` , x, size)) +} + +fs___FileStats__base_name <- function(x){ + .Call(`_arrow_fs___FileStats__base_name` , x) +} + +fs___FileStats__extension <- function(x){ + .Call(`_arrow_fs___FileStats__extension` , x) +} + +fs___FileStats__mtime <- function(x){ + .Call(`_arrow_fs___FileStats__mtime` , x) +} + +fs___FileStats__set_mtime <- function(x, time){ + invisible(.Call(`_arrow_fs___FileStats__set_mtime` , x, time)) +} + +fs___Selector__base_dir <- function(selector){ + .Call(`_arrow_fs___Selector__base_dir` , selector) +} + +fs___Selector__allow_non_existent <- function(selector){ + .Call(`_arrow_fs___Selector__allow_non_existent` , selector) +} + +fs___Selector__recursive <- function(selector){ + .Call(`_arrow_fs___Selector__recursive` , selector) +} + +fs___Selector__create <- function(base_dir, allow_non_existent, recursive){ + .Call(`_arrow_fs___Selector__create` , base_dir, allow_non_existent, recursive) +} + +fs___FileSystem__GetTargetStats_Paths <- function(file_system, paths){ + .Call(`_arrow_fs___FileSystem__GetTargetStats_Paths` , file_system, paths) +} + +fs___FileSystem__GetTargetStats_Selector <- function(file_system, selector){ + .Call(`_arrow_fs___FileSystem__GetTargetStats_Selector` , file_system, selector) +} + +fs___FileSystem__CreateDir <- function(file_system, path, recursive){ + invisible(.Call(`_arrow_fs___FileSystem__CreateDir` , file_system, path, recursive)) +} + +fs___FileSystem__DeleteDir <- function(file_system, path){ + invisible(.Call(`_arrow_fs___FileSystem__DeleteDir` , file_system, path)) +} + +fs___FileSystem__DeleteDirContents <- function(file_system, path){ + invisible(.Call(`_arrow_fs___FileSystem__DeleteDirContents` , file_system, path)) +} + +fs___FileSystem__DeleteFile <- function(file_system, path){ + invisible(.Call(`_arrow_fs___FileSystem__DeleteFile` , file_system, path)) +} + +fs___FileSystem__DeleteFiles <- function(file_system, paths){ + invisible(.Call(`_arrow_fs___FileSystem__DeleteFiles` , file_system, paths)) +} + +fs___FileSystem__Move <- function(file_system, src, dest){ + invisible(.Call(`_arrow_fs___FileSystem__Move` , file_system, src, dest)) +} + +fs___FileSystem__CopyFile <- function(file_system, src, dest){ + invisible(.Call(`_arrow_fs___FileSystem__CopyFile` , file_system, src, dest)) +} + +fs___FileSystem__OpenInputStream <- function(file_system, path){ + .Call(`_arrow_fs___FileSystem__OpenInputStream` , file_system, path) +} + +fs___FileSystem__OpenInputFile <- function(file_system, path){ + .Call(`_arrow_fs___FileSystem__OpenInputFile` , file_system, path) +} + +fs___FileSystem__OpenOutputStream <- function(file_system, path){ + .Call(`_arrow_fs___FileSystem__OpenOutputStream` , file_system, path) +} + +fs___FileSystem__OpenAppendStream <- function(file_system, path){ + .Call(`_arrow_fs___FileSystem__OpenAppendStream` , file_system, path) +} + +fs___LocalFileSystem__create <- function(){ + .Call(`_arrow_fs___LocalFileSystem__create` ) +} + +fs___SubTreeFileSystem__create <- function(base_path, base_fs){ + .Call(`_arrow_fs___SubTreeFileSystem__create` , base_path, base_fs) +} + io___Readable__Read <- function(x, nbytes){ .Call(`_arrow_io___Readable__Read` , x, nbytes) } diff --git a/r/R/enums.R b/r/R/enums.R index 5a5cdfa3d25..ade6d8e94f3 100644 --- a/r/R/enums.R +++ b/r/R/enums.R @@ -78,3 +78,9 @@ MessageType <- enum("Message::Type", CompressionType <- enum("Compression::type", UNCOMPRESSED = 0L, SNAPPY = 1L, GZIP = 2L, BROTLI = 3L, ZSTD = 4L, LZ4 = 5L, LZO = 6L, BZ2 = 7L ) + +#' @export +#' @rdname enums +FileType <- enum("FileType", + NonExistent = 0L, Unknown = 1L, File = 2L, Directory = 3L +) diff --git a/r/R/filesystem.R b/r/R/filesystem.R new file mode 100644 index 00000000000..d20edcc6c02 --- /dev/null +++ b/r/R/filesystem.R @@ -0,0 +1,237 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +#' @include arrow-package.R +#' @title FileSystem entry stats +#' @usage NULL +#' @format NULL +#' +#' @section Methods: +#' +#' - `base_name()` : The file base name (component after the last directory +#' separator). +#' - `extension()` : The file extension +#' +#' @section Active bindings: +#' +#' - `$type`: The file type +#' - `$path`: The full file path in the filesystem +#' - `$size`: The size in bytes, if available. Only regular files are +#' guaranteed to have a size. +#' - `$mtime`: The time of last modification, if available. +#' +#' @rdname FileStats +#' @export +FileStats <- R6Class("FileStats", + inherit = Object, + public = list( + base_name = function() fs___FileStats__base_name(self), + extension = function() fs___FileStats__extension(self) + ), + active = list( + type = function(type) { + if (missing(type)) { + fs___FileStats__type(self) + } else { + fs___FileStats__set_type(self, type) + } + }, + path = function(path) { + if (missing(path)) { + fs___FileStats__path(self) + } else { + invisible(fs___FileStats__set_path(self)) + } + }, + + size = function(size) { + if (missing(size)) { + fs___FileStats__size(self) + } else { + invisible(fs___FileStats__set_size(self, size)) + } + }, + + mtime = function(time) { + if (missing(time)) { + fs___FileStats__mtime(self) + } else { + if (!inherits(time, "POSIXct") && length(time) == 1L) { + abort("invalid time") + } + invisible(fs___FileStats__set_mtime(self, time)) + } + } + ) +) + +#' @title file selector +#' @format NULL +#' +#' @section Factory: +#' +#' The `$create()` factory method instantiates a `Selector` given the 3 fields +#' described below. +#' +#' @section Fields: +#' +#' - `base_dir`: The directory in which to select files. If the path exists but +#' doesn't point to a directory, this should be an error. +#' - `allow_non_existent`: The behavior if `base_dir` doesn't exist in the +#' filesystem. If `FALSE`, an error is returned. If `TRUE`, an empty +#' selection is returned +#' - `recursive`: Whether to recurse into subdirectories. +#' +#' @rdname Selector +#' @export +Selector <- R6Class("Selector", + inherit = Object, + active = list( + base_dir = function() fs___Selector__base_dir(self), + allow_non_existent = function() fs___Selector__allow_non_existent(self), + recursive = function() fs___Selector__recursive(self) + ) +) + +Selector$create <- function(base_dir, allow_non_existent = FALSE, recursive = FALSE) { + shared_ptr(Selector, fs___Selector__create(base_dir, allow_non_existent, recursive)) +} + +#' @title FileSystem classes +#' @description `FileSystem` is an abstract file system API, +#' `LocalFileSystem` is an implementation accessing files +#' on the local machine. `SubTreeFileSystem` is an implementation that delegates +#' to another implementation after prepending a fixed base path +#' +#' @section Factory: +#' +#' The `$create()` factory methods instantiate the `FileSystem` object and +#' take the following arguments, depending on the subclass: +#' +#' - no argument is needed for instantiating a `LocalFileSystem` +#' - `base_path` and `base_fs` for instantiating a `SubTreeFileSystem` +#' +#' @section Methods: +#' +#' - `$GetTargetStats(x)`: `x` may be a [Selector][Selector] or a character +#' vector of paths. Returns a list of [FileStats][FileStats] +#' - `$CreateDir(path, recursive = TRUE)`: Create a directory and subdirectories. +#' - `$DeleteDir(path)`: Delete a directory and its contents, recursively. +#' - `$DeleteDirContents(path)`: Delete a directory's contents, recursively. +#' Like `$DeleteDir()`, +#' but doesn't delete the directory itself. Passing an empty path (`""`) will +#' wipe the entire filesystem tree. +#' - `$DeleteFile(path)` : Delete a file. +#' - `$DeleteFiles(paths)` : Delete many files. The default implementation +#' issues individual delete operations in sequence. +#' - `$Move(src, dest)`: Move / rename a file or directory. If the destination +#' exists: +#' if it is a non-empty directory, an error is returned +#' otherwise, if it has the same type as the source, it is replaced +#' otherwise, behavior is unspecified (implementation-dependent). +#' - `$CopyFile(src, dest)`: Copy a file. If the destination exists and is a +#' directory, an error is returned. Otherwise, it is replaced. +#' - `$OpenInputStream(path)`: Open an [input stream][InputStream] for +#' sequential reading. +#' - `$OpenInputFile(path)`: Open an [input file][RandomAccessFile] for random +#' access reading. +#' - `$OpenOutputStream(path)`: Open an [output stream][OutputStream] for +#' sequential writing. +#' - `$OpenAppendStream(path)`: Open an [output stream][OutputStream] for +#' appending. +#' +#' @usage NULL +#' @format NULL +#' @docType class +#' +#' @rdname FileSystem +#' @name FileSystem +#' @export +FileSystem <- R6Class("FileSystem", inherit = Object, + public = list( + GetTargetStats = function(x) { + if (inherits(x, "Selector")) { + map(fs___FileSystem__GetTargetStats_Selector(self, x), shared_ptr, class = FileStats) + } else if (is.character(x)){ + map(fs___FileSystem__GetTargetStats_Paths(self, x), shared_ptr, class = FileStats) + } else { + abort("incompatible type for FileSystem$GetTargetStarts()") + } + }, + + CreateDir = function(path, recursive = TRUE) { + fs___FileSystem__CreateDir(self, path, isTRUE(recursive)) + }, + + DeleteDir = function(path) { + fs___FileSystem__DeleteDir(self, path) + }, + + DeleteDirContents = function(path) { + fs___FileSystem__DeleteDirContents(self, path) + }, + + DeleteFile = function(path) { + fs___FileSystem__DeleteFile(self, path) + }, + + DeleteFiles = function(paths) { + fs___FileSystem__DeleteFiles(self, paths) + }, + + Move = function(src, dest) { + fs___FileSystem__Move(self, src, dest) + }, + + CopyFile = function(src, dest) { + fs___FileSystem__CopyFile(self, src, dest) + }, + + OpenInputStream = function(path) { + shared_ptr(InputStream, fs___FileSystem__OpenInputStream(self, path)) + }, + OpenInputFile = function(path) { + shared_ptr(InputStream, fs___FileSystem__OpenInputFile(self, path)) + }, + OpenOutputStream = function(path) { + shared_ptr(OutputStream, fs___FileSystem__OpenOutputStream(self, path)) + }, + OpenAppendStream = function(path) { + shared_ptr(OutputStream, fs___FileSystem__OpenAppendStream(self, path)) + } + ) +) + +#' @usage NULL +#' @format NULL +#' @rdname FileSystem +#' @export +LocalFileSystem <- R6Class("LocalFileSystem", inherit = FileSystem) +LocalFileSystem$create <- function() { + shared_ptr(LocalFileSystem, fs___LocalFileSystem__create()) +} + + +#' @usage NULL +#' @format NULL +#' @rdname FileSystem +#' @export +SubTreeFileSystem <- R6Class("SubTreeFileSystem", inherit = FileSystem) +SubTreeFileSystem$create <- function(base_path, base_fs) { + xp <- fs___SubTreeFileSystem__create(base_path, base_fs) + shared_ptr(SubTreeFileSystem, xp) +} diff --git a/r/man/FileStats.Rd b/r/man/FileStats.Rd new file mode 100644 index 00000000000..04bd92fe2a8 --- /dev/null +++ b/r/man/FileStats.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/filesystem.R +\docType{data} +\name{FileStats} +\alias{FileStats} +\title{FileSystem entry stats} +\description{ +FileSystem entry stats +} +\section{Methods}{ + +\itemize{ +\item \code{base_name()} : The file base name (component after the last directory +separator). +\item \code{extension()} : The file extension +} +} + +\section{Active bindings}{ + +\itemize{ +\item \code{$type}: The file type +\item \code{$path}: The full file path in the filesystem +\item \code{$size}: The size in bytes, if available. Only regular files are +guaranteed to have a size. +\item \code{$mtime}: The time of last modification, if available. +} +} + +\keyword{datasets} diff --git a/r/man/FileSystem.Rd b/r/man/FileSystem.Rd new file mode 100644 index 00000000000..89fa4e6ea94 --- /dev/null +++ b/r/man/FileSystem.Rd @@ -0,0 +1,58 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/filesystem.R +\docType{class} +\name{FileSystem} +\alias{FileSystem} +\alias{LocalFileSystem} +\alias{SubTreeFileSystem} +\title{FileSystem classes} +\description{ +\code{FileSystem} is an abstract file system API, +\code{LocalFileSystem} is an implementation accessing files +on the local machine. \code{SubTreeFileSystem} is an implementation that delegates +to another implementation after prepending a fixed base path +} +\section{Factory}{ + + +The \code{$create()} factory methods instantiate the \code{FileSystem} object and +take the following arguments, depending on the subclass: +\itemize{ +\item no argument is needed for instantiating a \code{LocalFileSystem} +\item \code{base_path} and \code{base_fs} for instantiating a \code{SubTreeFileSystem} +} +} + +\section{Methods}{ + +\itemize{ +\item \code{$GetTargetStats(x)}: \code{x} may be a \link{Selector} or a character +vector of paths. Returns a list of \link{FileStats} +\item \code{$CreateDir(path, recursive = TRUE)}: Create a directory and subdirectories. +\item \code{$DeleteDir(path)}: Delete a directory and its contents, recursively. +\item \code{$DeleteDirContents(path)}: Delete a directory's contents, recursively. +Like \code{$DeleteDir()}, +but doesn't delete the directory itself. Passing an empty path (\code{""}) will +wipe the entire filesystem tree. +\item \code{$DeleteFile(path)} : Delete a file. +\item \code{$DeleteFiles(paths)} : Delete many files. The default implementation +issues individual delete operations in sequence. +\item \code{$Move(src, dest)}: Move / rename a file or directory. If the destination +exists: +if it is a non-empty directory, an error is returned +otherwise, if it has the same type as the source, it is replaced +otherwise, behavior is unspecified (implementation-dependent). +\item \code{$CopyFile(src, dest)}: Copy a file. If the destination exists and is a +directory, an error is returned. Otherwise, it is replaced. +\item \code{$OpenInputStream(path)}: Open an \link[=InputStream]{input stream} for +sequential reading. +\item \code{$OpenInputFile(path)}: Open an \link[=RandomAccessFile]{input file} for random +access reading. +\item \code{$OpenOutputStream(path)}: Open an \link[=OutputStream]{output stream} for +sequential writing. +\item \code{$OpenAppendStream(path)}: Open an \link[=OutputStream]{output stream} for +appending. +} +} + +\keyword{datasets} diff --git a/r/man/Selector.Rd b/r/man/Selector.Rd new file mode 100644 index 00000000000..fe270ed0a61 --- /dev/null +++ b/r/man/Selector.Rd @@ -0,0 +1,32 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/filesystem.R +\docType{data} +\name{Selector} +\alias{Selector} +\title{file selector} +\usage{ +Selector +} +\description{ +file selector +} +\section{Factory}{ + + +The \code{$create()} factory method instantiates a \code{Selector} given the 3 fields +described below. +} + +\section{Fields}{ + +\itemize{ +\item \code{base_dir}: The directory in which to select files. If the path exists but +doesn't point to a directory, this should be an error. +\item \code{allow_non_existent}: The behavior if \code{base_dir} doesn't exist in the +filesystem. If \code{FALSE}, an error is returned. If \code{TRUE}, an empty +selection is returned +\item \code{recursive}: Whether to recurse into subdirectories. +} +} + +\keyword{datasets} diff --git a/r/man/enums.Rd b/r/man/enums.Rd index f7f76c3c035..3d841fa0c64 100644 --- a/r/man/enums.Rd +++ b/r/man/enums.Rd @@ -10,6 +10,7 @@ \alias{FileMode} \alias{MessageType} \alias{CompressionType} +\alias{FileType} \title{Arrow enums} \format{An object of class \code{TimeUnit::type} (inherits from \code{arrow-enum}) of length 4.} \usage{ @@ -26,6 +27,8 @@ FileMode MessageType CompressionType + +FileType } \description{ Arrow enums diff --git a/r/src/array_to_vector.cpp b/r/src/array_to_vector.cpp index 7997a1c6442..1925d7e9f04 100644 --- a/r/src/array_to_vector.cpp +++ b/r/src/array_to_vector.cpp @@ -412,7 +412,7 @@ class Converter_Date64 : public Converter { SEXP Allocate(R_xlen_t n) const { Rcpp::NumericVector data(no_init(n)); - data.attr("class") = Rcpp::CharacterVector::create("POSIXct", "POSIXt"); + Rf_classgets(data, arrow::r::data::classes_POSIXct); return data; } @@ -508,7 +508,7 @@ class Converter_Timestamp : public Converter_Time { SEXP Allocate(R_xlen_t n) const { Rcpp::NumericVector data(no_init(n)); - data.attr("class") = Rcpp::CharacterVector::create("POSIXct", "POSIXt"); + Rf_classgets(data, arrow::r::data::classes_POSIXct); return data; } }; diff --git a/r/src/arrowExports.cpp b/r/src/arrowExports.cpp index 0ebac0cc5a1..ded317d5aef 100644 --- a/r/src/arrowExports.cpp +++ b/r/src/arrowExports.cpp @@ -2075,6 +2075,474 @@ RcppExport SEXP _arrow_Field__type(SEXP field_sexp){ } #endif +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +arrow::fs::FileType fs___FileStats__type(const std::shared_ptr& x); +RcppExport SEXP _arrow_fs___FileStats__type(SEXP x_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type x(x_sexp); + return Rcpp::wrap(fs___FileStats__type(x)); +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileStats__type(SEXP x_sexp){ + Rf_error("Cannot call fs___FileStats__type(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +void fs___FileStats__set_type(const std::shared_ptr& x, arrow::fs::FileType type); +RcppExport SEXP _arrow_fs___FileStats__set_type(SEXP x_sexp, SEXP type_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type x(x_sexp); + Rcpp::traits::input_parameter::type type(type_sexp); + fs___FileStats__set_type(x, type); + return R_NilValue; +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileStats__set_type(SEXP x_sexp, SEXP type_sexp){ + Rf_error("Cannot call fs___FileStats__set_type(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +std::string fs___FileStats__path(const std::shared_ptr& x); +RcppExport SEXP _arrow_fs___FileStats__path(SEXP x_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type x(x_sexp); + return Rcpp::wrap(fs___FileStats__path(x)); +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileStats__path(SEXP x_sexp){ + Rf_error("Cannot call fs___FileStats__path(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +void fs___FileStats__set_path(const std::shared_ptr& x, const std::string& path); +RcppExport SEXP _arrow_fs___FileStats__set_path(SEXP x_sexp, SEXP path_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type x(x_sexp); + Rcpp::traits::input_parameter::type path(path_sexp); + fs___FileStats__set_path(x, path); + return R_NilValue; +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileStats__set_path(SEXP x_sexp, SEXP path_sexp){ + Rf_error("Cannot call fs___FileStats__set_path(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +int64_t fs___FileStats__size(const std::shared_ptr& x); +RcppExport SEXP _arrow_fs___FileStats__size(SEXP x_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type x(x_sexp); + return Rcpp::wrap(fs___FileStats__size(x)); +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileStats__size(SEXP x_sexp){ + Rf_error("Cannot call fs___FileStats__size(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +void fs___FileStats__set_size(const std::shared_ptr& x, int64_t size); +RcppExport SEXP _arrow_fs___FileStats__set_size(SEXP x_sexp, SEXP size_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type x(x_sexp); + Rcpp::traits::input_parameter::type size(size_sexp); + fs___FileStats__set_size(x, size); + return R_NilValue; +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileStats__set_size(SEXP x_sexp, SEXP size_sexp){ + Rf_error("Cannot call fs___FileStats__set_size(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +std::string fs___FileStats__base_name(const std::shared_ptr& x); +RcppExport SEXP _arrow_fs___FileStats__base_name(SEXP x_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type x(x_sexp); + return Rcpp::wrap(fs___FileStats__base_name(x)); +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileStats__base_name(SEXP x_sexp){ + Rf_error("Cannot call fs___FileStats__base_name(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +std::string fs___FileStats__extension(const std::shared_ptr& x); +RcppExport SEXP _arrow_fs___FileStats__extension(SEXP x_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type x(x_sexp); + return Rcpp::wrap(fs___FileStats__extension(x)); +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileStats__extension(SEXP x_sexp){ + Rf_error("Cannot call fs___FileStats__extension(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +SEXP fs___FileStats__mtime(const std::shared_ptr& x); +RcppExport SEXP _arrow_fs___FileStats__mtime(SEXP x_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type x(x_sexp); + return Rcpp::wrap(fs___FileStats__mtime(x)); +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileStats__mtime(SEXP x_sexp){ + Rf_error("Cannot call fs___FileStats__mtime(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +void fs___FileStats__set_mtime(const std::shared_ptr& x, SEXP time); +RcppExport SEXP _arrow_fs___FileStats__set_mtime(SEXP x_sexp, SEXP time_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type x(x_sexp); + Rcpp::traits::input_parameter::type time(time_sexp); + fs___FileStats__set_mtime(x, time); + return R_NilValue; +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileStats__set_mtime(SEXP x_sexp, SEXP time_sexp){ + Rf_error("Cannot call fs___FileStats__set_mtime(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +std::string fs___Selector__base_dir(const std::shared_ptr& selector); +RcppExport SEXP _arrow_fs___Selector__base_dir(SEXP selector_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type selector(selector_sexp); + return Rcpp::wrap(fs___Selector__base_dir(selector)); +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___Selector__base_dir(SEXP selector_sexp){ + Rf_error("Cannot call fs___Selector__base_dir(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +bool fs___Selector__allow_non_existent(const std::shared_ptr& selector); +RcppExport SEXP _arrow_fs___Selector__allow_non_existent(SEXP selector_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type selector(selector_sexp); + return Rcpp::wrap(fs___Selector__allow_non_existent(selector)); +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___Selector__allow_non_existent(SEXP selector_sexp){ + Rf_error("Cannot call fs___Selector__allow_non_existent(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +bool fs___Selector__recursive(const std::shared_ptr& selector); +RcppExport SEXP _arrow_fs___Selector__recursive(SEXP selector_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type selector(selector_sexp); + return Rcpp::wrap(fs___Selector__recursive(selector)); +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___Selector__recursive(SEXP selector_sexp){ + Rf_error("Cannot call fs___Selector__recursive(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +std::shared_ptr fs___Selector__create(const std::string& base_dir, bool allow_non_existent, bool recursive); +RcppExport SEXP _arrow_fs___Selector__create(SEXP base_dir_sexp, SEXP allow_non_existent_sexp, SEXP recursive_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter::type base_dir(base_dir_sexp); + Rcpp::traits::input_parameter::type allow_non_existent(allow_non_existent_sexp); + Rcpp::traits::input_parameter::type recursive(recursive_sexp); + return Rcpp::wrap(fs___Selector__create(base_dir, allow_non_existent, recursive)); +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___Selector__create(SEXP base_dir_sexp, SEXP allow_non_existent_sexp, SEXP recursive_sexp){ + Rf_error("Cannot call fs___Selector__create(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +std::vector> fs___FileSystem__GetTargetStats_Paths(const std::shared_ptr& file_system, const std::vector& paths); +RcppExport SEXP _arrow_fs___FileSystem__GetTargetStats_Paths(SEXP file_system_sexp, SEXP paths_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type file_system(file_system_sexp); + Rcpp::traits::input_parameter&>::type paths(paths_sexp); + return Rcpp::wrap(fs___FileSystem__GetTargetStats_Paths(file_system, paths)); +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileSystem__GetTargetStats_Paths(SEXP file_system_sexp, SEXP paths_sexp){ + Rf_error("Cannot call fs___FileSystem__GetTargetStats_Paths(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +std::vector> fs___FileSystem__GetTargetStats_Selector(const std::shared_ptr& file_system, const std::shared_ptr& selector); +RcppExport SEXP _arrow_fs___FileSystem__GetTargetStats_Selector(SEXP file_system_sexp, SEXP selector_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type file_system(file_system_sexp); + Rcpp::traits::input_parameter&>::type selector(selector_sexp); + return Rcpp::wrap(fs___FileSystem__GetTargetStats_Selector(file_system, selector)); +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileSystem__GetTargetStats_Selector(SEXP file_system_sexp, SEXP selector_sexp){ + Rf_error("Cannot call fs___FileSystem__GetTargetStats_Selector(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +void fs___FileSystem__CreateDir(const std::shared_ptr& file_system, const std::string& path, bool recursive); +RcppExport SEXP _arrow_fs___FileSystem__CreateDir(SEXP file_system_sexp, SEXP path_sexp, SEXP recursive_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type file_system(file_system_sexp); + Rcpp::traits::input_parameter::type path(path_sexp); + Rcpp::traits::input_parameter::type recursive(recursive_sexp); + fs___FileSystem__CreateDir(file_system, path, recursive); + return R_NilValue; +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileSystem__CreateDir(SEXP file_system_sexp, SEXP path_sexp, SEXP recursive_sexp){ + Rf_error("Cannot call fs___FileSystem__CreateDir(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +void fs___FileSystem__DeleteDir(const std::shared_ptr& file_system, const std::string& path); +RcppExport SEXP _arrow_fs___FileSystem__DeleteDir(SEXP file_system_sexp, SEXP path_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type file_system(file_system_sexp); + Rcpp::traits::input_parameter::type path(path_sexp); + fs___FileSystem__DeleteDir(file_system, path); + return R_NilValue; +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileSystem__DeleteDir(SEXP file_system_sexp, SEXP path_sexp){ + Rf_error("Cannot call fs___FileSystem__DeleteDir(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +void fs___FileSystem__DeleteDirContents(const std::shared_ptr& file_system, const std::string& path); +RcppExport SEXP _arrow_fs___FileSystem__DeleteDirContents(SEXP file_system_sexp, SEXP path_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type file_system(file_system_sexp); + Rcpp::traits::input_parameter::type path(path_sexp); + fs___FileSystem__DeleteDirContents(file_system, path); + return R_NilValue; +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileSystem__DeleteDirContents(SEXP file_system_sexp, SEXP path_sexp){ + Rf_error("Cannot call fs___FileSystem__DeleteDirContents(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +void fs___FileSystem__DeleteFile(const std::shared_ptr& file_system, const std::string& path); +RcppExport SEXP _arrow_fs___FileSystem__DeleteFile(SEXP file_system_sexp, SEXP path_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type file_system(file_system_sexp); + Rcpp::traits::input_parameter::type path(path_sexp); + fs___FileSystem__DeleteFile(file_system, path); + return R_NilValue; +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileSystem__DeleteFile(SEXP file_system_sexp, SEXP path_sexp){ + Rf_error("Cannot call fs___FileSystem__DeleteFile(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +void fs___FileSystem__DeleteFiles(const std::shared_ptr& file_system, const std::vector& paths); +RcppExport SEXP _arrow_fs___FileSystem__DeleteFiles(SEXP file_system_sexp, SEXP paths_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type file_system(file_system_sexp); + Rcpp::traits::input_parameter&>::type paths(paths_sexp); + fs___FileSystem__DeleteFiles(file_system, paths); + return R_NilValue; +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileSystem__DeleteFiles(SEXP file_system_sexp, SEXP paths_sexp){ + Rf_error("Cannot call fs___FileSystem__DeleteFiles(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +void fs___FileSystem__Move(const std::shared_ptr& file_system, const std::string& src, const std::string& dest); +RcppExport SEXP _arrow_fs___FileSystem__Move(SEXP file_system_sexp, SEXP src_sexp, SEXP dest_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type file_system(file_system_sexp); + Rcpp::traits::input_parameter::type src(src_sexp); + Rcpp::traits::input_parameter::type dest(dest_sexp); + fs___FileSystem__Move(file_system, src, dest); + return R_NilValue; +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileSystem__Move(SEXP file_system_sexp, SEXP src_sexp, SEXP dest_sexp){ + Rf_error("Cannot call fs___FileSystem__Move(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +void fs___FileSystem__CopyFile(const std::shared_ptr& file_system, const std::string& src, const std::string& dest); +RcppExport SEXP _arrow_fs___FileSystem__CopyFile(SEXP file_system_sexp, SEXP src_sexp, SEXP dest_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type file_system(file_system_sexp); + Rcpp::traits::input_parameter::type src(src_sexp); + Rcpp::traits::input_parameter::type dest(dest_sexp); + fs___FileSystem__CopyFile(file_system, src, dest); + return R_NilValue; +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileSystem__CopyFile(SEXP file_system_sexp, SEXP src_sexp, SEXP dest_sexp){ + Rf_error("Cannot call fs___FileSystem__CopyFile(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +std::shared_ptr fs___FileSystem__OpenInputStream(const std::shared_ptr& file_system, const std::string& path); +RcppExport SEXP _arrow_fs___FileSystem__OpenInputStream(SEXP file_system_sexp, SEXP path_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type file_system(file_system_sexp); + Rcpp::traits::input_parameter::type path(path_sexp); + return Rcpp::wrap(fs___FileSystem__OpenInputStream(file_system, path)); +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileSystem__OpenInputStream(SEXP file_system_sexp, SEXP path_sexp){ + Rf_error("Cannot call fs___FileSystem__OpenInputStream(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +std::shared_ptr fs___FileSystem__OpenInputFile(const std::shared_ptr& file_system, const std::string& path); +RcppExport SEXP _arrow_fs___FileSystem__OpenInputFile(SEXP file_system_sexp, SEXP path_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type file_system(file_system_sexp); + Rcpp::traits::input_parameter::type path(path_sexp); + return Rcpp::wrap(fs___FileSystem__OpenInputFile(file_system, path)); +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileSystem__OpenInputFile(SEXP file_system_sexp, SEXP path_sexp){ + Rf_error("Cannot call fs___FileSystem__OpenInputFile(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +std::shared_ptr fs___FileSystem__OpenOutputStream(const std::shared_ptr& file_system, const std::string& path); +RcppExport SEXP _arrow_fs___FileSystem__OpenOutputStream(SEXP file_system_sexp, SEXP path_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type file_system(file_system_sexp); + Rcpp::traits::input_parameter::type path(path_sexp); + return Rcpp::wrap(fs___FileSystem__OpenOutputStream(file_system, path)); +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileSystem__OpenOutputStream(SEXP file_system_sexp, SEXP path_sexp){ + Rf_error("Cannot call fs___FileSystem__OpenOutputStream(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +std::shared_ptr fs___FileSystem__OpenAppendStream(const std::shared_ptr& file_system, const std::string& path); +RcppExport SEXP _arrow_fs___FileSystem__OpenAppendStream(SEXP file_system_sexp, SEXP path_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter&>::type file_system(file_system_sexp); + Rcpp::traits::input_parameter::type path(path_sexp); + return Rcpp::wrap(fs___FileSystem__OpenAppendStream(file_system, path)); +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___FileSystem__OpenAppendStream(SEXP file_system_sexp, SEXP path_sexp){ + Rf_error("Cannot call fs___FileSystem__OpenAppendStream(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +std::shared_ptr fs___LocalFileSystem__create(); +RcppExport SEXP _arrow_fs___LocalFileSystem__create(){ +BEGIN_RCPP + return Rcpp::wrap(fs___LocalFileSystem__create()); +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___LocalFileSystem__create(){ + Rf_error("Cannot call fs___LocalFileSystem__create(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + +// filesystem.cpp +#if defined(ARROW_R_WITH_ARROW) +std::shared_ptr fs___SubTreeFileSystem__create(const std::string& base_path, const std::shared_ptr& base_fs); +RcppExport SEXP _arrow_fs___SubTreeFileSystem__create(SEXP base_path_sexp, SEXP base_fs_sexp){ +BEGIN_RCPP + Rcpp::traits::input_parameter::type base_path(base_path_sexp); + Rcpp::traits::input_parameter&>::type base_fs(base_fs_sexp); + return Rcpp::wrap(fs___SubTreeFileSystem__create(base_path, base_fs)); +END_RCPP +} +#else +RcppExport SEXP _arrow_fs___SubTreeFileSystem__create(SEXP base_path_sexp, SEXP base_fs_sexp){ + Rf_error("Cannot call fs___SubTreeFileSystem__create(). Please use arrow::install_arrow() to install required runtime libraries. "); +} +#endif + // io.cpp #if defined(ARROW_R_WITH_ARROW) std::shared_ptr io___Readable__Read(const std::shared_ptr& x, int64_t nbytes); @@ -3835,6 +4303,35 @@ static const R_CallMethodDef CallEntries[] = { { "_arrow_Field__Equals", (DL_FUNC) &_arrow_Field__Equals, 2}, { "_arrow_Field__nullable", (DL_FUNC) &_arrow_Field__nullable, 1}, { "_arrow_Field__type", (DL_FUNC) &_arrow_Field__type, 1}, + { "_arrow_fs___FileStats__type", (DL_FUNC) &_arrow_fs___FileStats__type, 1}, + { "_arrow_fs___FileStats__set_type", (DL_FUNC) &_arrow_fs___FileStats__set_type, 2}, + { "_arrow_fs___FileStats__path", (DL_FUNC) &_arrow_fs___FileStats__path, 1}, + { "_arrow_fs___FileStats__set_path", (DL_FUNC) &_arrow_fs___FileStats__set_path, 2}, + { "_arrow_fs___FileStats__size", (DL_FUNC) &_arrow_fs___FileStats__size, 1}, + { "_arrow_fs___FileStats__set_size", (DL_FUNC) &_arrow_fs___FileStats__set_size, 2}, + { "_arrow_fs___FileStats__base_name", (DL_FUNC) &_arrow_fs___FileStats__base_name, 1}, + { "_arrow_fs___FileStats__extension", (DL_FUNC) &_arrow_fs___FileStats__extension, 1}, + { "_arrow_fs___FileStats__mtime", (DL_FUNC) &_arrow_fs___FileStats__mtime, 1}, + { "_arrow_fs___FileStats__set_mtime", (DL_FUNC) &_arrow_fs___FileStats__set_mtime, 2}, + { "_arrow_fs___Selector__base_dir", (DL_FUNC) &_arrow_fs___Selector__base_dir, 1}, + { "_arrow_fs___Selector__allow_non_existent", (DL_FUNC) &_arrow_fs___Selector__allow_non_existent, 1}, + { "_arrow_fs___Selector__recursive", (DL_FUNC) &_arrow_fs___Selector__recursive, 1}, + { "_arrow_fs___Selector__create", (DL_FUNC) &_arrow_fs___Selector__create, 3}, + { "_arrow_fs___FileSystem__GetTargetStats_Paths", (DL_FUNC) &_arrow_fs___FileSystem__GetTargetStats_Paths, 2}, + { "_arrow_fs___FileSystem__GetTargetStats_Selector", (DL_FUNC) &_arrow_fs___FileSystem__GetTargetStats_Selector, 2}, + { "_arrow_fs___FileSystem__CreateDir", (DL_FUNC) &_arrow_fs___FileSystem__CreateDir, 3}, + { "_arrow_fs___FileSystem__DeleteDir", (DL_FUNC) &_arrow_fs___FileSystem__DeleteDir, 2}, + { "_arrow_fs___FileSystem__DeleteDirContents", (DL_FUNC) &_arrow_fs___FileSystem__DeleteDirContents, 2}, + { "_arrow_fs___FileSystem__DeleteFile", (DL_FUNC) &_arrow_fs___FileSystem__DeleteFile, 2}, + { "_arrow_fs___FileSystem__DeleteFiles", (DL_FUNC) &_arrow_fs___FileSystem__DeleteFiles, 2}, + { "_arrow_fs___FileSystem__Move", (DL_FUNC) &_arrow_fs___FileSystem__Move, 3}, + { "_arrow_fs___FileSystem__CopyFile", (DL_FUNC) &_arrow_fs___FileSystem__CopyFile, 3}, + { "_arrow_fs___FileSystem__OpenInputStream", (DL_FUNC) &_arrow_fs___FileSystem__OpenInputStream, 2}, + { "_arrow_fs___FileSystem__OpenInputFile", (DL_FUNC) &_arrow_fs___FileSystem__OpenInputFile, 2}, + { "_arrow_fs___FileSystem__OpenOutputStream", (DL_FUNC) &_arrow_fs___FileSystem__OpenOutputStream, 2}, + { "_arrow_fs___FileSystem__OpenAppendStream", (DL_FUNC) &_arrow_fs___FileSystem__OpenAppendStream, 2}, + { "_arrow_fs___LocalFileSystem__create", (DL_FUNC) &_arrow_fs___LocalFileSystem__create, 0}, + { "_arrow_fs___SubTreeFileSystem__create", (DL_FUNC) &_arrow_fs___SubTreeFileSystem__create, 2}, { "_arrow_io___Readable__Read", (DL_FUNC) &_arrow_io___Readable__Read, 2}, { "_arrow_io___InputStream__Close", (DL_FUNC) &_arrow_io___InputStream__Close, 1}, { "_arrow_io___OutputStream__Close", (DL_FUNC) &_arrow_io___OutputStream__Close, 1}, diff --git a/r/src/arrow_types.h b/r/src/arrow_types.h index 4259a48cdc5..38f3f83b22f 100644 --- a/r/src/arrow_types.h +++ b/r/src/arrow_types.h @@ -33,6 +33,11 @@ struct symbols { static SEXP inspect; static SEXP row_names; }; + +struct data { + static SEXP classes_POSIXct; +}; + } // namespace r } // namespace arrow @@ -167,6 +172,8 @@ inline std::shared_ptr extract(SEXP x) { #include #include #include +#include +#include #include #include #include @@ -187,6 +194,7 @@ RCPP_EXPOSED_ENUM_NODECL(arrow::StatusCode) RCPP_EXPOSED_ENUM_NODECL(arrow::io::FileMode::type) RCPP_EXPOSED_ENUM_NODECL(arrow::ipc::Message::Type) RCPP_EXPOSED_ENUM_NODECL(arrow::Compression::type) +RCPP_EXPOSED_ENUM_NODECL(arrow::fs::FileType) SEXP ChunkedArray__as_vector(const std::shared_ptr& chunked_array); SEXP Array__as_vector(const std::shared_ptr& array); diff --git a/r/src/filesystem.cpp b/r/src/filesystem.cpp new file mode 100644 index 00000000000..e204645392c --- /dev/null +++ b/r/src/filesystem.cpp @@ -0,0 +1,230 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "./arrow_types.h" +#if defined(ARROW_R_WITH_ARROW) + +// FileStype + +// [[arrow::export]] +arrow::fs::FileType fs___FileStats__type(const std::shared_ptr& x) { + return x->type(); +} + +// [[arrow::export]] +void fs___FileStats__set_type(const std::shared_ptr& x, + arrow::fs::FileType type) { + x->set_type(type); +} + +// [[arrow::export]] +std::string fs___FileStats__path(const std::shared_ptr& x) { + return x->path(); +} + +// [[arrow::export]] +void fs___FileStats__set_path(const std::shared_ptr& x, + const std::string& path) { + x->set_path(path); +} + +// [[arrow::export]] +int64_t fs___FileStats__size(const std::shared_ptr& x) { + return x->size(); +} + +// [[arrow::export]] +void fs___FileStats__set_size(const std::shared_ptr& x, + int64_t size) { + x->set_size(size); +} + +// [[arrow::export]] +std::string fs___FileStats__base_name(const std::shared_ptr& x) { + return x->base_name(); +} + +// [[arrow::export]] +std::string fs___FileStats__extension(const std::shared_ptr& x) { + return x->extension(); +} + +// [[arrow::export]] +SEXP fs___FileStats__mtime(const std::shared_ptr& x) { + SEXP res = PROTECT(Rf_allocVector(REALSXP, 1)); + // .mtime() gets us nanoseconds since epoch, POSIXct is seconds since epoch as a double + REAL(res)[0] = static_cast(x->mtime().time_since_epoch().count()) / 1000000000; + Rf_classgets(res, arrow::r::data::classes_POSIXct); + UNPROTECT(1); + return res; +} + +// [[arrow::export]] +void fs___FileStats__set_mtime(const std::shared_ptr& x, + SEXP time) { + auto nanosecs = + std::chrono::nanoseconds(static_cast(REAL(time)[0] * 1000000000)); + x->set_mtime(arrow::fs::TimePoint(nanosecs)); +} + +// Selector + +// [[arrow::export]] +std::string fs___Selector__base_dir( + const std::shared_ptr& selector) { + return selector->base_dir; +} + +// [[arrow::export]] +bool fs___Selector__allow_non_existent( + const std::shared_ptr& selector) { + return selector->allow_non_existent; +} + +// [[arrow::export]] +bool fs___Selector__recursive(const std::shared_ptr& selector) { + return selector->recursive; +} + +// [[arrow::export]] +std::shared_ptr fs___Selector__create(const std::string& base_dir, + bool allow_non_existent, + bool recursive) { + auto selector = std::make_shared(); + selector->base_dir = base_dir; + selector->allow_non_existent = allow_non_existent; + selector->recursive = recursive; + return selector; +} + +// FileSystem + +template +std::vector> shared_ptr_vector(const std::vector& vec) { + std::vector> res(vec.size()); + std::transform(vec.begin(), vec.end(), res.begin(), [](const arrow::fs::FileStats& x) { + return std::make_shared(x); + }); + return res; +} + +// [[arrow::export]] +std::vector> fs___FileSystem__GetTargetStats_Paths( + const std::shared_ptr& file_system, + const std::vector& paths) { + std::vector out; + STOP_IF_NOT_OK(file_system->GetTargetStats(paths, &out)); + return shared_ptr_vector(out); +} + +// [[arrow::export]] +std::vector> +fs___FileSystem__GetTargetStats_Selector( + const std::shared_ptr& file_system, + const std::shared_ptr& selector) { + std::vector out; + STOP_IF_NOT_OK(file_system->GetTargetStats(*selector, &out)); + return shared_ptr_vector(out); +} + +// [[arrow::export]] +void fs___FileSystem__CreateDir(const std::shared_ptr& file_system, + const std::string& path, bool recursive) { + STOP_IF_NOT_OK(file_system->CreateDir(path, recursive)); +} + +// [[arrow::export]] +void fs___FileSystem__DeleteDir(const std::shared_ptr& file_system, + const std::string& path) { + STOP_IF_NOT_OK(file_system->DeleteDir(path)); +} + +// [[arrow::export]] +void fs___FileSystem__DeleteDirContents( + const std::shared_ptr& file_system, const std::string& path) { + STOP_IF_NOT_OK(file_system->DeleteDirContents(path)); +} + +// [[arrow::export]] +void fs___FileSystem__DeleteFile( + const std::shared_ptr& file_system, const std::string& path) { + STOP_IF_NOT_OK(file_system->DeleteFile(path)); +} + +// [[arrow::export]] +void fs___FileSystem__DeleteFiles( + const std::shared_ptr& file_system, + const std::vector& paths) { + STOP_IF_NOT_OK(file_system->DeleteFiles(paths)); +} + +// [[arrow::export]] +void fs___FileSystem__Move(const std::shared_ptr& file_system, + const std::string& src, const std::string& dest) { + STOP_IF_NOT_OK(file_system->Move(src, dest)); +} + +// [[arrow::export]] +void fs___FileSystem__CopyFile(const std::shared_ptr& file_system, + const std::string& src, const std::string& dest) { + STOP_IF_NOT_OK(file_system->CopyFile(src, dest)); +} + +// [[arrow::export]] +std::shared_ptr fs___FileSystem__OpenInputStream( + const std::shared_ptr& file_system, const std::string& path) { + std::shared_ptr stream; + STOP_IF_NOT_OK(file_system->OpenInputStream(path, &stream)); + return stream; +} + +// [[arrow::export]] +std::shared_ptr fs___FileSystem__OpenInputFile( + const std::shared_ptr& file_system, const std::string& path) { + std::shared_ptr file; + STOP_IF_NOT_OK(file_system->OpenInputFile(path, &file)); + return file; +} + +// [[arrow::export]] +std::shared_ptr fs___FileSystem__OpenOutputStream( + const std::shared_ptr& file_system, const std::string& path) { + std::shared_ptr stream; + STOP_IF_NOT_OK(file_system->OpenOutputStream(path, &stream)); + return stream; +} + +// [[arrow::export]] +std::shared_ptr fs___FileSystem__OpenAppendStream( + const std::shared_ptr& file_system, const std::string& path) { + std::shared_ptr stream; + STOP_IF_NOT_OK(file_system->OpenAppendStream(path, &stream)); + return stream; +} + +// [[arrow::export]] +std::shared_ptr fs___LocalFileSystem__create() { + return std::make_shared(); +} + +// [[arrow::export]] +std::shared_ptr fs___SubTreeFileSystem__create( + const std::string& base_path, const std::shared_ptr& base_fs) { + return std::make_shared(base_path, base_fs); +} + +#endif diff --git a/r/src/parquet.cpp b/r/src/parquet.cpp index 692916bb963..9f9216a9522 100644 --- a/r/src/parquet.cpp +++ b/r/src/parquet.cpp @@ -31,29 +31,26 @@ parquet___arrow___ArrowReaderProperties__Make(bool use_threads) { // [[arrow::export]] void parquet___arrow___ArrowReaderProperties__set_use_threads( - const std::shared_ptr& properties, - bool use_threads) { + const std::shared_ptr& properties, bool use_threads) { properties->set_use_threads(use_threads); } // [[arrow::export]] bool parquet___arrow___ArrowReaderProperties__get_use_threads( - const std::shared_ptr& properties, - bool use_threads) { + const std::shared_ptr& properties, bool use_threads) { return properties->use_threads(); } // [[arrow::export]] bool parquet___arrow___ArrowReaderProperties__get_read_dictionary( - const std::shared_ptr& properties, - int column_index) { + const std::shared_ptr& properties, int column_index) { return properties->read_dictionary(column_index); } // [[arrow::export]] void parquet___arrow___ArrowReaderProperties__set_read_dictionary( - const std::shared_ptr& properties, - int column_index, bool read_dict) { + const std::shared_ptr& properties, int column_index, + bool read_dict) { properties->set_read_dictionary(column_index, read_dict); } diff --git a/r/src/symbols.cpp b/r/src/symbols.cpp index 828033bf82d..6f27eec126d 100644 --- a/r/src/symbols.cpp +++ b/r/src/symbols.cpp @@ -25,6 +25,16 @@ SEXP symbols::dot_Internal = Rf_install(".Internal"); SEXP symbols::inspect = Rf_install("inspect"); SEXP symbols::row_names = Rf_install("row.names"); +SEXP get_classes_POSIXct() { + SEXP classes = Rf_allocVector(STRSXP, 2); + R_PreserveObject(classes); + SET_STRING_ELT(classes, 0, Rf_mkChar("POSIXct")); + SET_STRING_ELT(classes, 1, Rf_mkChar("POSIXt")); + return classes; +} + +SEXP data::classes_POSIXct = get_classes_POSIXct(); + void inspect(SEXP obj) { Rcpp::Shield call_inspect(Rf_lang2(symbols::inspect, obj)); Rcpp::Shield call_internal(Rf_lang2(symbols::dot_Internal, call_inspect)); diff --git a/r/tests/testthat/test-filesystem.R b/r/tests/testthat/test-filesystem.R new file mode 100644 index 00000000000..1c198383066 --- /dev/null +++ b/r/tests/testthat/test-filesystem.R @@ -0,0 +1,123 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +context("test-type") + +test_that("LocalFilesystem", { + fs <- LocalFileSystem$create() + DESCRIPTION <- system.file("DESCRIPTION", package = "arrow") + stat <- fs$GetTargetStats(DESCRIPTION)[[1]] + expect_equal(stat$base_name(), "DESCRIPTION") + expect_equal(stat$extension(), "") + expect_equal(stat$type, FileType$File) + expect_equal(stat$path, DESCRIPTION) + info <- file.info(DESCRIPTION) + + expect_equal(stat$size, info$size) + expect_equal(stat$mtime, info$mtime) + + tf <- tempfile(fileext = ".txt") + fs$CopyFile(DESCRIPTION, tf) + stat <- fs$GetTargetStats(tf)[[1]] + expect_equal(stat$extension(), "txt") + expect_equal(stat$size, info$size) + expect_equal(readLines(DESCRIPTION), readLines(tf)) + + tf2 <- tempfile(fileext = ".txt") + fs$Move(tf, tf2) + stats <- fs$GetTargetStats(c(tf, tf2, dirname(tf))) + expect_equal(stats[[1]]$type, FileType$NonExistent) + expect_equal(stats[[2]]$type, FileType$File) + expect_equal(stats[[3]]$type, FileType$Directory) + + fs$DeleteFile(tf2) + expect_equal(fs$GetTargetStats(tf2)[[1L]]$type, FileType$NonExistent) + expect_true(!file.exists(tf2)) + + expect_equal(fs$GetTargetStats(tf)[[1L]]$type, FileType$NonExistent) + expect_true(!file.exists(tf)) + + td <- tempfile() + fs$CreateDir(td) + expect_equal(fs$GetTargetStats(td)[[1L]]$type, FileType$Directory) + fs$CopyFile(DESCRIPTION, file.path(td, "DESCRIPTION")) + fs$DeleteDirContents(td) + expect_equal(length(dir(td)), 0L) + fs$DeleteDir(td) + expect_equal(fs$GetTargetStats(td)[[1L]]$type, FileType$NonExistent) + + tf3 <- tempfile() + os <- fs$OpenOutputStream(path = tf3) + bytes <- as.raw(1:40) + os$write(bytes) + os$close() + + is <- fs$OpenInputStream(tf3) + buf <- is$Read(40) + expect_equal(buf$data(), bytes) + is$close() +}) + +test_that("SubTreeFilesystem", { + dir.create(td <- tempfile()) + DESCRIPTION <- system.file("DESCRIPTION", package = "arrow") + file.copy(DESCRIPTION, file.path(td, "DESCRIPTION")) + + local_fs <- LocalFileSystem$create() + st_fs <- SubTreeFileSystem$create(td, local_fs) + expect_is(st_fs, "SubTreeFileSystem") + expect_is(st_fs, "FileSystem") + st_fs$CreateDir("test") + st_fs$CopyFile("DESCRIPTION", "DESC.txt") + skip_on_os("windows") # See ARROW-6622 + stats <- st_fs$GetTargetStats(c("DESCRIPTION", "test", "nope", "DESC.txt")) + expect_equal(stats[[1L]]$type, FileType$File) + expect_equal(stats[[2L]]$type, FileType$Directory) + expect_equal(stats[[3L]]$type, FileType$NonExistent) + expect_equal(stats[[4L]]$type, FileType$File) + expect_equal(stats[[4L]]$extension(), "txt") + + local_fs$DeleteDirContents(td) + stats <- st_fs$GetTargetStats(c("DESCRIPTION", "test", "nope", "DESC.txt")) + expect_equal(stats[[1L]]$type, FileType$NonExistent) + expect_equal(stats[[2L]]$type, FileType$NonExistent) + expect_equal(stats[[3L]]$type, FileType$NonExistent) + expect_equal(stats[[4L]]$type, FileType$NonExistent) +}) + +test_that("LocalFileSystem + Selector", { + fs <- LocalFileSystem$create() + dir.create(td <- tempfile()) + writeLines("blah blah", file.path(td, "one.txt")) + writeLines("yada yada", file.path(td, "two.txt")) + dir.create(file.path(td, "dir")) + writeLines("...", file.path(td, "dir", "three.txt")) + + selector <- Selector$create(td, recursive = TRUE) + stats <- fs$GetTargetStats(selector) + expect_equal(length(stats), 4L) + types <- sapply(stats, function(.x) .x$type) + expect_equal(sum(types == FileType$File), 3L) + expect_equal(sum(types == FileType$Directory), 1L) + + selector <- Selector$create(td, recursive = FALSE) + stats <- fs$GetTargetStats(selector) + expect_equal(length(stats), 3L) + types <- sapply(stats, function(.x) .x$type) + expect_equal(sum(types == FileType$File), 2L) + expect_equal(sum(types == FileType$Directory), 1L) +})