Skip to content

Commit

Permalink
define and use internal make_valid_version() function
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed Sep 27, 2019
1 parent 004cf90 commit 9bee8de
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions r/R/parquet.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,29 @@ ParquetArrowWriterProperties$create <- function(use_deprecated_int96_timestamps
}
}

valid_parquet_version <- c(
"1.0" = ParquetVersionType$PARQUET_1_0,
"2.0" = ParquetVersionType$PARQUET_2_0
)

make_valid_version <- function(version, valid_versions = valid_parquet_version) {
if (is_integerish(version)) {
version <- as.character(version)
}
tryCatch(
valid_versions[[match.arg(version, choices = names(valid_versions))]],
error = function(cond) {
stop('"version" should be one of ', oxford_paste(names(valid_versions), "or"), call.=FALSE)
}
)
}

ParquetWriterProperties <- R6Class("ParquetWriterProperties", inherit = Object)
ParquetWriterPropertiesBuilder <- R6Class("ParquetWriterPropertiesBuilder", inherit = Object,
public = list(
set_version = function(version = NULL) {
if (!is.null(version)) {
if (identical(version, "1.0")) {
parquet___ArrowWriterProperties___Builder__version(self, ParquetVersionType$PARQUET_1_0)
} else if (identical(version, "2.0")) {
parquet___ArrowWriterProperties___Builder__version(self, ParquetVersionType$PARQUET_2_0)
} else {
abort("unknown parquet version")
}
parquet___ArrowWriterProperties___Builder__version(self, make_valid_version(version))
}
},

Expand Down

0 comments on commit 9bee8de

Please sign in to comment.