Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change concat_batches parameter to non owned reference #3480

Merged
merged 2 commits into from
Jan 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions arrow-select/src/concat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ pub fn concat(arrays: &[&dyn Array]) -> Result<ArrayRef, ArrowError> {
}

/// Concatenates `batches` together into a single record batch.
pub fn concat_batches(
pub fn concat_batches<'a>(
schema: &SchemaRef,
batches: &[RecordBatch],
input_batches: impl IntoIterator<Item = &'a RecordBatch>,
) -> Result<RecordBatch, ArrowError> {
let batches: Vec<&RecordBatch> = input_batches.into_iter().collect();
if batches.is_empty() {
return Ok(RecordBatch::new_empty(schema.clone()));
}
Expand Down Expand Up @@ -611,10 +612,14 @@ mod tests {
],
)
.unwrap();
let new_batch = concat_batches(&schema, &[batch1, batch2]).unwrap();
let new_batch = concat_batches(&schema, [&batch1, &batch2]).unwrap();
askoa marked this conversation as resolved.
Show resolved Hide resolved
assert_eq!(new_batch.schema().as_ref(), schema.as_ref());
assert_eq!(2, new_batch.num_columns());
assert_eq!(4, new_batch.num_rows());
askoa marked this conversation as resolved.
Show resolved Hide resolved
let new_batch_owned = concat_batches(&schema, &[batch1, batch2]).unwrap();
assert_eq!(new_batch_owned.schema().as_ref(), schema.as_ref());
assert_eq!(2, new_batch_owned.num_columns());
assert_eq!(4, new_batch_owned.num_rows());
}

#[test]
Expand All @@ -623,7 +628,7 @@ mod tests {
Field::new("a", DataType::Int32, false),
Field::new("b", DataType::Utf8, false),
]));
let batch = concat_batches(&schema, &[]).unwrap();
let batch = concat_batches(&schema, []).unwrap();
assert_eq!(batch.schema().as_ref(), schema.as_ref());
assert_eq!(0, batch.num_rows());
}
Expand Down Expand Up @@ -654,7 +659,7 @@ mod tests {
],
)
.unwrap();
let error = concat_batches(&schema1, &[batch1, batch2]).unwrap_err();
let error = concat_batches(&schema1, [&batch1, &batch2]).unwrap_err();
assert_eq!(
error.to_string(),
"Invalid argument error: batches[1] schema is different with argument schema.",
Expand Down