Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion r/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export(Buffer)
export(BufferOutputStream)
export(BufferReader)
export(ChunkedArray)
export(Codec)
export(CompressedInputStream)
export(CompressedOutputStream)
export(CompressionType)
Expand Down Expand Up @@ -75,7 +76,6 @@ export(boolean)
export(buffer)
export(cast_options)
export(chunked_array)
export(compression_codec)
export(contains)
export(csv_convert_options)
export(csv_parse_options)
Expand Down
46 changes: 28 additions & 18 deletions r/R/compression.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,30 @@
#' @include arrow-package.R
#' @include io.R

Codec <- R6Class("Codec", inherit = Object)

#' codec
#'
#' @param type type of codec
#'
#' @title Compression Codec class
#' @usage NULL
#' @format NULL
#' @docType class
#' @description Codecs allow you to create [compressed input and output
#' streams][compression].
#' @section Factory:
#' The `Codec$create()` factory method takes the following argument:
#' * `type`: string name of the compression method. See [CompressionType] for
#' a list of possible values. `type` may be upper- or lower-cased. Support
#' for compression methods depends on build-time flags for the C++ library.
#' Most builds support at least "gzip" and "snappy".
#' @rdname Codec
#' @name Codec
#' @export
compression_codec <- function(type = "GZIP") {
type <- CompressionType[[match.arg(type, names(CompressionType))]]
unique_ptr(Codec, util___Codec__Create(type))
Codec <- R6Class("Codec", inherit = Object)
Codec$create <- function(type = "gzip") {
if (is.character(type)) {
type <- unique_ptr(Codec, util___Codec__Create(
CompressionType[[match.arg(toupper(type), names(CompressionType))]]
))
}
assert_is(type, "Codec")
type
}

#' @title Compressed stream classes
Expand All @@ -39,7 +53,7 @@ compression_codec <- function(type = "GZIP") {
#' @usage NULL
#' @format NULL
#' @description `CompressedInputStream` and `CompressedOutputStream`
#' allow you to apply a [compression_codec()] to an
#' allow you to apply a compression [Codec] to an
#' input or output stream.
#'
#' @section Factory:
Expand All @@ -56,11 +70,8 @@ compression_codec <- function(type = "GZIP") {
#' @export
#' @include arrow-package.R
CompressedOutputStream <- R6Class("CompressedOutputStream", inherit = OutputStream)
CompressedOutputStream$create <- function(stream, codec = compression_codec()){
if (.Platform$OS.type == "windows") {
stop("'CompressedOutputStream' is unsupported in Windows.")
}
assert_is(codec, "Codec")
CompressedOutputStream$create <- function(stream, codec = "gzip"){
codec <- Codec$create(codec)
if (is.character(stream)) {
stream <- FileOutputStream$create(stream)
}
Expand All @@ -73,9 +84,8 @@ CompressedOutputStream$create <- function(stream, codec = compression_codec()){
#' @format NULL
#' @export
CompressedInputStream <- R6Class("CompressedInputStream", inherit = InputStream)
CompressedInputStream$create <- function(stream, codec = compression_codec()){
# TODO (npr): why would CompressedInputStream work on Windows if CompressedOutputStream doesn't? (and is it still the case that it does not?)
assert_is(codec, "Codec")
CompressedInputStream$create <- function(stream, codec = "gzip"){
codec <- Codec$create(codec)
if (is.character(stream)) {
stream <- ReadableFile$create(stream)
}
Expand Down
3 changes: 2 additions & 1 deletion r/data-raw/codegen.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ suppressPackageStartupMessages({
library(dplyr)
library(purrr)
library(glue)
library(vctrs)
})

if (packageVersion("decor") < '0.0.0.9001') {
Expand All @@ -53,7 +54,7 @@ decorations <- cpp_decorations() %>%
# more concisely
# rap( ~ decor:::parse_cpp_function(context))
mutate(functions = map(context, decor:::parse_cpp_function)) %>%
{ bind_cols(., bind_rows(pull(., functions))) } %>%
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? If so, please add vctrs to the README where the codegen script dependencies are discussed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, I see we already Suggest vctrs.

{ vec_cbind(., vec_rbind(!!!pull(., functions))) } %>%
select(-functions)

message(glue("*** > {n} functions decorated with [[arrow::export]]", n = nrow(decorations)))
Expand Down
21 changes: 21 additions & 0 deletions r/man/Codec.Rd

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

2 changes: 1 addition & 1 deletion r/man/compression.Rd

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

14 changes: 0 additions & 14 deletions r/man/compression_codec.Rd

This file was deleted.

2 changes: 1 addition & 1 deletion r/tests/testthat/helper-arrow.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# under the License.

# Wrap testthat::test_that with a check for the C++ library
options(..skip.tests = !arrow::arrow_available())
options(..skip.tests = !arrow:::arrow_available())

test_that <- function(what, code) {
testthat::test_that(what, {
Expand Down
2 changes: 0 additions & 2 deletions r/tests/testthat/test-compressed.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
context("Compressed.*Stream")

test_that("can write Buffer to CompressedOutputStream and read back in CompressedInputStream", {
skip_on_os("windows")

buf <- buffer(as.raw(sample(0:255, size = 1024, replace = TRUE)))

tf1 <- tempfile()
Expand Down