toppyy commented on a change in pull request #12083:
URL: https://github.com/apache/arrow/pull/12083#discussion_r791814292
##########
File path: r/tests/testthat/test-dataset-csv.R
##########
@@ -299,3 +299,21 @@ test_that("open_dataset() deals with BOMs
(byte-order-marks) correctly", {
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)
+
+ # Mismatch of column names vs schema given via read_options should raise an
error
+ opts <- CsvReadOptions$create(column_names = c("i", "d"))
+ schema <- schema(int = int32(), dbl = float64())
+
+ expect_error(
+ open_dataset(csv_dir, format = "csv", schema = schema, read_options =
opts),
+ "column_names not matching or not found in schema-names"
+ )
Review comment:
Thanks again for all of the comments, really helpful!
At the moment the example you provided would *not* raise an error if I've
got it right. This is due to the following logic in `csv_file_format_read_opts`:
https://github.com/apache/arrow/blob/0fa4b9ca1e7b13ac230f85075d86d783eeea6a74/r/R/dataset-format.R#L223-L225
If schema is set, it overrides `column_names` in all situations. Because the
check is done after `csv_file_format_read_opts` no error is raised despite of
conflicting arguments from the user (which might be a little confusing for the
user?).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]