This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new 38f9bc5 concatenating single element array shortcut (#492)
38f9bc5 is described below
commit 38f9bc5aeffd3c134adbad24ef6c72d105f057d6
Author: Jiayu Liu <[email protected]>
AuthorDate: Wed Jun 23 18:56:24 2021 +0800
concatenating single element array shortcut (#492)
---
arrow/src/compute/kernels/concat.rs | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/arrow/src/compute/kernels/concat.rs
b/arrow/src/compute/kernels/concat.rs
index cc976a4..5526432 100644
--- a/arrow/src/compute/kernels/concat.rs
+++ b/arrow/src/compute/kernels/concat.rs
@@ -57,6 +57,9 @@ pub fn concat(arrays: &[&Array]) -> Result<ArrayRef> {
return Err(ArrowError::ComputeError(
"concat requires input of at least one array".to_string(),
));
+ } else if arrays.len() == 1 {
+ let array = arrays[0];
+ return Ok(array.slice(0, array.len()));
}
if arrays
@@ -114,6 +117,21 @@ mod tests {
}
#[test]
+ fn test_concat_one_element_vec() -> Result<()> {
+ let arr = Arc::new(PrimitiveArray::<Int64Type>::from(vec![
+ Some(-1),
+ Some(2),
+ None,
+ ])) as ArrayRef;
+ let result = concat(&[arr.as_ref()])?;
+ assert_eq!(
+ &arr, &result,
+ "concatenating single element array gives back the same result"
+ );
+ Ok(())
+ }
+
+ #[test]
fn test_concat_incompatible_datatypes() {
let re = concat(&[
&PrimitiveArray::<Int64Type>::from(vec![Some(-1), Some(2), None]),