Skip to content
3 changes: 3 additions & 0 deletions r/R/dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ open_dataset <- function(sources,
partitioning = hive_partition(),
unify_schemas = NULL,
...) {
if (isFALSE(inherits(schema, "Schema")) && isFALSE(is.null(schema))) {
stop("'schema' must be a Schema object", call. = FALSE)
}
Comment thread
pachadotdev marked this conversation as resolved.
Outdated
Comment thread
pachadotdev marked this conversation as resolved.
Outdated
if (is_list_of(sources, "Dataset")) {
if (is.null(schema)) {
if (is.null(unify_schemas) || isTRUE(unify_schemas)) {
Expand Down
32 changes: 32 additions & 0 deletions r/tests/testthat/test-dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,38 @@ test_that("Hive partitioning", {
)
})

test_that("open_dataset fails when partitioning is passed as schema", {
Comment thread
pachadotdev marked this conversation as resolved.
Outdated
expect_error(
open_dataset(hive_dir, hive_partition(other = utf8(), group = uint8()))
)

# skipping schema
ds <- open_dataset(hive_dir, , hive_partition(other = utf8(), group = uint8()))
Comment thread
pachadotdev marked this conversation as resolved.
Outdated
expect_is(ds, "Dataset")
expect_equivalent(
ds %>%
filter(group == 2) %>%
select(chr, dbl) %>%
filter(dbl > 7 & dbl < 53) %>%
collect() %>%
arrange(dbl),
df2[1:2, c("chr", "dbl")]
)

# and again with explicit argument
ds <- open_dataset(hive_dir, partitioning = hive_partition(other = utf8(), group = uint8()))
expect_is(ds, "Dataset")
expect_equivalent(
ds %>%
filter(group == 2) %>%
select(chr, dbl) %>%
filter(dbl > 7 & dbl < 53) %>%
collect() %>%
arrange(dbl),
df2[1:2, c("chr", "dbl")]
)
})

test_that("Partitioning inference", {
# These are the same tests as above, just using the *PartitioningFactory
ds1 <- open_dataset(dataset_dir, partitioning = "part")
Expand Down