wjones127 commented on code in PR #12751:
URL: https://github.com/apache/arrow/pull/12751#discussion_r852402786


##########
r/R/record-batch.R:
##########
@@ -189,3 +189,62 @@ record_batch <- RecordBatch$create
 
 #' @export
 names.RecordBatch <- function(x) x$names()
+
+#' @export
+rbind.RecordBatch <- function(...) {
+  abort("Use `Table$create()` to combine record batches")
+}
+
+cbind_check_length <- function(target_length, length, idx, call = 
caller_env()) {
+  if (length != target_length) {
+    abort(
+      c("Non-scalar inputs must have an equal number of rows.",
+        i = sprintf("..1 has %d, ..%d has %d", target_length, idx, length)),
+      call = call
+    )
+  }
+}
+
+#' @export
+cbind.RecordBatch <- function(...) {
+  call <- sys.call()
+  inputs <- list(...)
+  num_rows <- inputs[[1]]$num_rows
+
+  # These names are only used for scalar or arrays
+  arg_names <- if (is.null(names(inputs))) character(length(inputs)) else 
names(inputs)
+  arg_names <- make.names(arg_names, unique = TRUE)
+
+  batches <- map(seq_along(inputs), function(i) {
+    input <- inputs[[i]]
+    name <- arg_names[i]
+
+    if (inherits(input, "RecordBatch")) {
+      cbind_check_length(num_rows, input$num_rows, i, call)
+      input
+    } else if (inherits(input, "data.frame")) {
+      cbind_check_length(num_rows, nrow(input), i, call)
+      RecordBatch$create(input)
+    } else if (length(input) == 1) {
+      RecordBatch$create("{name}" := repeat_value_as_array(input, num_rows))

Review Comment:
   Did this; we now construct a flattened list of columns out of the inputs.



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