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
8 changes: 5 additions & 3 deletions r/R/metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ apply_arrow_r_metadata <- function(x, r_metadata) {
call. = FALSE
)
} else {
x <- map2(x, columns_metadata, function(.x, .y) {
apply_arrow_r_metadata(.x, .y)
})
if (length(x) > 0) {
x <- map2(x, columns_metadata, function(.x, .y) {
apply_arrow_r_metadata(.x, .y)
})
}
}
x
}
Expand Down
65 changes: 30 additions & 35 deletions r/tests/testthat/test-metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,6 @@ test_that("Row-level metadata (does not) roundtrip in datasets", {
skip_if_not_available("dataset")
skip_if_not_available("parquet")

library(dplyr, warn.conflicts = FALSE)

df <- tibble::tibble(
metadata = list(
structure(1, my_value_as_attr = 1),
Expand All @@ -269,39 +267,36 @@ test_that("Row-level metadata (does not) roundtrip in datasets", {

dst_dir <- make_temp_dir()

withr::with_options(
list("arrow.preserve_row_level_metadata" = TRUE),
{
expect_warning(
write_dataset(df, dst_dir, partitioning = "part"),
"Row-level metadata is not compatible with datasets and will be discarded"
)

# Reset directory as previous write will have created some files and the default
# behavior is to error on existing
dst_dir <- make_temp_dir()
# but we need to write a dataset with row-level metadata to make sure when
# reading ones that have been written with them we warn appropriately
fake_func_name <- write_dataset
fake_func_name(df, dst_dir, partitioning = "part")

ds <- open_dataset(dst_dir)
expect_warning(
df_from_ds <- collect(ds),
"Row-level metadata is not compatible with this operation and has been ignored"
)
expect_equal(
arrange(df_from_ds, int),
arrange(df, int),
ignore_attr = TRUE
)

# however there is *no* warning if we don't select the metadata column
expect_warning(
df_from_ds <- ds %>% select(int) %>% collect(),
NA
)
}
withr::local_options("arrow.preserve_row_level_metadata" = TRUE)

expect_warning(
write_dataset(df, dst_dir, partitioning = "part"),
"Row-level metadata is not compatible with datasets and will be discarded"
)

# Reset directory as previous write will have created some files and the default
# behavior is to error on existing
dst_dir <- make_temp_dir()
# but we need to write a dataset with row-level metadata to make sure when
# reading ones that have been written with them we warn appropriately
fake_func_name <- write_dataset
fake_func_name(df, dst_dir, partitioning = "part")

ds <- open_dataset(dst_dir)
expect_warning(
df_from_ds <- collect(ds),
"Row-level metadata is not compatible with this operation and has been ignored"
)
expect_equal(
dplyr::arrange(df_from_ds, int),
dplyr::arrange(df, int),
ignore_attr = TRUE
)

# however there is *no* warning if we don't select the metadata column
expect_warning(
df_from_ds <- ds %>% dplyr::select(int) %>% dplyr::collect(),
NA
)
})

Expand Down