amoeba commented on code in PR #608:
URL: https://github.com/apache/arrow-nanoarrow/pull/608#discussion_r1761312478


##########
r/R/ipc.R:
##########
@@ -35,6 +35,8 @@
 #' @param x A `raw()` vector, connection, or file path from which to read
 #'   binary data. Common extensions indicating compression (.gz, .bz2, .zip)
 #'   are automatically uncompressed.
+#' @param data An object to write as an Arrow IPC stream, converted using

Review Comment:
   Is the allowable set of types really any object? This is a minor nit but 
just saying what types you know support may be an improvement.



##########
r/src/ipc.c:
##########
@@ -159,3 +261,40 @@ SEXP nanoarrow_c_ipc_array_reader_connection(SEXP con) {
   UNPROTECT(2);
   return array_stream_xptr;
 }
+
+SEXP nanoarrow_c_ipc_writer_connection(SEXP con) {
+  SEXP output_stream_xptr = PROTECT(output_stream_owning_xptr());
+  struct ArrowIpcOutputStream* output_stream =
+      (struct ArrowIpcOutputStream*)R_ExternalPtrAddr(output_stream_xptr);
+
+  output_stream->write = &write_con_output_stream;
+  output_stream->release = &release_con_output_stream;
+  output_stream->private_data = (SEXP)con;
+  nanoarrow_preserve_sexp(con);
+
+  SEXP writer_xptr = PROTECT(writer_owning_xptr());
+  struct ArrowIpcWriter* writer = (struct 
ArrowIpcWriter*)R_ExternalPtrAddr(writer_xptr);
+
+  int code = ArrowIpcWriterInit(writer, output_stream);
+  if (code != NANOARROW_OK) {
+    Rf_error("ArrowIpcWriterInit() failed");

Review Comment:
   Could a more useful error message be produced here? It looks like code is an 
errno-style error so it seems like it'd be possible.



##########
r/src/ipc.c:
##########
@@ -112,6 +157,34 @@ static SEXP call_readbin(void* hdata) {
   return R_NilValue;
 }
 
+static SEXP call_writebin(void* hdata) {
+  struct ConnectionInputStreamHandler* data = (struct 
ConnectionInputStreamHandler*)hdata;
+
+  // Write 16MB chunks

Review Comment:
   where does the 16MB value come from?



##########
r/R/ipc.R:
##########
@@ -24,8 +24,8 @@
 #' from files or URLs and is essentially a high performance equivalent of
 #' a CSV file that does a better job maintaining types.
 #'
-#' The nanoarrow package does not currently have the ability to write 
serialized
-#' IPC data: use [arrow::write_ipc_stream()] to write data from R, or use
+#' The nanoarrow package implements an IPC writer; however, you can also

Review Comment:
   I didn't look yet but do we have a PR updating 
https://arrow.apache.org/docs/status.html#ipc-format to match the change in 
this PR?



##########
r/R/ipc.R:
##########
@@ -107,6 +109,42 @@ read_nanoarrow.connection <- function(x, ..., lazy = 
FALSE) {
   check_stream_if_requested(reader, lazy)
 }
 
+#' @rdname read_nanoarrow

Review Comment:
   This puts `write_nanoarrow` on `read_nanoarrow`'s page which either needs to 
be updated or maybe `write_nanoarrow` just needs its own help page. I'm happy 
to contribute the latter.



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