You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/01/25 15:38:19 UTC

[GitHub] [arrow] jonkeane commented on a change in pull request #12083: ARROW-14744: [R] open_dataset() error when `schema` argument supplied, but `column_names` not supplied to `CSVReadOptions`

jonkeane commented on a change in pull request #12083:
URL: https://github.com/apache/arrow/pull/12083#discussion_r791842872



##########
File path: r/R/dataset-format.R
##########
@@ -122,6 +122,31 @@ CsvFileFormat$create <- function(...,
                                  opts = csv_file_format_parse_options(...),
                                  convert_options = csv_file_format_convert_opts(...),
                                  read_options = csv_file_format_read_opts(...)) {
+
+  options <- list(...)
+  schema  <- options[["schema"]]
+
+  column_names     <- read_options$column_names
+  schema_names     <- names(schema)
+
+  if (!is.null(schema) & !identical(schema_names, column_names)) {
+
+    # Element wise comparison and set differnce of column_names and names in schema
+    mismatch_colnames <- column_names[match(column_names, schema_names, nomatch = 0) != seq(column_names)]
+    not_in_schema     <- setdiff(schema_names, column_names)
+
+    abort(c(
+            paste(
+                "column_names not matching or not found in schema-names:",
+                deparse1(c(mismatch_colnames, not_in_schema))
+            ),
+            i = "Set column_names to match names of schema",
+            i = "Omit the column_names argument",
+            i = "Omit the read_options argument"

Review comment:
       I agree with @thisisnic, I really like solutions provided in error messages generally. But here, since there are so many ways one can get to this (and not all of the solutions would work in all of those paths), it's probably better to simply error with the problem up above




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org