wjones127 commented on code in PR #12751:
URL: https://github.com/apache/arrow/pull/12751#discussion_r853350259
##########
r/R/record-batch.R:
##########
@@ -189,3 +189,59 @@ 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(inputs, call = caller_env()) {
+ sizes <- map(inputs, function(input) {
+ # TODO: can we somehow implement vec_size for Arrow structures?
+ if (inherits(input, "ArrowTabular") || is.data.frame(input)) {
+ nrow(input)
+ } else {
+ length(input)
+ }
+ })
+ wrong_idx <- which.min(sizes == sizes[[1]] | sizes == 1)
+ if (wrong_idx != 1) {
+ abort(
+ c("Non-scalar inputs must have an equal number of rows.",
+ i = sprintf("..1 has %d, ..%d has %d", sizes[[1]], wrong_idx,
sizes[[wrong_idx]])),
+ call = call
+ )
+ }
+}
+
+#' @export
+cbind.RecordBatch <- function(...) {
+ call <- sys.call()
+ inputs <- list(...)
+ arg_names <- if (is.null(names(inputs))) {
+ rep("", length(inputs))
+ } else {
+ names(inputs)
+ }
+
+ cbind_check_length(inputs, call)
+
+ columns <- flatten(map(seq_along(inputs), function(i) {
+ input <- inputs[[i]]
+ name <- arg_names[i]
+
+ if (inherits(input, "RecordBatch")) {
+ set_names(input$columns, names(input))
Review Comment:
Issue created: https://issues.apache.org/jira/browse/ARROW-16239
--
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]