You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2022/12/03 17:56:37 UTC
[arrow-rs] branch master updated: Fix panic on nullif empty array (#3261) (#3263)
This is an automated email from the ASF dual-hosted git repository.
tustvold 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 796b67033 Fix panic on nullif empty array (#3261) (#3263)
796b67033 is described below
commit 796b670338ce33806a39777ea18cf6fae8fa7ee4
Author: Raphael Taylor-Davies <17...@users.noreply.github.com>
AuthorDate: Sat Dec 3 17:56:33 2022 +0000
Fix panic on nullif empty array (#3261) (#3263)
* Fix panic on nullif empty array (#3261)
* Format
---
arrow-select/src/nullif.rs | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/arrow-select/src/nullif.rs b/arrow-select/src/nullif.rs
index a0a1a3a22..23a586f63 100644
--- a/arrow-select/src/nullif.rs
+++ b/arrow-select/src/nullif.rs
@@ -39,6 +39,10 @@ pub fn nullif(left: &dyn Array, right: &BooleanArray) -> Result<ArrayRef, ArrowE
let len = left_data.len();
let left_offset = left_data.offset();
+ if len == 0 {
+ return Ok(make_array(left_data.clone()));
+ }
+
// left=0 (null) right=null output bitmap=null
// left=0 right=1 output bitmap=null
// left=1 (set) right=null output bitmap=set (passthrough)
@@ -119,6 +123,7 @@ mod tests {
use arrow_array::cast::{as_boolean_array, as_primitive_array, as_string_array};
use arrow_array::types::Int32Type;
use arrow_array::{Int32Array, StringArray, StructArray};
+ use arrow_data::ArrayData;
use arrow_schema::{DataType, Field};
#[test]
@@ -451,4 +456,12 @@ mod tests {
let expected = Int32Array::from(vec![Some(15), Some(7), None, Some(1), Some(9)]);
assert_eq!(res, &expected);
}
+
+ #[test]
+ fn nullif_empty() {
+ let a = Int32Array::from(ArrayData::new_empty(&DataType::Int32));
+ let mask = BooleanArray::from(ArrayData::new_empty(&DataType::Boolean));
+ let res = nullif(&a, &mask).unwrap();
+ assert_eq!(res.as_ref(), &a);
+ }
}