1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713
|
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
skip_if_not_available("dataset")
library(dplyr, warn.conflicts = FALSE)
csv_dir <- make_temp_dir()
tsv_dir <- make_temp_dir()
# Data containing a header row
tbl <- df1[, c("int", "dbl")]
header_csv_dir <- make_temp_dir()
headerless_csv_dir <- make_temp_dir()
test_that("Setup (putting data in the dirs)", {
dir.create(file.path(csv_dir, 5))
dir.create(file.path(csv_dir, 6))
write.csv(df1, file.path(csv_dir, 5, "file1.csv"), row.names = FALSE)
write.csv(df2, file.path(csv_dir, 6, "file2.csv"), row.names = FALSE)
expect_length(dir(csv_dir, recursive = TRUE), 2)
# Now, tab-delimited
dir.create(file.path(tsv_dir, 5))
dir.create(file.path(tsv_dir, 6))
write.table(df1, file.path(tsv_dir, 5, "file1.tsv"), row.names = FALSE, sep = "\t")
write.table(df2, file.path(tsv_dir, 6, "file2.tsv"), row.names = FALSE, sep = "\t")
expect_length(dir(tsv_dir, recursive = TRUE), 2)
write.table(tbl, file.path(header_csv_dir, "file1.csv"), sep = ",", row.names = FALSE)
write.table(tbl, file.path(headerless_csv_dir, "file1.csv"), sep = ",", row.names = FALSE, col.names = FALSE)
})
test_that("CSV dataset", {
ds <- open_dataset(csv_dir, partitioning = "part", format = "csv")
expect_r6_class(ds$format, "CsvFileFormat")
expect_r6_class(ds$filesystem, "LocalFileSystem")
expect_named(ds, c(names(df1), "part"))
expect_identical(dim(ds), c(20L, 7L))
expect_equal(
ds |>
select(string = chr, integer = int, part) |>
filter(integer > 6 & part == 5) |>
collect() |>
summarize(mean = mean(as.numeric(integer))), # as.numeric bc they're being parsed as int64
df1 |>
select(string = chr, integer = int) |>
filter(integer > 6) |>
summarize(mean = mean(integer))
)
# Collecting virtual partition column works
expect_equal(
collect(ds) |> arrange(part) |> pull(part),
c(rep(5, 10), rep(6, 10))
)
})
test_that("CSV scan options", {
options <- FragmentScanOptions$create("text")
expect_equal(options$type, "csv")
options <- FragmentScanOptions$create("csv", null_values = c("mynull"), strings_can_be_null = TRUE)
expect_equal(options$type, "csv")
dst_dir <- make_temp_dir()
dst_file <- file.path(dst_dir, "data.csv")
df <- tibble(chr = c("foo", "mynull"))
write.csv(df, dst_file, row.names = FALSE, quote = FALSE)
ds <- open_dataset(dst_dir, format = "csv")
expect_equal(ds |> collect(), df)
sb <- ds$NewScan()
sb$FragmentScanOptions(options)
tab <- sb$Finish()$ToTable()
expect_equal_data_frame(tab, data.frame(chr = c("foo", NA), stringsAsFactors = FALSE))
# Set default convert options in CsvFileFormat
csv_format <- CsvFileFormat$create(
null_values = c("mynull"),
strings_can_be_null = TRUE
)
ds <- open_dataset(dst_dir, format = csv_format)
expect_equal(ds |> collect(), tibble(chr = c("foo", NA)))
# Set both parse and convert options
df <- tibble(chr = c("foo", "mynull"), chr2 = c("bar", "baz"))
write.table(df, dst_file, row.names = FALSE, quote = FALSE, sep = "\t")
ds <- open_dataset(dst_dir, format = "csv", delimiter = "\t", null_values = c("mynull"), strings_can_be_null = TRUE)
expect_equal(
ds |> collect(),
tibble(
chr = c("foo", NA),
chr2 = c("bar", "baz")
)
)
expect_equal(
ds |>
group_by(chr2) |>
summarize(na = all(is.na(chr))) |>
arrange(chr2) |>
collect(),
tibble(
chr2 = c("bar", "baz"),
na = c(FALSE, TRUE)
)
)
})
test_that("compressed CSV dataset", {
skip_if_not_available("gzip")
dst_dir <- make_temp_dir()
dst_file <- file.path(dst_dir, "data.csv.gz")
write.csv(df1, gzfile(dst_file), row.names = FALSE, quote = FALSE)
format <- FileFormat$create("csv")
ds <- open_dataset(dst_dir, format = format)
expect_r6_class(ds$format, "CsvFileFormat")
expect_r6_class(ds$filesystem, "LocalFileSystem")
expect_equal(
ds |>
select(string = chr, integer = int) |>
filter(integer > 6 & integer < 11) |>
collect() |>
summarize(mean = mean(integer)),
df1 |>
select(string = chr, integer = int) |>
filter(integer > 6) |>
summarize(mean = mean(integer))
)
})
test_that("CSV dataset options", {
dst_dir <- make_temp_dir()
dst_file <- file.path(dst_dir, "data.csv")
df <- tibble(chr = letters[1:10])
write.csv(df, dst_file, row.names = FALSE, quote = FALSE)
format <- FileFormat$create("csv", skip_rows = 1)
ds <- open_dataset(dst_dir, format = format)
expect_equal(
ds |>
select(string = a) |>
collect(),
df1[-1, ] |>
select(string = chr)
)
ds <- open_dataset(dst_dir, format = "csv", column_names = c("foo"))
expect_equal(
ds |>
select(string = foo) |>
collect(),
tibble(string = c(c("chr"), letters[1:10]))
)
})
test_that("Other text delimited dataset", {
ds1 <- open_dataset(tsv_dir, partitioning = "part", format = "tsv")
expect_equal(
ds1 |>
select(string = chr, integer = int, part) |>
filter(integer > 6 & part == 5) |>
collect() |>
summarize(mean = mean(as.numeric(integer))), # as.numeric bc they're being parsed as int64
df1 |>
select(string = chr, integer = int) |>
filter(integer > 6) |>
summarize(mean = mean(integer))
)
ds2 <- open_dataset(tsv_dir, partitioning = "part", format = "text", delimiter = "\t")
expect_equal(
ds2 |>
select(string = chr, integer = int, part) |>
filter(integer > 6 & part == 5) |>
collect() |>
summarize(mean = mean(as.numeric(integer))), # as.numeric bc they're being parsed as int64
df1 |>
select(string = chr, integer = int) |>
filter(integer > 6) |>
summarize(mean = mean(integer))
)
})
test_that("readr parse options", {
arrow_opts <- names(formals(csv_parse_options))
readr_opts <- names(formals(readr_to_csv_parse_options))
# Arrow and readr parse options must be mutually exclusive, or else the code
# in `csv_file_format_parse_options()` will error or behave incorrectly. A
# failure of this test indicates that these two sets of option names are not
# mutually exclusive.
expect_equal(
intersect(arrow_opts, readr_opts),
character(0)
)
# With not yet supported readr parse options
expect_error(
open_dataset(tsv_dir, partitioning = "part", delim = "\t", col_select = "integer"),
"supported"
)
# With unrecognized (garbage) parse options
expect_error(
open_dataset(
tsv_dir,
partitioning = "part",
format = "text",
asdfg = "\\"
),
"Unrecognized"
)
# With both Arrow and readr parse options (disallowed)
expect_error(
open_dataset(
tsv_dir,
partitioning = "part",
format = "text",
quote = "\"",
quoting = TRUE
),
"either"
)
# With ambiguous partial option names (disallowed)
expect_error(
open_dataset(
tsv_dir,
partitioning = "part",
format = "text",
del = ","
),
"Ambiguous"
)
# With only readr parse options (and omitting format = "text")
ds1 <- open_dataset(tsv_dir, partitioning = "part", delim = "\t")
expect_equal(
ds1 |>
select(string = chr, integer = int, part) |>
filter(integer > 6 & part == 5) |>
collect() |>
summarize(mean = mean(as.numeric(integer))), # as.numeric bc they're being parsed as int64
df1 |>
select(string = chr, integer = int) |>
filter(integer > 6) |>
summarize(mean = mean(integer))
)
})
test_that("Can set null string values", {
dst_dir <- make_temp_dir()
df <- tibble(x = c(1, NA, 3))
write_dataset(df, dst_dir, null_string = "NULL_VALUE", format = "csv")
csv_contents <- readLines(list.files(dst_dir, full.names = TRUE)[1])
expect_equal(csv_contents, c("\"x\"", "1", "NULL_VALUE", "3"))
back <- open_dataset(dst_dir, null_values = "NULL_VALUE", format = "csv") |> collect()
expect_equal(df, back)
# Also works with `na` parameter
dst_dir <- make_temp_dir()
write_dataset(df, dst_dir, na = "another_null", format = "csv")
csv_contents <- readLines(list.files(dst_dir, full.names = TRUE)[1])
expect_equal(csv_contents, c("\"x\"", "1", "another_null", "3"))
back <- open_dataset(dst_dir, null_values = "another_null", format = "csv") |> collect()
expect_equal(df, back)
})
# see https://issues.apache.org/jira/browse/ARROW-12791
test_that("Error if no format specified and files are not parquet", {
expect_error(
open_dataset(csv_dir, partitioning = "part"),
"Did you mean to specify a 'format' other than the default (parquet)?",
fixed = TRUE
)
expect_error(
open_dataset(csv_dir, partitioning = "part", format = "parquet"),
"Parquet magic bytes not found"
)
})
test_that("Column names can be inferred from schema", {
# First row must be skipped if file has header
ds <- open_dataset(
header_csv_dir,
format = "csv",
schema = schema(int = int32(), dbl = float64()),
skip_rows = 1
)
expect_equal(collect(ds), tbl)
# If first row isn't skipped, supply user-friendly error
ds <- open_dataset(
header_csv_dir,
format = "csv",
schema = schema(int = int32(), dbl = float64())
)
expect_error(
collect(ds),
regexp = paste0(
"If you have supplied a schema and your data contains a ",
"header row, you should supply the argument `skip = 1` to ",
"prevent the header being read in as data."
)
)
ds <- open_dataset(
headerless_csv_dir,
format = "csv",
schema = schema(int = int32(), dbl = float64())
)
expect_equal(ds |> collect(), tbl)
})
test_that("Can use col_names readr parameter", {
expected_names <- c("my_int", "my_double")
ds <- open_dataset(
headerless_csv_dir,
format = "csv",
col_names = expected_names
)
expect_named(ds, expected_names)
expect_equal(ds |> collect(), set_names(tbl, expected_names))
# WITHOUT header, makes up names
ds <- open_dataset(
headerless_csv_dir,
format = "csv",
col_names = FALSE
)
expect_named(ds, c("f0", "f1"))
expect_equal(ds |> collect(), set_names(tbl, c("f0", "f1")))
# WITH header, gets names
ds <- open_dataset(
header_csv_dir,
format = "csv",
col_names = TRUE
)
expect_named(ds, c("int", "dbl"))
expect_equal(ds |> collect(), tbl)
ds <- open_dataset(
header_csv_dir,
format = "csv",
col_names = FALSE,
skip = 1
)
expect_named(ds, c("f0", "f1"))
expect_equal(ds |> collect(), set_names(tbl, c("f0", "f1")))
expect_error(
open_dataset(headerless_csv_dir, format = "csv", col_names = c("my_int"))
)
})
test_that("open_dataset() deals with BOMs (byte-order-marks) correctly", {
temp_dir <- make_temp_dir()
writeLines("\xef\xbb\xbfa,b\n1,2\n", con = file.path(temp_dir, "file1.csv"))
writeLines("\xef\xbb\xbfa,b\n3,4\n", con = file.path(temp_dir, "file2.csv"))
expect_equal(
open_dataset(temp_dir, format = "csv") |> collect() |> arrange(b),
tibble(a = c(1, 3), b = c(2, 4))
)
})
test_that("Error if read_options$column_names and schema-names differ (ARROW-14744)", {
dst_dir <- make_temp_dir()
dst_file <- file.path(dst_dir, "file.csv")
df <- df1[, c("int", "dbl")]
write.csv(df, dst_file, row.names = FALSE, quote = FALSE)
schema <- schema(int = int32(), dbl = float64())
# names in column_names but not in schema
expect_error(
open_dataset(csv_dir, format = "csv", schema = schema, column_names = c("int", "dbl", "lgl", "chr")),
"`lgl` and `chr` not present in `schema`"
)
# names in schema but not in column_names
expect_error(
open_dataset(csv_dir, format = "csv", schema = schema, column_names = c("int")),
"`dbl` not present in `column_names`"
)
# mismatches both ways
expect_error(
open_dataset(csv_dir, format = "csv", schema = schema, column_names = c("these", "wont", "match")),
"`these`, `wont`, and `match` not present in `schema`.*`int` and `dbl` not present in `column_names`"
)
# correct names wrong order
expect_error(
open_dataset(csv_dir, format = "csv", schema = schema, column_names = c("dbl", "int")),
"`column_names` and `schema` field names match but are not in the same order"
)
})
test_that("skip argument in open_dataset", {
tbl <- df1[, c("int", "dbl")]
header_csv_dir <- make_temp_dir()
write.table(tbl, file.path(header_csv_dir, "file1.csv"), sep = ",", row.names = FALSE)
ds <- open_dataset(
header_csv_dir,
format = "csv",
schema = schema(int = int32(), dbl = float64()),
skip = 1
)
expect_equal(collect(ds), tbl)
})
test_that("error message if non-schema passed in as schema to open_dataset", {
# passing in the schema function, not an actual schema
expect_error(
open_dataset(csv_dir, format = "csv", schema = schema),
regexp = "`schema` must be an object of class 'Schema' not 'function'.",
fixed = TRUE
)
})
test_that("CSV reading/parsing/convert options can be passed in as lists", {
tf <- tempfile()
on.exit(unlink(tf))
writeLines('"x"\n"y"\nNA\nNA\n"NULL"\n\n"foo"\n', tf)
ds1 <- open_dataset(
tf,
format = "csv",
convert_options = list(null_values = c("NA", "NULL"), strings_can_be_null = TRUE),
read_options = list(skip_rows = 1L)
) |>
collect()
ds2 <- open_dataset(
tf,
format = "csv",
convert_options = csv_convert_options(null_values = c(NA, "NA", "NULL"), strings_can_be_null = TRUE),
read_options = csv_read_options(skip_rows = 1L)
) |>
collect()
expect_equal(ds1, ds2)
})
test_that("open_delim_dataset params passed through to open_dataset", {
ds <- open_delim_dataset(csv_dir, delim = ",", partitioning = "part")
expect_r6_class(ds$format, "CsvFileFormat")
expect_r6_class(ds$filesystem, "LocalFileSystem")
expect_named(ds, c(names(df1), "part"))
expect_identical(dim(ds), c(20L, 7L))
# quote
dst_dir <- make_temp_dir()
dst_file <- file.path(dst_dir, "data.csv")
df <- data.frame(a = c(1, 2), b = c("'abc'", "'def'"))
write.csv(df, dst_file, row.names = FALSE, quote = FALSE)
ds_quote <- open_csv_dataset(dst_dir, quote = "'") |> collect()
expect_equal(ds_quote$b, c("abc", "def"))
# na
ds <- open_csv_dataset(csv_dir, partitioning = "part", na = c("", "NA", "FALSE")) |> collect()
expect_identical(
ds$lgl,
c(
TRUE,
NA,
NA,
TRUE,
NA,
TRUE,
NA,
NA,
TRUE,
NA,
TRUE,
NA,
NA,
TRUE,
NA,
TRUE,
NA,
NA,
TRUE,
NA
)
)
# col_names and skip
ds <- open_csv_dataset(
csv_dir,
partitioning = "part",
col_names = paste0("col_", 1:6),
skip = 1
) |>
collect()
expect_named(ds, c("col_1", "col_2", "col_3", "col_4", "col_5", "col_6", "part"))
expect_equal(nrow(ds), 20)
# col_types
dst_dir <- make_temp_dir()
dst_file <- file.path(dst_dir, "data.csv")
df <- data.frame(a = c(1, NA, 2), b = c("'abc'", NA, "'def'"))
write.csv(df, dst_file, row.names = FALSE, quote = FALSE)
data_schema <- schema(a = string(), b = string())
ds_strings <- open_csv_dataset(dst_dir, col_types = data_schema)
expect_equal(ds_strings$schema, schema(a = string(), b = string()))
# col_types - as compact schema
compact_schema <- schema(
int = int32(),
dbl = float64(),
lgl = bool(),
chr = utf8(),
fct = dictionary(),
ts = timestamp(unit = "ns")
)
ds <- open_csv_dataset(
csv_dir,
col_names = c("int", "dbl", "lgl", "chr", "fct", "ts"),
col_types = "idlcfT",
skip = 1
)
expect_equal(schema(ds), compact_schema)
# skip_empty_rows
tf <- tempfile()
writeLines('"x"\n"y"\nNA\nNA\n"NULL"\n\n\n', tf)
ds <- open_csv_dataset(tf, skip_empty_rows = FALSE) |> collect()
expect_equal(nrow(ds), 7)
# convert_options
ds <- open_csv_dataset(
csv_dir,
convert_options = list(null_values = c("NA", "", "FALSE"), strings_can_be_null = TRUE)
) |>
collect()
expect_equal(
ds$lgl,
c(TRUE, NA, NA, TRUE, NA, TRUE, NA, NA, TRUE, NA, TRUE, NA, NA, TRUE, NA, TRUE, NA, NA, TRUE, NA)
)
# read_options
ds <- open_csv_dataset(
csv_dir,
read_options = list(column_names = paste0("col_", 1:6))
) |>
collect()
expect_named(ds, c("col_1", "col_2", "col_3", "col_4", "col_5", "col_6"))
# schema
ds <- open_csv_dataset(
csv_dir,
schema = schema(
int = int64(),
dbl = float64(),
lgl = bool(),
chr = utf8(),
fct = utf8(),
ts = timestamp(unit = "s")
),
skip = 1
) |>
collect()
expect_named(ds, c("int", "dbl", "lgl", "chr", "fct", "ts"))
# quoted_na
dst_dir <- make_temp_dir()
dst_file <- file.path(dst_dir, "data.csv")
writeLines("text,num\none,1\ntwo,2\n,3\nfour,4", dst_file)
ds <- open_csv_dataset(dst_dir, quoted_na = TRUE) |> collect()
expect_equal(ds$text, c("one", "two", NA, "four"))
ds <- open_csv_dataset(dst_dir, quoted_na = FALSE) |> collect()
expect_equal(ds$text, c("one", "two", "", "four"))
# parse_options
dst_dir <- make_temp_dir()
dst_file <- file.path(dst_dir, "data.csv")
writeLines("x\n\n1\n\n\n2\n\n3", dst_file)
ds <- open_csv_dataset(
dst_dir,
parse_options = csv_parse_options(ignore_empty_lines = FALSE)
) |>
collect()
expect_equal(ds$x, c(NA, 1L, NA, NA, 2L, NA, 3L))
# timestamp_parsers
skip("GH-33708: timestamp_parsers don't appear to be working properly")
dst_dir <- make_temp_dir()
dst_file <- file.path(dst_dir, "data.csv")
df <- data.frame(time = "2023-01-16 19:47:57")
write.csv(df, dst_file, row.names = FALSE, quote = FALSE)
ds <- open_csv_dataset(dst_dir, timestamp_parsers = c(TimestampParser$create(format = "%d-%m-%y"))) |> collect()
expect_equal(ds$time, "16-01-2023")
})
test_that("CSVReadOptions printing", {
default_read_options <- csv_read_options()
custom_read_options <- csv_read_options(skip_rows = 102)
expect_output(print(default_read_options), "skip_rows: 0")
expect_output(print(custom_read_options), "skip_rows: 102")
})
test_that("CSVReadOptions field access", {
options <- csv_read_options()
expect_equal(options$skip_rows, 0)
expect_equal(options$autogenerate_column_names, FALSE)
expect_equal(options$skip_rows_after_names, 0)
expect_equal(options$use_threads, option_use_threads())
expect_equal(options$column_names, character(0))
expect_equal(options$block_size, 1048576L)
expect_equal(options$encoding, "UTF-8")
})
test_that("GH-34640 - CSV datasets are read in correctly when both schema and partitioning supplied", {
target_schema <- schema(
int = int32(),
dbl = float32(),
lgl = bool(),
chr = utf8(),
fct = utf8(),
ts = timestamp(unit = "s"),
part = int8()
)
ds <- open_dataset(
csv_dir,
partitioning = schema(part = int32()),
format = "csv",
schema = target_schema,
skip = 1
)
expect_r6_class(ds$format, "CsvFileFormat")
expect_r6_class(ds$filesystem, "LocalFileSystem")
expect_named(ds, c(names(df1), "part"))
expect_named(collect(ds), c(names(df1), "part"))
expect_identical(dim(ds), c(20L, 7L))
expect_equal(schema(ds), target_schema)
expect_equal(
ds |>
select(string = chr, integer = int, part) |>
filter(integer > 6 & part == 5) |>
collect() |>
summarize(mean = mean(as.numeric(integer))),
df1 |>
select(string = chr, integer = int) |>
filter(integer > 6) |>
summarize(mean = mean(integer))
)
})
test_that("open_dataset() with `decimal_point` argument", {
temp_dir <- make_temp_dir()
writeLines("x\ty\n1,2\tc", con = file.path(temp_dir, "file1.csv"))
expect_equal(
open_dataset(temp_dir, format = "tsv") |> collect(),
tibble(x = "1,2", y = "c")
)
expect_equal(
open_dataset(temp_dir, format = "tsv", decimal_point = ",") |> collect(),
tibble(x = 1.2, y = "c")
)
})
|