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
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.

18 changes: 18 additions & 0 deletions r/R/parquet.R
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,18 @@ calculate_chunk_size <- function(
#' - `$set_thrift_string_size_limit()`
#' - `$thrift_container_size_limit()`
#' - `$set_thrift_container_size_limit()`
#' - `$page_checksum_verification()`: Whether page checksums are verified
#' when present (default `FALSE`).
#' - `$set_page_checksum_verification(check_crc)`: Enable or disable page
#' checksum verification with a logical value.
#'
#' @examplesIf arrow_with_parquet()
#' reader_props <- ParquetReaderProperties$create()
#' reader_props$set_page_checksum_verification(TRUE)
#' tf <- tempfile()
#' write_parquet(data.frame(x = 1:5), tf)
#' read_parquet(tf, reader_props = reader_props)
#' unlink(tf)
#'
#' @export
ParquetReaderProperties <- R6Class(
Expand All @@ -689,6 +701,12 @@ ParquetReaderProperties <- R6Class(
},
set_thrift_container_size_limit = function(size) {
parquet___arrow___ReaderProperties__set_thrift_container_size_limit(self, size)
},
page_checksum_verification = function() {
parquet___arrow___ReaderProperties__get_page_checksum_verification(self)
},
set_page_checksum_verification = function(check_crc) {
parquet___arrow___ReaderProperties__set_page_checksum_verification(self, check_crc)
}
)
)
Expand Down
14 changes: 14 additions & 0 deletions r/man/ParquetReaderProperties.Rd

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

34 changes: 34 additions & 0 deletions r/src/arrowExports.cpp

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

12 changes: 12 additions & 0 deletions r/src/parquet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ void parquet___arrow___ReaderProperties__set_thrift_container_size_limit(
properties->set_thrift_container_size_limit(size);
}

// [[parquet::export]]
bool parquet___arrow___ReaderProperties__get_page_checksum_verification(
const std::shared_ptr<parquet::ReaderProperties>& properties) {
return properties->page_checksum_verification();
}

// [[parquet::export]]
void parquet___arrow___ReaderProperties__set_page_checksum_verification(
const std::shared_ptr<parquet::ReaderProperties>& properties, bool check_crc) {
properties->set_page_checksum_verification(check_crc);
}

// [[parquet::export]]
void parquet___arrow___ArrowReaderProperties__set_use_threads(
const std::shared_ptr<parquet::ArrowReaderProperties>& properties, bool use_threads) {
Expand Down
53 changes: 53 additions & 0 deletions r/tests/testthat/test-parquet.R
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,59 @@ test_that("thrift string and container size can be specified when reading Parque
expect_identical(collect.ArrowTabular(data), example_data)
})

test_that("Parquet page checksum verification can be enabled and disabled", {
reader_props <- ParquetReaderProperties$create()
expect_identical(reader_props$page_checksum_verification(), FALSE)
reader_props$set_page_checksum_verification(TRUE)
expect_identical(reader_props$page_checksum_verification(), TRUE)
reader_props$set_page_checksum_verification(FALSE)
expect_identical(reader_props$page_checksum_verification(), FALSE)
})

test_that("Parquet page checksum verification detects corrupt checksums", {
parquet_test_data <- file.path(
Sys.getenv("ARROW_SOURCE_HOME", ".."),
"cpp", "submodules", "parquet-testing", "data"
)
skip_if_not(dir.exists(parquet_test_data) | force_tests(), "Parquet test data missing")

reader_props <- ParquetReaderProperties$create()
corrupt_files <- c(
"datapage_v1-corrupt-checksum.parquet" = 5120L,
"rle-dict-uncompressed-corrupt-checksum.parquet" = 1000L
)
for (name in names(corrupt_files)) {
file <- file.path(parquet_test_data, name)
expect_equal(nrow(read_parquet(file)), corrupt_files[[name]])

reader_props$set_page_checksum_verification(TRUE)
expect_error(
read_parquet(file, reader_props = reader_props),
"CRC checksum verification failed"
)

reader_props$set_page_checksum_verification(FALSE)
expect_equal(nrow(read_parquet(file, reader_props = reader_props)), corrupt_files[[name]])
}

reader_props$set_page_checksum_verification(TRUE)
valid_files <- c(
"datapage_v1-uncompressed-checksum.parquet" = 5120L,
"plain-dict-uncompressed-checksum.parquet" = 1000L
)
for (name in names(valid_files)) {
file <- file.path(parquet_test_data, name)
expect_equal(nrow(read_parquet(file, reader_props = reader_props)), valid_files[[name]])
}

# Files without page checksums remain readable when verification is enabled.
tf <- tempfile()
on.exit(unlink(tf))
table <- Table$create(x = 1:5)
write_parquet(table, tf, compression = "uncompressed")
expect_equal(read_parquet(tf, as_data_frame = FALSE, reader_props = reader_props), table)
})

test_that("We can use WriteBatch on ParquetFileWriter", {
tf <- tempfile()
on.exit(unlink(tf))
Expand Down
Loading