This is an automated email from the ASF dual-hosted git repository.
npr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 36d80e3 ARROW-11050: [R] Handle RecordBatch in write_parquet()
36d80e3 is described below
commit 36d80e37373ab49454eb47b2a89c10215ca1b67e
Author: Neal Richardson <[email protected]>
AuthorDate: Wed Dec 30 08:26:19 2020 -0800
ARROW-11050: [R] Handle RecordBatch in write_parquet()
Closes #9033 from nealrichardson/write-batch
Authored-by: Neal Richardson <[email protected]>
Signed-off-by: Neal Richardson <[email protected]>
---
r/R/parquet.R | 2 +-
r/tests/testthat/helper-parquet.R | 9 +++++++--
r/tests/testthat/test-parquet.R | 8 +++++++-
3 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/r/R/parquet.R b/r/R/parquet.R
index 722d1d2..ccf87c2 100644
--- a/r/R/parquet.R
+++ b/r/R/parquet.R
@@ -150,7 +150,7 @@ write_parquet <- function(x,
properties = NULL,
arrow_properties = NULL) {
x_out <- x
- if (is.data.frame(x)) {
+ if (!inherits(x, "Table")) {
x <- Table$create(x)
}
diff --git a/r/tests/testthat/helper-parquet.R
b/r/tests/testthat/helper-parquet.R
index e614f52..e2fd761 100644
--- a/r/tests/testthat/helper-parquet.R
+++ b/r/tests/testthat/helper-parquet.R
@@ -16,9 +16,14 @@
# under the License.
expect_parquet_roundtrip <- function(tab, ...) {
+ expect_equivalent(parquet_roundtrip(tab, ...), tab)
+}
+
+parquet_roundtrip <- function(x, ...) {
+ # write/read parquet, returns Table
tf <- tempfile()
on.exit(unlink(tf))
- write_parquet(tab, tf, ...)
- expect_equivalent(read_parquet(tf, as_data_frame = FALSE), tab)
+ write_parquet(x, tf, ...)
+ read_parquet(tf, as_data_frame = FALSE)
}
diff --git a/r/tests/testthat/test-parquet.R b/r/tests/testthat/test-parquet.R
index a59f2ea..3e8d8e0 100644
--- a/r/tests/testthat/test-parquet.R
+++ b/r/tests/testthat/test-parquet.R
@@ -17,7 +17,7 @@
context("Parquet file reading/writing")
-pq_file <- system.file("v0.7.1.parquet", package="arrow")
+pq_file <- system.file("v0.7.1.parquet", package = "arrow")
test_that("reading a known Parquet file to tibble", {
skip_if_not_available("snappy")
@@ -98,6 +98,12 @@ test_that("write_parquet() handles various write_statistics=
specs", {
expect_parquet_roundtrip(tab, write_statistics = c(x1 = TRUE, x2 = TRUE))
})
+test_that("write_parquet() accepts RecordBatch too", {
+ batch <- RecordBatch$create(x1 = 1:5, x2 = 1:5, y = 1:5)
+ tab <- parquet_roundtrip(batch)
+ expect_equivalent(tab, Table$create(batch))
+})
+
test_that("write_parquet() can truncate timestamps", {
tab <- Table$create(x1 = as.POSIXct("2020/06/03 18:00:00", tz = "UTC"))
expect_type_equal(tab$x1, timestamp("us", "UTC"))