@@ -22,10 +22,25 @@ use arrow_buffer::buffer::{bitwise_bin_op_helper, bitwise_unary_op_helper};
22
22
use arrow_buffer:: { BooleanBuffer , NullBuffer } ;
23
23
use arrow_schema:: { ArrowError , DataType } ;
24
24
25
- /// Copies original array, setting validity bit to false if a secondary comparison
26
- /// boolean array is set to true
25
+ /// Returns a new array with the same values and the validity bit to false where
26
+ /// the corresponding element of`right` is true.
27
27
///
28
- /// Typically used to implement NULLIF.
28
+ /// This can be used to implement SQL `NULLIF`
29
+ ///
30
+ /// # Example
31
+ /// ```
32
+ /// # use arrow_array::{Int32Array, BooleanArray};
33
+ /// # use arrow_array::cast::AsArray;
34
+ /// # use arrow_array::types::Int32Type;
35
+ /// # use arrow_select::nullif::nullif;
36
+ /// // input is [null, 8, 1, 9]
37
+ /// let a = Int32Array::from(vec![None, Some(8), Some(1), Some(9)]);
38
+ /// // use nullif to set index 1 to null
39
+ /// let bool_array = BooleanArray::from(vec![Some(false), Some(true), Some(false), None]);
40
+ /// let nulled = nullif(&a, &bool_array).unwrap();
41
+ /// // The resulting array is [null, null, 1, 9]
42
+ /// assert_eq!(nulled.as_primitive(), &Int32Array::from(vec![None, None, Some(1), Some(9)]));
43
+ /// ```
29
44
pub fn nullif ( left : & dyn Array , right : & BooleanArray ) -> Result < ArrayRef , ArrowError > {
30
45
let left_data = left. to_data ( ) ;
31
46
0 commit comments