Skip to content

Commit

Permalink
Add mmap argument to table_reader so that character method uses mmap_…
Browse files Browse the repository at this point in the history
…open instead of file_open if mmap = TRUE
  • Loading branch information
romainfrancois committed Nov 12, 2018
1 parent c844bd4 commit e0db6cc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
25 changes: 15 additions & 10 deletions r/R/feather.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,29 +113,32 @@ write_feather_RecordBatch <- function(data, stream) {
#' A arrow::ipc::feather::TableReader to read from a file
#'
#' @param file A file path, arrow::io::RandomAccessFile
#' @param mmap Is the file memory mapped (applicable to the character and fs_path methods)
#' @param ... extra parameters
#'
#' @export
table_reader <- function(file){
table_reader <- function(file, ...){
UseMethod("table_reader")
}

#' @export
table_reader.default <- function(file) {
table_reader.default <- function(file, ...) {
stop("unsupported")
}

#' @export
table_reader.character <- function(file) {
table_reader(fs::path_abs(file))
table_reader.character <- function(file, mmap = TRUE, ...) {
table_reader(fs::path_abs(file), mmap = mmap, ...)
}

#' @export
table_reader.fs_path <- function(file) {
table_reader(file_open(file))
table_reader.fs_path <- function(file, mmap = TRUE, ...) {
stream <- if(isTRUE(mmap)) mmap_open(file, ...) else file_open(file, ...)
table_reader(stream)
}

#' @export
`table_reader.arrow::io::RandomAccessFile` <- function(file){
`table_reader.arrow::io::RandomAccessFile` <- function(file, ...){
unique_ptr(`arrow::ipc::feather::TableReader`, ipc___feather___TableReader__Open(file))
}

Expand All @@ -146,10 +149,12 @@ table_reader.fs_path <- function(file) {

#' Read a feather file
#'
#' @param reader a arrow::ipc::feather::TableReader or whatever the [table_reader()] function can handle
#' @param file a arrow::ipc::feather::TableReader or whatever the [table_reader()] function can handle
#' @param ... additional parameters
#'
#' @return an arrow::Table
#'
#' @export
read_feather <- function(reader){
table_reader(reader)$Read()
read_feather <- function(file, ...){
table_reader(file, ...)$Read()
}
6 changes: 4 additions & 2 deletions r/man/read_feather.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion r/man/table_reader.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e0db6cc

Please sign in to comment.