Skip to content

Commit

Permalink
Enable writeCSV from RecordBatchReader
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisnic committed Dec 16, 2021
1 parent b9ad11f commit b45f9e6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
4 changes: 3 additions & 1 deletion r/R/csv.R
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ write_csv_arrow <- function(x,
x <- Table$create(x)
}

assert_that(is_writable_table(x))
assert_that(is_writable_table(x) | inherits(x, "FileSystemDataset"))

if (!inherits(sink, "OutputStream")) {
sink <- make_output_stream(sink)
Expand All @@ -703,6 +703,8 @@ write_csv_arrow <- function(x,
csv___WriteCSV__RecordBatch(x, write_options, sink)
} else if (inherits(x, "Table")) {
csv___WriteCSV__Table(x, write_options, sink)
} else if (inherits(x, "FileSystemDataset")) {
csv___WriteCSV__RecordBatchReader(x, write_options, sink)
}

invisible(x_out)
Expand Down
19 changes: 19 additions & 0 deletions r/src/arrowExports.cpp

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

16 changes: 16 additions & 0 deletions r/tests/testthat/test-csv.R
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,19 @@ test_that("read_csv_arrow() deals with BOMs (byte-order-marks) correctly", {
tibble(a = 1, b = 2)
)
})

test_that("write_csv_arrow can write from FileSystemDataset objects", {

skip_if_not_available("dataset")
data_dir <- make_temp_dir()
write_dataset(tbl_no_dates, data_dir, partitioning = "lgl")
data_in <- open_dataset(data_dir)

csv_file <- tempfile()
tbl_out <- write_csv_arrow(data_in, csv_file)


expect_true(file.exists(csv_file))
expect_identical(tbl_out, tbl_no_dates)

})

0 comments on commit b45f9e6

Please sign in to comment.