Skip to content

Commit

Permalink
concatenating single element array shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiayu Liu committed Jun 23, 2021
1 parent 4c7d418 commit dad8d16
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions arrow/src/compute/kernels/concat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -113,6 +116,21 @@ mod tests {
assert!(re.is_err());
}

#[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(&[
Expand Down

0 comments on commit dad8d16

Please sign in to comment.