Skip to content

Commit

Permalink
+ ParquetWriterProperties$create() and associated ParquetWriterProper…
Browse files Browse the repository at this point in the history
…ties_Builder class skeleton
  • Loading branch information
romainfrancois committed Sep 27, 2019
1 parent 1b84ad4 commit 09ea0ad
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 5 deletions.
8 changes: 8 additions & 0 deletions r/R/arrowExports.R

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

21 changes: 16 additions & 5 deletions r/R/parquet.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ ParquetWriterProperties$default <- function() {
shared_ptr(ParquetWriterProperties, parquet___default_writer_properties())
}

ParquetWriterProperties_Builder <- R6Class("ParquetWriterProperties_Builder", inherit = Object,
public = list(

)
)

ParquetWriterProperties$create <- function() {
builder <- shared_ptr(ParquetWriterProperties_Builder, parquet___WriterProperties___Builder__create())
shared_ptr(ParquetWriterProperties, parquet___WriterProperties___Builder__build(builder))
}

ParquetFileWriter <- R6Class("ParquetFileWriter", inherit = Object,
public = list(
WriteTable = function(table, chunk_size) {
Expand Down Expand Up @@ -103,7 +114,7 @@ ParquetFileWriter$create <- function(
#'
#' @param table An [arrow::Table][Table], or an object convertible to it with [to_arrow()]
#' @param sink an [arrow::io::OutputStream][OutputStream] or a string which is interpreted as a file path
#' @param chunk_size chunk size
#' @param chunk_size chunk size. If NULL, the number of rows of the table is used
#'
#' @examples
#' \donttest{
Expand All @@ -116,23 +127,23 @@ ParquetFileWriter$create <- function(
#'
#' }
#' @export
write_parquet <- function(table, sink, chunk_size = table$num_rows) {
write_parquet <- function(table, sink, chunk_size = NULL) {
UseMethod("write_parquet", sink)
}

#' @export
write_parquet.OutputStream <- function(table, sink, chunk_size = table$num_rows) {
write_parquet.OutputStream <- function(table, sink, chunk_size = NULL) {
table <- to_arrow(table)
schema <- table$schema
properties <- ParquetWriterProperties$default()
arrow_properties <- ParquetArrowWriterProperties$default()
writer <- ParquetFileWriter$create(schema, sink, properties = properties, arrow_properties = arrow_properties)
writer$WriteTable(table, chunk_size = chunk_size)
writer$WriteTable(table, chunk_size = chunk_size %||% table$num_rows)
writer$Close()
}

#' @export
write_parquet.character <- function(table, sink, chunk_size = table$num_rows) {
write_parquet.character <- function(table, sink, chunk_size = NULL) {
table <- to_arrow(table)
file_sink <- FileOutputStream$create(sink)
on.exit(file_sink$close())
Expand Down
31 changes: 31 additions & 0 deletions r/src/arrowExports.cpp

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

10 changes: 10 additions & 0 deletions r/src/parquet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ std::shared_ptr<parquet::WriterProperties> parquet___default_writer_properties()
return parquet::default_writer_properties();
}

// [[arrow::export]]
std::shared_ptr<parquet::WriterProperties::Builder> parquet___WriterProperties___Builder__create() {
return std::make_shared<parquet::WriterProperties::Builder>();
}

// [[arrow::export]]
std::shared_ptr<parquet::WriterProperties> parquet___WriterProperties___Builder__build(const std::shared_ptr<parquet::WriterProperties::Builder>& builder) {
return builder->build();
}

// [[arrow::export]]
std::unique_ptr<parquet::arrow::FileWriter> parquet___arrow___ParquetFileWriter__Open(
const std::shared_ptr<arrow::Schema>& schema,
Expand Down

0 comments on commit 09ea0ad

Please sign in to comment.