wjones127 commented on code in PR #12751:
URL: https://github.com/apache/arrow/pull/12751#discussion_r852182701
##########
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:
Not sure what you mean by "this". Repeating the values? Constructing a
single column batch? I'll look at the C++ constructor and see what I can
simplify.
--
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]