Skip to content
Merged
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
28 changes: 24 additions & 4 deletions r/R/dataset-write.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,12 @@ write_dataset <- function(
existing_data_behavior_opts <- c("delete_matching", "overwrite", "error")
existing_data_behavior <- match(match.arg(existing_data_behavior), existing_data_behavior_opts) - 1L

if (!missing(max_rows_per_file) && missing(max_rows_per_group) && max_rows_per_group > max_rows_per_file) {
if (
!missing(max_rows_per_file) &&
missing(max_rows_per_group) &&
max_rows_per_file > 0 &&
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This line max_rows_per_file > 0 is the one condition that was change, yeah? The rest is whitespace?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yup!

max_rows_per_group > max_rows_per_file
) {
max_rows_per_group <- max_rows_per_file
}

Expand Down Expand Up @@ -290,7 +295,12 @@ write_delim_dataset <- function(
quote = c("needed", "all", "none"),
preserve_order = FALSE
) {
if (!missing(max_rows_per_file) && missing(max_rows_per_group) && max_rows_per_group > max_rows_per_file) {
if (
!missing(max_rows_per_file) &&
missing(max_rows_per_group) &&
max_rows_per_file > 0 &&
max_rows_per_group > max_rows_per_file
) {
max_rows_per_group <- max_rows_per_file
}

Expand Down Expand Up @@ -343,7 +353,12 @@ write_csv_dataset <- function(
quote = c("needed", "all", "none"),
preserve_order = FALSE
) {
if (!missing(max_rows_per_file) && missing(max_rows_per_group) && max_rows_per_group > max_rows_per_file) {
if (
!missing(max_rows_per_file) &&
missing(max_rows_per_group) &&
max_rows_per_file > 0 &&
max_rows_per_group > max_rows_per_file
) {
max_rows_per_group <- max_rows_per_file
}

Expand Down Expand Up @@ -395,7 +410,12 @@ write_tsv_dataset <- function(
quote = c("needed", "all", "none"),
preserve_order = FALSE
) {
if (!missing(max_rows_per_file) && missing(max_rows_per_group) && max_rows_per_group > max_rows_per_file) {
if (
!missing(max_rows_per_file) &&
missing(max_rows_per_group) &&
max_rows_per_file > 0 &&
max_rows_per_group > max_rows_per_file
) {
max_rows_per_group <- max_rows_per_file
}

Expand Down
10 changes: 10 additions & 0 deletions r/tests/testthat/test-dataset-write.R
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,16 @@ test_that("max_rows_per_group is adjusted if at odds with max_rows_per_file", {
)
})

test_that("max_rows_per_file = 0 does not trigger max_rows_per_group adjustment (ARROW-40742)", {
skip_if_not_available("parquet")

# max_rows_per_file = 0 means "no limit" and should not error
dst_dir <- make_temp_dir()
expect_no_error(
write_dataset(df1, dst_dir, max_rows_per_file = 0L)
)
})


test_that("write_dataset checks for format-specific arguments", {
df <- tibble::tibble(
Expand Down
Loading