nealrichardson commented on a change in pull request #11971:
URL: https://github.com/apache/arrow/pull/11971#discussion_r804751670



##########
File path: r/R/csv.R
##########
@@ -699,15 +699,21 @@ write_csv_arrow <- function(x,
   if (is.null(write_options)) {
     write_options <- readr_to_csv_write_options(
       include_header = include_header,
-      batch_size = batch_size)
+      batch_size = batch_size
+    )
   }
 
   x_out <- x
+
+  if (inherits(x, "arrow_dplyr_query")) {
+    x <- as.data.frame(x)
+  }
+
   if (is.data.frame(x)) {
     x <- Table$create(x)
   }
 
-  assert_that(is_writable_table(x))
+  assert_that(is_writable_table(x) || inherits(x, c("Dataset", 
"arrow_dplyr_query")))

Review comment:
       Can we just deal with this in our `if` block below?
   
   ```suggestion
   ```

##########
File path: r/R/csv.R
##########
@@ -699,15 +699,21 @@ write_csv_arrow <- function(x,
   if (is.null(write_options)) {
     write_options <- readr_to_csv_write_options(
       include_header = include_header,
-      batch_size = batch_size)
+      batch_size = batch_size
+    )
   }
 
   x_out <- x
+
+  if (inherits(x, "arrow_dplyr_query")) {
+    x <- as.data.frame(x)
+  }
+

Review comment:
       ```suggestion
   ```

##########
File path: r/R/csv.R
##########
@@ -718,6 +724,9 @@ write_csv_arrow <- function(x,
     csv___WriteCSV__RecordBatch(x, write_options, sink)
   } else if (inherits(x, "Table")) {
     csv___WriteCSV__Table(x, write_options, sink)
+  } else if (inherits(x, c("Dataset", "arrow_dplyr_query"))) {
+    rb_reader <- Scanner$create(x)$ToRecordBatchReader()
+    csv___WriteCSV__RecordBatchReader(rb_reader, write_options, sink)

Review comment:
       ```suggestion
       csv___WriteCSV__RecordBatchReader(rb_reader, write_options, sink)
     } else if (inherits(x, "RecordBatchReader")) {
       csv___WriteCSV__RecordBatchReader(x, write_options, sink)
     } else {
       stop("[insert message here that x is not a type we can write]", call. = 
FALSE)
   ```




-- 
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]


Reply via email to