From 1df1bb58ff2b3fce02e79e29af543d80d4959ff6 Mon Sep 17 00:00:00 2001 From: Jiayu Liu Date: Wed, 23 Jun 2021 18:56:24 +0800 Subject: [PATCH] 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 cc976a463ff4..5526432f8d8a 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 { 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 @@ -113,6 +116,21 @@ mod tests { assert!(re.is_err()); } + #[test] + fn test_concat_one_element_vec() -> Result<()> { + let arr = Arc::new(PrimitiveArray::::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(&[