arrow_select::nullif

Function nullif

Source
pub fn nullif(
    left: &dyn Array,
    right: &BooleanArray,
) -> Result<ArrayRef, ArrowError>
Expand description

Returns a new array with the same values and the validity bit to false where the corresponding element ofright is true.

This can be used to implement SQL NULLIF

ยงExample

// input is [null, 8, 1, 9]
let a = Int32Array::from(vec![None, Some(8), Some(1), Some(9)]);
// use nullif to set index 1 to null
let bool_array = BooleanArray::from(vec![Some(false), Some(true), Some(false), None]);
let nulled = nullif(&a, &bool_array).unwrap();
// The resulting array is [null, null, 1, 9]
assert_eq!(nulled.as_primitive(), &Int32Array::from(vec![None, None, Some(1), Some(9)]));