Skip to content

Commit 37cd34d

Browse files
authored
Improve documentation for nullif kernel (apache#6658)
* Improve `nullif` docs * Improve documentation for `nullif` kernel
1 parent 0b890ea commit 37cd34d

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

arrow-select/src/nullif.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,25 @@ use arrow_buffer::buffer::{bitwise_bin_op_helper, bitwise_unary_op_helper};
2222
use arrow_buffer::{BooleanBuffer, NullBuffer};
2323
use arrow_schema::{ArrowError, DataType};
2424

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.
2727
///
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+
/// ```
2944
pub fn nullif(left: &dyn Array, right: &BooleanArray) -> Result<ArrayRef, ArrowError> {
3045
let left_data = left.to_data();
3146

0 commit comments

Comments
 (0)